[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();
|
---|
[804] | 31 | TArray(uint_4 ndim, const uint_4 * siz, uint_4 step =1);
|
---|
| 32 | TArray(uint_4 nx, uint_4 ny=0, uint_4 nz=0, uint_4 nt=0, uint_4 nu=0);
|
---|
| 33 | TArray(uint_4 ndim, const uint_4 * siz, NDataBlock<T> & db, bool share=false, uint_4 step=1, uint_8 offset=0);
|
---|
| 34 | TArray(uint_4 ndim, const uint_4 * siz, T* values, uint_4 step=1, uint_8 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"
|
---|
| 57 |
|
---|
| 58 | void Share(const TArray<T>& a);
|
---|
[804] | 59 | void ReSize(uint_4 ndim, uint_4 * siz, uint_4 step=1);
|
---|
| 60 | void Realloc(uint_4 ndim, uint_4 * siz, uint_4 step=1, bool force=false);
|
---|
[787] | 61 |
|
---|
[785] | 62 | // Compacts size=1 array dimensions
|
---|
[787] | 63 | virtual TArray<T>& CompactAllDimensions();
|
---|
| 64 | virtual TArray<T>& CompactTrailingDimensions();
|
---|
[785] | 65 |
|
---|
[804] | 66 | // Packing array elements in memory
|
---|
| 67 | virtual TArray<T> PackElements(bool force=false) const ;
|
---|
[772] | 68 |
|
---|
[804] | 69 | // SubArrays - $CHECK$ Reza 03/2000 je ne sais pas s'il faut declarer ca const ??
|
---|
[894] | 70 | TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const ;
|
---|
[963] | 71 | #if !defined(__GNUG__)
|
---|
[894] | 72 | //! () operator for Sub arrays extraction
|
---|
| 73 | /*! \sa SubArray */
|
---|
[804] | 74 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt=0, Range ru=0) const
|
---|
| 75 | { return SubArray(rx, ry, rz, rt, ru); }
|
---|
[963] | 76 | #else
|
---|
| 77 | // g++ (2.95) se melange les pinceaux avec les arguments par defaut !
|
---|
| 78 | //! () operator for Sub arrays extraction
|
---|
| 79 | /*! \sa SubArray */
|
---|
| 80 | inline TArray<T> operator () (Range rx, Range ry, Range rz) const
|
---|
| 81 | { return SubArray(rx, ry, rz, Range(0), Range(0)); }
|
---|
| 82 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt) const
|
---|
| 83 | { return SubArray(rx, ry, rz, rt, Range(0)); }
|
---|
| 84 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt, Range ru) const
|
---|
| 85 | { return SubArray(rx, ry, rz, rt, ru); }
|
---|
| 86 | #endif
|
---|
[772] | 87 |
|
---|
[787] | 88 | // ---- Access to data
|
---|
| 89 | // Definition of virtual element acces method inherited from BaseArray class
|
---|
[1081] | 90 | virtual MuTyV & ValueAtPosition(uint_8 ip) const;
|
---|
[785] | 91 |
|
---|
[787] | 92 | // Data Access: operator overloaded inline acces methods
|
---|
[772] | 93 | inline T const& operator()(uint_4 ix, uint_4 iy, uint_4 iz) const ;
|
---|
| 94 | inline T& operator()(uint_4 ix, uint_4 iy, uint_4 iz);
|
---|
| 95 | inline T const& operator()(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu=0) const ;
|
---|
| 96 | inline T& operator()(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu=0);
|
---|
[785] | 97 | inline T const& operator[](uint_8 ip) const ;
|
---|
| 98 | inline T& operator[](uint_8 ip);
|
---|
[772] | 99 |
|
---|
| 100 | inline T const& Elem(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it=0, uint_4 iu=0) const ;
|
---|
| 101 | inline T& Elem(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it=0, uint_4 iu=0);
|
---|
| 102 | inline T const& ElemCheckBound(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it=0, uint_4 iu=0) const ;
|
---|
| 103 | inline T& ElemCheckBound(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it=0, uint_4 iu=0);
|
---|
| 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 |
|
---|
[772] | 145 | // A += -= (ajoute, soustrait element par element les deux tableaux )
|
---|
[804] | 146 | virtual TArray<T>& AddElt(const TArray<T>& a);
|
---|
[894] | 147 | //! Operator TArray += TArray
|
---|
[804] | 148 | inline TArray<T>& operator += (const TArray<T>& a) { return AddElt(a); }
|
---|
[970] | 149 | virtual TArray<T>& SubElt(const TArray<T>& a, bool fginv=false);
|
---|
[894] | 150 | //! Operator TArray -= TArray
|
---|
[804] | 151 | inline TArray<T>& operator -= (const TArray<T>& a) { return SubElt(a); }
|
---|
[787] | 152 | // Multiplication, division element par element les deux tableaux
|
---|
[804] | 153 | virtual TArray<T>& MulElt(const TArray<T>& a);
|
---|
[1072] | 154 | virtual TArray<T>& DivElt(const TArray<T>& a, bool fginv=false, bool divzero=false);
|
---|
[804] | 155 | // Recopie des valeurs, element par element
|
---|
| 156 | virtual TArray<T>& CopyElt(const TArray<T>& a);
|
---|
[1081] | 157 | // Recopie des valeurs avec conversion prealable, element par element
|
---|
| 158 | virtual TArray<T>& ConvertAndCopyElt(const BaseArray& a);
|
---|
[772] | 159 |
|
---|
[804] | 160 | // Somme et produit des elements
|
---|
| 161 | virtual T Sum() const ;
|
---|
| 162 | virtual T Product() const ;
|
---|
| 163 |
|
---|
[772] | 164 | // Impression, I/O, ...
|
---|
[813] | 165 | virtual string InfoString() const;
|
---|
| 166 | virtual void Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
|
---|
[772] | 167 |
|
---|
| 168 | // Pour la gestion de persistance
|
---|
| 169 | friend class FIO_TArray<T>;
|
---|
| 170 |
|
---|
| 171 | protected:
|
---|
| 172 |
|
---|
[894] | 173 | NDataBlock<T> mNDBlock; //!< Block for datas
|
---|
[1081] | 174 | mutable MuTyV my_mtv; //!< for use by ValueAtPosition()
|
---|
[772] | 175 | };
|
---|
| 176 |
|
---|
| 177 | ////////////////////////////////////////////////////////////////
|
---|
| 178 | // Surcharge d'operateur <<
|
---|
[894] | 179 | //! Print TArray \b a on stream \b os
|
---|
[772] | 180 | template <class T>
|
---|
| 181 | inline ostream& operator << (ostream& os, const TArray<T>& a)
|
---|
| 182 | { a.Print(os); return(os); }
|
---|
| 183 |
|
---|
| 184 | ////////////////////////////////////////////////////////////////
|
---|
| 185 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
| 186 |
|
---|
[958] | 187 | /*! \ingroup TArray \fn operator+(const TArray<T>&,T)
|
---|
| 188 | \brief Operator TArray = TArray + constant */
|
---|
[772] | 189 | template <class T> inline TArray<T> operator + (const TArray<T>& a, T b)
|
---|
[970] | 190 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 191 | result.Add(b); return result;}
|
---|
[772] | 192 |
|
---|
[958] | 193 | /*! \ingroup TArray \fn operator+(T,const TArray<T>&)
|
---|
| 194 | \brief Operator TArray = constant + TArray */
|
---|
[772] | 195 | template <class T> inline TArray<T> operator + (T b,const TArray<T>& a)
|
---|
[970] | 196 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 197 | result.Add(b); return result;}
|
---|
[772] | 198 |
|
---|
[958] | 199 | /*! \ingroup TArray \fn operator-(const TArray<T>&,T)
|
---|
| 200 | \brief Operator TArray = TArray - constant */
|
---|
[772] | 201 | template <class T> inline TArray<T> operator - (const TArray<T>& a, T b)
|
---|
[970] | 202 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 203 | result.Sub(b); return result;}
|
---|
[772] | 204 |
|
---|
[958] | 205 | /*! \ingroup TArray \fn operator-(T,const TArray<T>&)
|
---|
| 206 | \brief Operator TArray = constant - TArray */
|
---|
[772] | 207 | template <class T> inline TArray<T> operator - (T b,const TArray<T>& a)
|
---|
[970] | 208 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 209 | result.Sub(b,true); return result;}
|
---|
[772] | 210 |
|
---|
[958] | 211 | /*! \ingroup TArray \fn operator*(const TArray<T>&,T)
|
---|
| 212 | \brief Operator TArray = TArray * constant */
|
---|
[772] | 213 | template <class T> inline TArray<T> operator * (const TArray<T>& a, T b)
|
---|
[970] | 214 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 215 | result.Mul(b); return result;}
|
---|
[772] | 216 |
|
---|
[958] | 217 | /*! \ingroup TArray \fn operator*(T,const TArray<T>&)
|
---|
| 218 | \brief Operator TArray = constant * TArray */
|
---|
[772] | 219 | template <class T> inline TArray<T> operator * (T b,const TArray<T>& a)
|
---|
[970] | 220 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 221 | result.Mul(b); return result;}
|
---|
[772] | 222 |
|
---|
[958] | 223 | /*! \ingroup TArray \fn operator/(const TArray<T>&,T)
|
---|
| 224 | \brief Operator TArray = TArray / constant */
|
---|
[772] | 225 | template <class T> inline TArray<T> operator / (const TArray<T>& a, T b)
|
---|
[970] | 226 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 227 | result.Div(b); return result;}
|
---|
[772] | 228 |
|
---|
[970] | 229 | /*! \ingroup TArray \fn operator/(T,const TArray<T>&)
|
---|
| 230 | \brief Operator TArray = constant / TArray */
|
---|
| 231 | template <class T> inline TArray<T> operator / (T b, const TArray<T>& a)
|
---|
| 232 | {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 233 | result.Div(b, true); return result;}
|
---|
| 234 |
|
---|
[772] | 235 | ////////////////////////////////////////////////////////////////
|
---|
| 236 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 237 |
|
---|
[958] | 238 | /*! \ingroup TArray \fn operator+(const TArray<T>&,const TArray<T>&)
|
---|
| 239 | \brief Operator TArray = TArray + TArray */
|
---|
[772] | 240 | template <class T>
|
---|
| 241 | inline TArray<T> operator + (const TArray<T>& a,const TArray<T>& b)
|
---|
[970] | 242 | { TArray<T> result; result.SetTemp(true);
|
---|
| 243 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
| 244 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
| 245 | return result; }
|
---|
[772] | 246 |
|
---|
[958] | 247 | /*! \ingroup TArray \fn operator-(const TArray<T>&,const TArray<T>&)
|
---|
| 248 | \brief Operator TArray = TArray - TArray */
|
---|
[772] | 249 | template <class T>
|
---|
| 250 | inline TArray<T> operator - (const TArray<T>& a,const TArray<T>& b)
|
---|
[970] | 251 | { TArray<T> result; result.SetTemp(true);
|
---|
| 252 | if (b.IsTemp()) { result.Share(b); result.SubElt(a, true); }
|
---|
| 253 | else { result.CloneOrShare(a); result.SubElt(b); }
|
---|
| 254 | return result; }
|
---|
[772] | 255 |
|
---|
| 256 |
|
---|
| 257 | // --------------------------------------------------
|
---|
| 258 | // inline element acces methods
|
---|
| 259 | // --------------------------------------------------
|
---|
[894] | 260 |
|
---|
| 261 | //! Return element (ix,iy,iz,it,iu) value
|
---|
[772] | 262 | template <class T>
|
---|
| 263 | inline T const& TArray<T>::Elem(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu) const
|
---|
| 264 | {
|
---|
| 265 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 266 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 267 | it*step_[3] + iu*step_[4]) );
|
---|
| 268 | }
|
---|
| 269 |
|
---|
[894] | 270 | //! Return element (ix,iy,iz,it,iu) value
|
---|
[772] | 271 | template <class T>
|
---|
| 272 | inline T & TArray<T>::Elem(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu)
|
---|
| 273 | {
|
---|
| 274 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 275 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 276 | it*step_[3] + iu*step_[4]) );
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[894] | 279 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first
|
---|
[772] | 280 | template <class T>
|
---|
| 281 | inline T const& TArray<T>::ElemCheckBound(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu) const
|
---|
| 282 | {
|
---|
| 283 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
[804] | 284 | return(Elem(ix, iy, iz, it, iu));
|
---|
[772] | 285 | }
|
---|
| 286 |
|
---|
[894] | 287 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first
|
---|
[772] | 288 | template <class T>
|
---|
| 289 | inline T & TArray<T>::ElemCheckBound(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu)
|
---|
| 290 | {
|
---|
| 291 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
[804] | 292 | return(Elem(ix, iy, iz, it, iu));
|
---|
[772] | 293 | }
|
---|
| 294 |
|
---|
[894] | 295 | //! Return element (ix,iy,iz) value
|
---|
[772] | 296 | template <class T>
|
---|
| 297 | inline T const& TArray<T>::operator()(uint_4 ix, uint_4 iy, uint_4 iz) const
|
---|
| 298 | {
|
---|
| 299 | #ifdef SO_BOUNDCHECKING
|
---|
| 300 | CheckBound(ix, iy, iz, 0, 0, 4);
|
---|
| 301 | #endif
|
---|
| 302 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 303 | ix*step_[0] + iy*step_[1] + iz*step_[2]) );
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[894] | 306 | //! Return element (ix,iy,iz) value
|
---|
[772] | 307 | template <class T>
|
---|
| 308 | inline T & TArray<T>::operator()(uint_4 ix, uint_4 iy, uint_4 iz)
|
---|
| 309 | {
|
---|
| 310 | #ifdef SO_BOUNDCHECKING
|
---|
| 311 | CheckBound(ix, iy, iz, 0, 0, 4);
|
---|
| 312 | #endif
|
---|
| 313 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 314 | ix*step_[0] + iy*step_[1] + iz*step_[2]) );
|
---|
| 315 | }
|
---|
| 316 |
|
---|
[894] | 317 | //! Operator () : return element (ix,iy,iz,it,iu) value
|
---|
[772] | 318 | template <class T>
|
---|
| 319 | inline T const& TArray<T>::operator()(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu) const
|
---|
| 320 | {
|
---|
| 321 | #ifdef SO_BOUNDCHECKING
|
---|
| 322 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
| 323 | #endif
|
---|
| 324 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 325 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 326 | it*step_[3] + iu*step_[4]) );
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[894] | 329 | //! Operator () : return element (ix,iy,iz,it,iu) value
|
---|
[772] | 330 | template <class T>
|
---|
| 331 | inline T & TArray<T>::operator()(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu)
|
---|
| 332 | {
|
---|
| 333 | #ifdef SO_BOUNDCHECKING
|
---|
| 334 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
| 335 | #endif
|
---|
| 336 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 337 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 338 | it*step_[3] + iu*step_[4]) );
|
---|
| 339 | }
|
---|
| 340 |
|
---|
[785] | 341 |
|
---|
[894] | 342 | //! Operator [] : return element at positon ip
|
---|
[772] | 343 | template <class T>
|
---|
[785] | 344 | inline T const& TArray<T>::operator[](uint_8 ip) const
|
---|
[772] | 345 | {
|
---|
| 346 | #ifdef SO_BOUNDCHECKING
|
---|
| 347 | if (ip >= totsize_) throw( ParmError("TArray<T>::operator[] Out-of-bound Error") );
|
---|
| 348 | #endif
|
---|
[785] | 349 | return *(mNDBlock.Begin()+Offset(ip));
|
---|
[772] | 350 | }
|
---|
| 351 |
|
---|
[894] | 352 | //! Operator [] : return element at positon ip
|
---|
[772] | 353 | template <class T>
|
---|
[785] | 354 | inline T & TArray<T>::operator[](uint_8 ip)
|
---|
[772] | 355 | {
|
---|
| 356 | #ifdef SO_BOUNDCHECKING
|
---|
| 357 | if (ip >= totsize_) throw( ParmError("TArray<T>::operator[] Out-of-bound Error") );
|
---|
| 358 | #endif
|
---|
[785] | 359 | return *(mNDBlock.Begin()+Offset(ip));
|
---|
[772] | 360 | }
|
---|
| 361 |
|
---|
[785] | 362 |
|
---|
[894] | 363 | //! Return the value of first element
|
---|
[772] | 364 | template <class T>
|
---|
[787] | 365 | inline T TArray<T>::toScalar()
|
---|
[772] | 366 | {
|
---|
| 367 | if (Size() != 1) throw(SzMismatchError("TArray<T>::operator T() Size() != 1")) ;
|
---|
| 368 | return ( (*this)[0] );
|
---|
| 369 | }
|
---|
| 370 |
|
---|
[804] | 371 | // Typedef pour simplifier
|
---|
[956] | 372 | /*! \ingroup TArray
|
---|
| 373 | \typedef Array
|
---|
| 374 | \brief To simplified TArray<r_8> writing
|
---|
| 375 | */
|
---|
[804] | 376 | typedef TArray<r_8> Array;
|
---|
| 377 |
|
---|
[772] | 378 | } // Fin du namespace
|
---|
| 379 |
|
---|
| 380 | #endif
|
---|