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