| 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
| 2 | //      template array class for numerical types | 
|---|
| 3 | //                     R. Ansari, C.Magneville   03/2000 | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef TArray_SEEN | 
|---|
| 6 | #define TArray_SEEN | 
|---|
| 7 |  | 
|---|
| 8 | #include "machdefs.h" | 
|---|
| 9 | #include <math.h> | 
|---|
| 10 | #include <iostream.h> | 
|---|
| 11 | #include "basarr.h" | 
|---|
| 12 | #include "ndatablock.h" | 
|---|
| 13 | #include <complex> | 
|---|
| 14 | #include "utilarr.h" | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | namespace SOPHYA { | 
|---|
| 18 |  | 
|---|
| 19 | // Forward declaration | 
|---|
| 20 | template <class T> class FIO_TArray; | 
|---|
| 21 |  | 
|---|
| 22 | //   --------------------------- classe template Array ----------------------- | 
|---|
| 23 | //  ( See BaseArray class for data organisation in  memory and related methods ) | 
|---|
| 24 |  | 
|---|
| 25 | //! Class for template arrays | 
|---|
| 26 | template <class T> | 
|---|
| 27 | class TArray : public BaseArray { | 
|---|
| 28 | public: | 
|---|
| 29 | // Creation / destruction | 
|---|
| 30 | TArray(); | 
|---|
| 31 | TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step =1); | 
|---|
| 32 | TArray(sa_size_t nx, sa_size_t ny=0, sa_size_t nz=0, sa_size_t nt=0, sa_size_t nu=0); | 
|---|
| 33 | TArray(int_4 ndim, const sa_size_t * siz, NDataBlock<T> & db, bool share=false, sa_size_t step=1, sa_size_t offset=0); | 
|---|
| 34 | TArray(int_4 ndim, const sa_size_t * siz, T* values, sa_size_t step=1, sa_size_t offset=0, Bridge* br=NULL); | 
|---|
| 35 | TArray(const TArray<T>& a); | 
|---|
| 36 | TArray(const TArray<T>& a, bool share); | 
|---|
| 37 | TArray(const BaseArray& a); | 
|---|
| 38 |  | 
|---|
| 39 | virtual ~TArray(); | 
|---|
| 40 |  | 
|---|
| 41 | // A = B | 
|---|
| 42 | //! = operator between TArray | 
|---|
| 43 | /*! \warning Datas are copied (cloned) from \b a. | 
|---|
| 44 | \sa Set \sa NDataBlock::operator=(const NDataBlock<T>&) */ | 
|---|
| 45 | inline  TArray<T>& operator = (const TArray<T>& a) { return Set(a); } | 
|---|
| 46 | virtual TArray<T>& Set(const TArray<T>& a); | 
|---|
| 47 |  | 
|---|
| 48 | //! = operator between  TArray 's with different types - Elements are converted. | 
|---|
| 49 | inline  TArray<T>& operator = (const BaseArray& a) { return SetBA(a); } | 
|---|
| 50 | virtual TArray<T>& SetBA(const BaseArray& a); | 
|---|
| 51 |  | 
|---|
| 52 | // Gestion taille/Remplissage | 
|---|
| 53 | virtual void Clone(const TArray<T>& a); | 
|---|
| 54 | // partage les donnees si "a" temporaire, clone sinon. | 
|---|
| 55 | void CloneOrShare(const TArray<T>& a); | 
|---|
| 56 | // Share: partage les donnees de "a" | 
|---|
| 57 | void Share(const TArray<T>& a); | 
|---|
| 58 |  | 
|---|
| 59 | void ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1); | 
|---|
| 60 | void ReSize(const TArray<T>& a); | 
|---|
| 61 | //! a synonym (alias) for method ReSize(int_4, ...) | 
|---|
| 62 | inline void SetSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1) | 
|---|
| 63 | { ReSize(ndim, siz, step); } | 
|---|
| 64 | //! a synonym (alias) for method ReSize(const TArray<T>&) | 
|---|
| 65 | inline void SetSize(const TArray<T>& a) | 
|---|
| 66 | { ReSize(a); } | 
|---|
| 67 | void Realloc(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool force=false); | 
|---|
| 68 |  | 
|---|
| 69 | // Compacts size=1 array dimensions | 
|---|
| 70 | virtual TArray<T>& CompactAllDimensions(); | 
|---|
| 71 | virtual TArray<T>& CompactTrailingDimensions(); | 
|---|
| 72 |  | 
|---|
| 73 | // Packing array elements in memory | 
|---|
| 74 | virtual TArray<T> PackElements(bool force=false) const ; | 
|---|
| 75 |  | 
|---|
| 76 | // SubArrays - $CHECK$ Reza 03/2000 je ne sais pas s'il faut declarer ca const ?? | 
|---|
| 77 | TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const ; | 
|---|
| 78 | #if !defined(__GNUG__) | 
|---|
| 79 | //! () operator for Sub arrays extraction | 
|---|
| 80 | /*! \sa SubArray */ | 
|---|
| 81 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt=0, Range ru=0) const | 
|---|
| 82 | { return  SubArray(rx, ry, rz, rt, ru); } | 
|---|
| 83 | #else | 
|---|
| 84 | // g++ (2.95) se melange les pinceaux avec les arguments par defaut ! | 
|---|
| 85 | //! () operator for Sub arrays extraction | 
|---|
| 86 | /*! \sa SubArray */ | 
|---|
| 87 | inline TArray<T> operator () (Range rx, Range ry, Range rz) const | 
|---|
| 88 | { return  SubArray(rx, ry, rz, Range(0), Range(0)); } | 
|---|
| 89 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt) const | 
|---|
| 90 | { return  SubArray(rx, ry, rz, rt, Range(0)); } | 
|---|
| 91 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt, Range ru) const | 
|---|
| 92 | { return  SubArray(rx, ry, rz, rt, ru); } | 
|---|
| 93 | #endif | 
|---|
| 94 |  | 
|---|
| 95 | // ---- Access to data | 
|---|
| 96 | // Definition of virtual element acces method inherited from BaseArray class | 
|---|
| 97 | virtual MuTyV & ValueAtPosition(sa_size_t ip) const; | 
|---|
| 98 |  | 
|---|
| 99 | // Data Access: operator overloaded inline acces methods | 
|---|
| 100 | inline T const& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) const ; | 
|---|
| 101 | inline T&       operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz); | 
|---|
| 102 | inline T const& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu=0) const ; | 
|---|
| 103 | inline T&       operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu=0); | 
|---|
| 104 | inline T const& operator[](sa_size_t ip) const ; | 
|---|
| 105 | inline T&       operator[](sa_size_t ip); | 
|---|
| 106 |  | 
|---|
| 107 | inline T const& Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0) const ; | 
|---|
| 108 | inline T&       Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0); | 
|---|
| 109 | inline T const& ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0) const ; | 
|---|
| 110 | inline T&       ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0); | 
|---|
| 111 |  | 
|---|
| 112 | //! Return pointer to first element adress | 
|---|
| 113 | inline        T* Data()       {return mNDBlock.Begin()+offset_;} | 
|---|
| 114 | //! Return pointer to first element adress | 
|---|
| 115 | inline const  T* Data() const {return mNDBlock.Begin()+offset_;} | 
|---|
| 116 | //! Return reference to datablock NDataBlock | 
|---|
| 117 | inline        NDataBlock<T>& DataBlock()       {return mNDBlock;} | 
|---|
| 118 | //! Return reference to datablock NDataBlock | 
|---|
| 119 | inline const  NDataBlock<T>& DataBlock() const {return mNDBlock;} | 
|---|
| 120 |  | 
|---|
| 121 | // Temporaire? | 
|---|
| 122 | //! Are the array temporay ? | 
|---|
| 123 | inline bool   IsTemp(void) const {return mNDBlock.IsTemp();} | 
|---|
| 124 | //! Set the array as temporay | 
|---|
| 125 | inline void   SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);} | 
|---|
| 126 |  | 
|---|
| 127 | // Operations diverses  = , +=, ... | 
|---|
| 128 | // Conversion en type T, if Size() == 1 | 
|---|
| 129 | inline T toScalar(); | 
|---|
| 130 | // Met les elements a une suite de valeurs | 
|---|
| 131 | virtual TArray<T>&  SetSeq(Sequence const & seq); | 
|---|
| 132 | //! Fill TArray with Sequence \b seq | 
|---|
| 133 | inline  TArray<T>&  operator = (Sequence const & seq)    { return SetSeq(seq); } | 
|---|
| 134 | // A = x (tous les elements a x) | 
|---|
| 135 | virtual TArray<T>&  SetT(T x); | 
|---|
| 136 | //! Fill TArray with all elements equal to \b x | 
|---|
| 137 | inline  TArray<T>&  operator = (T x)             { return SetT(x); } | 
|---|
| 138 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements) | 
|---|
| 139 | virtual TArray<T>&  Add(T x); | 
|---|
| 140 | //! Add \b x to all elements | 
|---|
| 141 | inline  TArray<T>&  operator += (T x)            { return Add(x); } | 
|---|
| 142 | virtual TArray<T>&  Sub(T x, bool fginv=false); | 
|---|
| 143 | //! Substract \b x to all elements | 
|---|
| 144 | inline  TArray<T>&  operator -= (T x)            { return Sub(x); } | 
|---|
| 145 | virtual TArray<T>&  Mul(T x); | 
|---|
| 146 | //! Multiply all elements by \b x | 
|---|
| 147 | inline  TArray<T>&  operator *= (T x)            { return Mul(x); } | 
|---|
| 148 | virtual TArray<T>&  Div(T x, bool fginv=false); | 
|---|
| 149 | //! Divide all elements by \b x | 
|---|
| 150 | inline  TArray<T>&  operator /= (T x)            { return Div(x); } | 
|---|
| 151 |  | 
|---|
| 152 | // applique le signe moins a tous les elements | 
|---|
| 153 | virtual TArray<T>&  NegateElt(); | 
|---|
| 154 |  | 
|---|
| 155 | // A += -=  (ajoute, soustrait element par element les deux tableaux ) | 
|---|
| 156 | virtual TArray<T>&  AddElt(const TArray<T>& a); | 
|---|
| 157 | //! Operator TArray += TArray | 
|---|
| 158 | inline  TArray<T>&  operator += (const TArray<T>& a)  { return AddElt(a); } | 
|---|
| 159 | virtual TArray<T>&  SubElt(const TArray<T>& a, bool fginv=false); | 
|---|
| 160 | //! Operator TArray -= TArray | 
|---|
| 161 | inline  TArray<T>&  operator -= (const TArray<T>& a)  { return SubElt(a); } | 
|---|
| 162 | // Multiplication, division element par element les deux tableaux | 
|---|
| 163 | virtual TArray<T>&  MulElt(const TArray<T>& a); | 
|---|
| 164 | virtual TArray<T>&  DivElt(const TArray<T>& a, bool fginv=false, bool divzero=false); | 
|---|
| 165 | // Recopie des valeurs, element par element | 
|---|
| 166 | virtual TArray<T>&  CopyElt(const TArray<T>& a); | 
|---|
| 167 | // Recopie des valeurs avec conversion prealable, element par element | 
|---|
| 168 | virtual TArray<T>&  ConvertAndCopyElt(const BaseArray& a); | 
|---|
| 169 |  | 
|---|
| 170 | // Somme et produit des elements | 
|---|
| 171 | virtual T Sum() const ; | 
|---|
| 172 | virtual T Product() const ; | 
|---|
| 173 | // Somme du carre des elements | 
|---|
| 174 | virtual T SumX2() const; | 
|---|
| 175 | // Valeur min et max des elements | 
|---|
| 176 | virtual void MinMax(T& min, T& max) const ; | 
|---|
| 177 |  | 
|---|
| 178 | // Impression, I/O, ... | 
|---|
| 179 | virtual string InfoString() const; | 
|---|
| 180 | virtual void   Print(ostream& os, int_4 maxprt=-1, bool si=false) const ; | 
|---|
| 181 |  | 
|---|
| 182 | //  Pour la gestion de persistance | 
|---|
| 183 | friend class  FIO_TArray<T>; | 
|---|
| 184 |  | 
|---|
| 185 | protected: | 
|---|
| 186 |  | 
|---|
| 187 | NDataBlock<T> mNDBlock; //!< Block for datas | 
|---|
| 188 | mutable MuTyV my_mtv;   //!< for use by ValueAtPosition() | 
|---|
| 189 | }; | 
|---|
| 190 |  | 
|---|
| 191 | //////////////////////////////////////////////////////////////// | 
|---|
| 192 | //   Surcharge d'operateur << | 
|---|
| 193 | //! Print TArray \b a on stream \b os | 
|---|
| 194 | template <class T> | 
|---|
| 195 | inline ostream& operator << (ostream& os, const TArray<T>& a) | 
|---|
| 196 | { a.Print(os);    return(os);    } | 
|---|
| 197 |  | 
|---|
| 198 | //////////////////////////////////////////////////////////////// | 
|---|
| 199 | // Surcharge d'operateurs A (+,-,*,/) (T) x | 
|---|
| 200 |  | 
|---|
| 201 | /*! \ingroup TArray \fn operator+(const TArray<T>&,T) | 
|---|
| 202 | \brief Operator TArray = TArray + constant */ | 
|---|
| 203 | template <class T> inline TArray<T> operator + (const TArray<T>& a, T b) | 
|---|
| 204 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 205 | result.Add(b); return result;} | 
|---|
| 206 |  | 
|---|
| 207 | /*! \ingroup TArray \fn operator+(T,const TArray<T>&) | 
|---|
| 208 | \brief Operator TArray = constant + TArray */ | 
|---|
| 209 | template <class T> inline TArray<T> operator + (T b,const TArray<T>& a) | 
|---|
| 210 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 211 | result.Add(b); return result;} | 
|---|
| 212 |  | 
|---|
| 213 | /*! \ingroup TArray \fn operator-(const TArray<T>&,T) | 
|---|
| 214 | \brief Operator TArray = TArray - constant */ | 
|---|
| 215 | template <class T> inline TArray<T> operator - (const TArray<T>& a, T b) | 
|---|
| 216 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 217 | result.Sub(b); return result;} | 
|---|
| 218 |  | 
|---|
| 219 | /*! \ingroup TArray \fn operator-(T,const TArray<T>&) | 
|---|
| 220 | \brief Operator TArray = constant - TArray */ | 
|---|
| 221 | template <class T> inline TArray<T> operator - (T b,const TArray<T>& a) | 
|---|
| 222 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 223 | result.Sub(b,true); return result;} | 
|---|
| 224 |  | 
|---|
| 225 | /*! \ingroup TArray \fn operator*(const TArray<T>&,T) | 
|---|
| 226 | \brief Operator TArray = TArray * constant */ | 
|---|
| 227 | template <class T> inline TArray<T> operator * (const TArray<T>& a, T b) | 
|---|
| 228 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 229 | result.Mul(b); return result;} | 
|---|
| 230 |  | 
|---|
| 231 | /*! \ingroup TArray \fn operator*(T,const TArray<T>&) | 
|---|
| 232 | \brief Operator TArray = constant * TArray */ | 
|---|
| 233 | template <class T> inline TArray<T> operator * (T b,const TArray<T>& a) | 
|---|
| 234 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 235 | result.Mul(b); return result;} | 
|---|
| 236 |  | 
|---|
| 237 | /*! \ingroup TArray \fn operator/(const TArray<T>&,T) | 
|---|
| 238 | \brief Operator TArray = TArray / constant */ | 
|---|
| 239 | template <class T> inline TArray<T> operator / (const TArray<T>& a, T b) | 
|---|
| 240 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 241 | result.Div(b); return result;} | 
|---|
| 242 |  | 
|---|
| 243 | /*! \ingroup TArray \fn operator/(T,const TArray<T>&) | 
|---|
| 244 | \brief Operator TArray = constant / TArray  */ | 
|---|
| 245 | template <class T> inline TArray<T> operator / (T b, const TArray<T>& a) | 
|---|
| 246 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 247 | result.Div(b, true); return result;} | 
|---|
| 248 |  | 
|---|
| 249 | //////////////////////////////////////////////////////////////// | 
|---|
| 250 | // Surcharge d'operateurs B = -A | 
|---|
| 251 |  | 
|---|
| 252 | /*! \ingroup TArray \fn operator - (const TArray<T>&) | 
|---|
| 253 | \brief Operator - Returns an array with elements equal to the opposite of | 
|---|
| 254 | the original array elements.  */ | 
|---|
| 255 | template <class T> inline TArray<T> operator - (const TArray<T>& a) | 
|---|
| 256 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 257 | result.NegateElt(); return result;} | 
|---|
| 258 |  | 
|---|
| 259 | //////////////////////////////////////////////////////////////// | 
|---|
| 260 | // Surcharge d'operateurs C = A (+,-) B | 
|---|
| 261 |  | 
|---|
| 262 | /*! \ingroup TArray \fn operator+(const TArray<T>&,const TArray<T>&) | 
|---|
| 263 | \brief Operator TArray = TArray + TArray */ | 
|---|
| 264 | template <class T> | 
|---|
| 265 | inline TArray<T> operator + (const TArray<T>& a,const TArray<T>& b) | 
|---|
| 266 | { TArray<T> result; result.SetTemp(true); | 
|---|
| 267 | if (b.IsTemp())  { result.Share(b); result.AddElt(a); } | 
|---|
| 268 | else { result.CloneOrShare(a); result.AddElt(b); } | 
|---|
| 269 | return result; } | 
|---|
| 270 |  | 
|---|
| 271 | /*! \ingroup TArray \fn operator-(const TArray<T>&,const TArray<T>&) | 
|---|
| 272 | \brief Operator TArray = TArray - TArray */ | 
|---|
| 273 | template <class T> | 
|---|
| 274 | inline TArray<T> operator - (const TArray<T>& a,const TArray<T>& b) | 
|---|
| 275 | { TArray<T> result; result.SetTemp(true); | 
|---|
| 276 | if (b.IsTemp())  { result.Share(b); result.SubElt(a, true); } | 
|---|
| 277 | else { result.CloneOrShare(a); result.SubElt(b); } | 
|---|
| 278 | return result; } | 
|---|
| 279 |  | 
|---|
| 280 |  | 
|---|
| 281 | // -------------------------------------------------- | 
|---|
| 282 | //        inline element acces methods | 
|---|
| 283 | // -------------------------------------------------- | 
|---|
| 284 |  | 
|---|
| 285 | //! Return element (ix,iy,iz,it,iu) value | 
|---|
| 286 | template <class T> | 
|---|
| 287 | inline T const& TArray<T>::Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) const | 
|---|
| 288 | { | 
|---|
| 289 | return ( *( mNDBlock.Begin()+ offset_+ | 
|---|
| 290 | ix*step_[0] + iy*step_[1] + iz*step_[2] + | 
|---|
| 291 | it*step_[3] + iu*step_[4]) ); | 
|---|
| 292 | } | 
|---|
| 293 |  | 
|---|
| 294 | //! Return element (ix,iy,iz,it,iu) value | 
|---|
| 295 | template <class T> | 
|---|
| 296 | inline T & TArray<T>::Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) | 
|---|
| 297 | { | 
|---|
| 298 | return ( *( mNDBlock.Begin()+ offset_+ | 
|---|
| 299 | ix*step_[0] + iy*step_[1] + iz*step_[2] + | 
|---|
| 300 | it*step_[3] + iu*step_[4]) ); | 
|---|
| 301 | } | 
|---|
| 302 |  | 
|---|
| 303 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first | 
|---|
| 304 | template <class T> | 
|---|
| 305 | inline T const& TArray<T>::ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) const | 
|---|
| 306 | { | 
|---|
| 307 | CheckBound(ix, iy, iz, it, iu, 4); | 
|---|
| 308 | return(Elem(ix, iy, iz, it, iu)); | 
|---|
| 309 | } | 
|---|
| 310 |  | 
|---|
| 311 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first | 
|---|
| 312 | template <class T> | 
|---|
| 313 | inline T & TArray<T>::ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) | 
|---|
| 314 | { | 
|---|
| 315 | CheckBound(ix, iy, iz, it, iu, 4); | 
|---|
| 316 | return(Elem(ix, iy, iz, it, iu)); | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | //! Return element (ix,iy,iz) value | 
|---|
| 320 | template <class T> | 
|---|
| 321 | inline T const& TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) const | 
|---|
| 322 | { | 
|---|
| 323 | #ifdef SO_BOUNDCHECKING | 
|---|
| 324 | CheckBound(ix, iy, iz, 0, 0, 4); | 
|---|
| 325 | #endif | 
|---|
| 326 | return ( *( mNDBlock.Begin()+ offset_+ | 
|---|
| 327 | ix*step_[0] + iy*step_[1] + iz*step_[2]) ); | 
|---|
| 328 | } | 
|---|
| 329 |  | 
|---|
| 330 | //! Return element (ix,iy,iz) value | 
|---|
| 331 | template <class T> | 
|---|
| 332 | inline T & TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) | 
|---|
| 333 | { | 
|---|
| 334 | #ifdef SO_BOUNDCHECKING | 
|---|
| 335 | CheckBound(ix, iy, iz, 0, 0, 4); | 
|---|
| 336 | #endif | 
|---|
| 337 | return ( *( mNDBlock.Begin()+ offset_+ | 
|---|
| 338 | ix*step_[0] + iy*step_[1] + iz*step_[2]) ); | 
|---|
| 339 | } | 
|---|
| 340 |  | 
|---|
| 341 | //! Operator () : return element (ix,iy,iz,it,iu) value | 
|---|
| 342 | template <class T> | 
|---|
| 343 | inline T const& TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) const | 
|---|
| 344 | { | 
|---|
| 345 | #ifdef SO_BOUNDCHECKING | 
|---|
| 346 | CheckBound(ix, iy, iz, it, iu, 4); | 
|---|
| 347 | #endif | 
|---|
| 348 | return ( *( mNDBlock.Begin()+ offset_+ | 
|---|
| 349 | ix*step_[0] + iy*step_[1] + iz*step_[2] + | 
|---|
| 350 | it*step_[3] + iu*step_[4]) ); | 
|---|
| 351 | } | 
|---|
| 352 |  | 
|---|
| 353 | //! Operator () : return element (ix,iy,iz,it,iu) value | 
|---|
| 354 | template <class T> | 
|---|
| 355 | inline T & TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) | 
|---|
| 356 | { | 
|---|
| 357 | #ifdef SO_BOUNDCHECKING | 
|---|
| 358 | CheckBound(ix, iy, iz, it, iu, 4); | 
|---|
| 359 | #endif | 
|---|
| 360 | return ( *( mNDBlock.Begin()+ offset_+ | 
|---|
| 361 | ix*step_[0] + iy*step_[1] + iz*step_[2] + | 
|---|
| 362 | it*step_[3] + iu*step_[4]) ); | 
|---|
| 363 | } | 
|---|
| 364 |  | 
|---|
| 365 |  | 
|---|
| 366 | //! Operator [] : return element at positon ip | 
|---|
| 367 | template <class T> | 
|---|
| 368 | inline T const& TArray<T>::operator[](sa_size_t ip) const | 
|---|
| 369 | { | 
|---|
| 370 | #ifdef SO_BOUNDCHECKING | 
|---|
| 371 | if (ip >= totsize_)  throw( ParmError("TArray<T>::operator[] Out-of-bound Error") ); | 
|---|
| 372 | #endif | 
|---|
| 373 | return *(mNDBlock.Begin()+Offset(ip)); | 
|---|
| 374 | } | 
|---|
| 375 |  | 
|---|
| 376 | //! Operator [] : return element at positon ip | 
|---|
| 377 | template <class T> | 
|---|
| 378 | inline T & TArray<T>::operator[](sa_size_t ip) | 
|---|
| 379 | { | 
|---|
| 380 | #ifdef SO_BOUNDCHECKING | 
|---|
| 381 | if (ip >= totsize_)  throw( ParmError("TArray<T>::operator[] Out-of-bound Error") ); | 
|---|
| 382 | #endif | 
|---|
| 383 | return *(mNDBlock.Begin()+Offset(ip)); | 
|---|
| 384 | } | 
|---|
| 385 |  | 
|---|
| 386 |  | 
|---|
| 387 | //! Converts to a scalar (value of first element) if the array size is equal to 1 | 
|---|
| 388 | template <class T> | 
|---|
| 389 | inline T TArray<T>::toScalar() | 
|---|
| 390 | { | 
|---|
| 391 | if (Size() != 1) throw(SzMismatchError("TArray<T>::operator T() Size() != 1")) ; | 
|---|
| 392 | return ( (*this)[0] ); | 
|---|
| 393 | } | 
|---|
| 394 |  | 
|---|
| 395 | // Typedef pour simplifier | 
|---|
| 396 | /*! \ingroup TArray | 
|---|
| 397 | \typedef Array | 
|---|
| 398 | \brief To simplified TArray<r_8> writing | 
|---|
| 399 | */ | 
|---|
| 400 | typedef TArray<r_8> Array; | 
|---|
| 401 |  | 
|---|
| 402 | } // Fin du namespace | 
|---|
| 403 |  | 
|---|
| 404 | #endif | 
|---|