#include <STK_Array1D.h>
Inherits IArray1DBase< TYPE, TYPE, Array1D< TYPE > >.
Public Types | |
| typedef IArrayBase< TYPE * > | _IArrayBaseType |
| typedef IArray1DBase< TYPE, TYPE, Array1D< TYPE > > | _IArray1DType |
Public Member Functions | |
| Array1D (const Inx &I=Inx()) | |
| Array1D (const Inx &I, const TYPE &v) | |
| Array1D (const Array1D &T, bool ref=false) | |
| Array1D (const Array1D &T, const Inx &I) | |
| Array1D (TYPE *q, const Inx &I, const Integer &index=0) | |
| Array1D (const _IArrayBaseType &T, const Inx &I, const Integer &index) | |
| virtual | ~Array1D () |
| TYPE & | getElt (const Integer &pos) |
| const TYPE & | getElt (const Integer &pos) const |
| Array1D | getElt (const Inx &J) const |
| void | clear () |
| void | freeMem () |
| void | initialize (const Inx &I) |
| void | pushBackElts (const Integer &n=1) |
| void | insertElts (Integer pos, Integer n=1) |
| void | popBackElts (const Integer &n=1) |
| void | eraseElts (Integer pos, Integer n=1) |
| Array1D< TYPE > & | operator= (const Array1D< TYPE > &T) |
| Array1D & | operator= (const TYPE &v) |
| template<class LEAF > | |
| Array1D & | operator= (const ITContainer1D< TYPE, LEAF > &T) |
This container implements the interface class IArray1DBase.
Definition at line 69 of file STK_Array1D.h.
| typedef IArrayBase<TYPE*> STK::Array1D< TYPE >::_IArrayBaseType |
Type for the Base reference Class.
Reimplemented from STK::IArray1DBase< TYPE, TYPE, Array1D< TYPE > >.
Definition at line 75 of file STK_Array1D.h.
| typedef IArray1DBase<TYPE, TYPE, Array1D<TYPE> > STK::Array1D< TYPE >::_IArray1DType |
Type for the IArray1DBase Class.
Definition at line 78 of file STK_Array1D.h.
| STK::Array1D< TYPE >::Array1D | ( | const Inx & | I = Inx() |
) | [inline] |
Default Ctor : beg_ =1 and end_ =0.
| I | range of the container |
Definition at line 85 of file STK_Array1D.h.
Referenced by STK::Array1D< Real >::getElt(), and STK::Array1D< String >::getElt().
00086 : _IArray1DType(I) 00087 { ;}
| STK::Array1D< TYPE >::Array1D | ( | const Inx & | I, | |
| const TYPE & | v | |||
| ) | [inline] |
Misc Ctor with beg and end, initialization with a constant.
| I | range of the container | |
| v | initial value of the container |
Definition at line 93 of file STK_Array1D.h.
00094 : _IArray1DType(I) 00095 { 00096 for (Integer i=this->first(); i<=this->last(); i++) 00097 this->setData(i, v); 00098 }
| STK::Array1D< TYPE >::Array1D | ( | const Array1D< TYPE > & | T, | |
| bool | ref = false | |||
| ) | [inline] |
Copy Ctor.
| T | the container to copy | |
| ref | true if T is wrapped |
Definition at line 104 of file STK_Array1D.h.
00105 : _IArray1DType(T, ref) 00106 { 00107 // check if we want just a reference 00108 if (!ref) 00109 { 00110 for (Integer j=this->first(); j<=this->last(); j++) 00111 this->setData(j, T.getData(j)); 00112 } 00113 }
| STK::Array1D< TYPE >::Array1D | ( | const Array1D< TYPE > & | T, | |
| const Inx & | I | |||
| ) | [inline] |
Ctor by reference, ref_=1.
| T | the container to wrap | |
| I | range of the datas to wrap |
Definition at line 119 of file STK_Array1D.h.
00120 : _IArray1DType(T, I) 00121 { ;}
| STK::Array1D< TYPE >::Array1D | ( | TYPE * | q, | |
| const Inx & | I, | |||
| const Integer & | index = 0 | |||
| ) | [inline] |
Wrapper Ctor : the container is a reference.
| q | pointer on datas | |
| I | range of the datas | |
| index | index (row or col) of the datas |
Definition at line 128 of file STK_Array1D.h.
00129 : _IArray1DType(q, I, index) 00130 { ;}
| STK::Array1D< TYPE >::Array1D | ( | const _IArrayBaseType & | T, | |
| const Inx & | I, | |||
| const Integer & | index | |||
| ) | [inline] |
Ctor by reference, ref_=1.
| T | the container to wrap | |
| I | the range of the datas to wrap | |
| index | the index of the col to wrap |
Definition at line 137 of file STK_Array1D.h.
00141 : _IArray1DType(T.getData(index), I, index) 00142 { ;}
| virtual STK::Array1D< TYPE >::~Array1D | ( | ) | [inline, virtual] |
Virtual Dtor: allocated memory is liberated by IArrayBase base class.
Definition at line 147 of file STK_Array1D.h.
| TYPE& STK::Array1D< TYPE >::getElt | ( | const Integer & | pos | ) | [inline] |
access to one element.
| pos | index of the element |
Reimplemented from STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Definition at line 154 of file STK_Array1D.h.
Referenced by STK::Array1D< Real >::eraseElts(), STK::Array1D< Real >::insertElts(), STK::Array1D< Real >::operator*=(), STK::Array1D< Real >::operator+=(), STK::Array1D< Real >::operator-=(), and STK::Array1D< Real >::operator/=().
00155 { return this->getData(pos);}
| const TYPE& STK::Array1D< TYPE >::getElt | ( | const Integer & | pos | ) | const [inline] |
access to one element const.
| pos | index of the const element |
Reimplemented from STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Definition at line 160 of file STK_Array1D.h.
00161 { return this->getData(pos);}
| Array1D STK::Array1D< TYPE >::getElt | ( | const Inx & | J | ) | const [inline] |
access to many elements.
| J | the range of the elements |
Reimplemented from STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Definition at line 166 of file STK_Array1D.h.
00167 { 00168 #ifdef STK_BOUNDS_CHECK 00169 if ((J.first()<this->first())) 00170 { throw std::out_of_range("Array1D::getElt(J) " 00171 "J.first()<this->first()"); 00172 } 00173 if ((J.last()>this->last())) 00174 { throw std::out_of_range("Array1D::getElt(J) " 00175 "J.last()>this->last()"); 00176 } 00177 #endif 00178 return Array1D(*this, J); 00179 }
| void STK::Array1D< TYPE >::clear | ( | ) | [inline] |
Clear the object. Memory is liberated and the range of the Container is set to 0:-1.
Reimplemented from STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.
Definition at line 186 of file STK_Array1D.h.
Referenced by STK::ReadWriteCsv::clear(), STK::IArray2DBase< Real, Real *, ArrayHo< Real >, Array1D< Real >, MatrixUpperTriangular >::initHo(), STK::Array1D< Real >::initialize(), and STK::Array1D< String >::initialize().
00187 { 00188 if (this->isRef()) return; // Nothing to do for ref 00189 this->freeMem(); // Free Mem 00190 this->setRange(); // Set dimension to default 00191 }
| void STK::Array1D< TYPE >::freeMem | ( | ) | [inline] |
Method for memory desallocation. Memory is liberated and the range of the Container is set to begin:begin-1.
Definition at line 196 of file STK_Array1D.h.
Referenced by STK::Array1D< Real >::clear(), STK::Array1D< String >::clear(), STK::Array1D< Real >::eraseElts(), STK::Array1D< String >::eraseElts(), STK::IArray2DBase< Real, Real *, ArrayHo< Real >, Array1D< Real >, MatrixUpperTriangular >::freeHo(), STK::Array1D< Real >::popBackElts(), and STK::Array1D< String >::popBackElts().
00197 { 00198 if (this->isRef()) return; // Nothing to do for ref 00199 this->free1D(); // free the elts 00200 }
| void STK::Array1D< TYPE >::initialize | ( | const Inx & | I | ) | [inline] |
function for memory allocation and initialization. This method will free all allocated memory owned by this container before initialization.
| I | range of the container |
Definition at line 207 of file STK_Array1D.h.
Referenced by STK::IArray2DBase< Real, Real *, ArrayHo< Real >, Array1D< Real >, MatrixUpperTriangular >::initHo(), STK::IArray2D< Real, MatrixUpperTriangular >::initialize(), STK::Array1D< Real >::insertElts(), STK::Array1D< String >::insertElts(), STK::Array1D< Real >::pushBackElts(), and STK::Array1D< String >::pushBackElts().
00208 { 00209 // check if there is memory allocated 00210 this->clear(); 00211 // if we initialize the memory the container is not a reference 00212 this->setRef(false); 00213 // try to allocate memory 00214 this->init1D(I); 00215 // set the range of the container if init1D is successful 00216 this->setRange(I); 00217 }
| void STK::Array1D< TYPE >::pushBackElts | ( | const Integer & | n = 1 |
) | [inline] |
Add n Elts to the container.
| n | number of elements to add |
Reimplemented from STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.
Definition at line 222 of file STK_Array1D.h.
00223 { 00224 // if n<=0 nothing to do 00225 if (n <= 0) return; 00226 #ifdef STK_DEBUG 00227 // is this structure just a pointer? 00228 if (this->isRef()) 00229 { throw std::runtime_error("Array1D::pushBackElts(n) " 00230 "can't operate on references."); 00231 } 00232 #endif 00233 // If the container is empty : create it 00234 if (this->empty()) 00235 this->initialize(Inx(this->first(), this->first()+n-1)); 00236 else 00237 this->insertElts(this->last()+1, n); 00238 }
| void STK::Array1D< TYPE >::insertElts | ( | Integer | pos, | |
| Integer | n = 1 | |||
| ) | [inline] |
Insert n elts at the position pos of the container.
| pos | index where to insert elements | |
| n | number of elements to insert (default 1) |
Definition at line 244 of file STK_Array1D.h.
Referenced by STK::IArray2D< Real, MatrixUpperTriangular >::insertCols(), STK::Array1D< Real >::pushBackElts(), and STK::Array1D< String >::pushBackElts().
00245 { 00246 // if n<=0 nothing to do 00247 if (n <= 0) return; 00248 #ifdef STK_DEBUG 00249 // is this structure just a pointer? 00250 if (this->isRef()) 00251 { throw std::runtime_error("Array1D::insertElts(pos, n) " 00252 "can't operate on references."); 00253 } 00254 #endif 00255 #ifdef STK_BOUNDS_CHECK 00256 // check indices 00257 if (this->first() > pos) 00258 { throw std::out_of_range("Array1D::insertElts(pos, n) " 00259 "this->first() > pos"); 00260 } 00261 if (this->last()+1 < pos) 00262 { throw std::out_of_range("Array1D::insertElts(pos, n) " 00263 "this->last()+1 < pos"); 00264 } 00265 #endif 00266 // compute new range 00267 // allocate, if necessary, the mem for the elts 00268 if (this->getCapacity() < this->size()+n) 00269 { 00270 // temporary empty container 00271 Array1D Taux; 00272 // save elts 00273 this->swap(Taux); 00274 // compute range of the container after insertion 00275 Inx range(Taux.getRange()); 00276 range.incLast(n); 00277 // initialize 00278 try 00279 { 00280 this->initialize(range); 00281 } 00282 catch (std::runtime_error & error) // if an error occur 00283 { 00284 this->swap(Taux); // restore elts 00285 throw error; // and send again the exception 00286 } 00287 // copy first elts 00288 for (Integer k=this->first(); k<pos; k++) 00289 this->setData(k, Taux.getData(k)); 00290 // translate and copy last elts 00291 for (Integer k=this->last()-n; k>=pos; k--) 00292 this->setData(k+n, Taux.getData(k)); 00293 } 00294 else // enough space -> shift the last elts 00295 { 00296 // update range_ 00297 this->incLast(n); 00298 // translate datas 00299 for (Integer k=this->last()-n; k>=pos; k--) 00300 this->setData(k+n, this->getData(k)); 00301 } 00302 }
| void STK::Array1D< TYPE >::popBackElts | ( | const Integer & | n = 1 |
) | [inline] |
Delete last elts of the container.
| n | number of elts to delete |
Reimplemented from STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.
Definition at line 307 of file STK_Array1D.h.
Referenced by STK::IArray2D< Real, MatrixUpperTriangular >::popBackCols().
00308 { 00309 // if n<=0 nothing to do 00310 if (n <= 0) return; 00311 #ifdef STK_DEBUG 00312 // is this structure just a pointer? 00313 if (this->isRef()) 00314 { throw std::runtime_error("Array1D::popBackElts() " 00315 "can't operate on references."); 00316 } 00317 #endif 00318 #ifdef STK_BOUNDS_CHECK 00319 // if there is elts to erase 00320 if (this->getSize()<n) 00321 { throw std::out_of_range("Array1D::popBackElts(n) " 00322 "this->getSize() < n"); 00323 } 00324 #endif 00325 // update range 00326 this->decLast(n); 00327 // if there is no more elts 00328 if (this->size() == 0) this->freeMem(); 00329 }
| void STK::Array1D< TYPE >::eraseElts | ( | Integer | pos, | |
| Integer | n = 1 | |||
| ) | [inline] |
Delete n elts at the pos index to the container.
| pos | index where to delete elements | |
| n | number of elements to delete (default 1) |
Definition at line 335 of file STK_Array1D.h.
Referenced by STK::ReadWriteCsv::eraseCols(), and STK::IArray2D< Real, MatrixUpperTriangular >::eraseCols().
00336 { 00337 // if n==0 nothing to do 00338 if (n<=0) return; 00339 #ifdef STK_DEBUG 00340 // is this structure just a pointer? 00341 if (this->isRef()) 00342 { throw std::runtime_error("Array1D::eraseElts(pos, n) " 00343 "can't operate on references."); 00344 } 00345 #endif 00346 #ifdef STK_BOUNDS_CHECK 00347 // check bounds 00348 if (this->first() > pos) 00349 { throw std::out_of_range("Array1D::eraseElts(pos, n) " 00350 "this->first() > pos"); 00351 } 00352 if (this->last() < pos) 00353 { throw std::out_of_range("Array1D::eraseElts(pos, n) " 00354 "this->last() < pos"); 00355 } 00356 if (this->last() < pos+n-1) 00357 { throw std::out_of_range("Array1D::eraseElts(pos, n) " 00358 "this->last() < pos+n-1"); 00359 } 00360 #endif 00361 // update dimensions 00362 this->decLast(n); 00363 // translate remaining elts 00364 for (Integer k=pos; k<=this->last(); k++) 00365 this->setData(k, this->getData(k+n)); 00366 // if there is no more cols, free mem 00367 if (this->size() == 0) this->freeMem(); 00368 }
| Array1D<TYPE>& STK::Array1D< TYPE >::operator= | ( | const Array1D< TYPE > & | T | ) | [inline] |
operator = : overwrite the Array1D with t. We resize the object if this and T does not have the same size but if they have the same size, we don't modify the range of the object.
| T | the container to copy |
Definition at line 377 of file STK_Array1D.h.
00378 { 00379 // check size 00380 if (this->size()!=T.size()) this->resize(T.getRange()); 00381 // copy without ovelapping. 00382 if (this->first() < T.first()) 00383 { for (Integer i=this->first(), j=T.first(); j<=T.last(); i++, j++) 00384 this->setData(i, T.getData(j)); 00385 } 00386 else 00387 { for (Integer i=this->last(), j=T.last(); j>=T.first(); i--, j--) 00388 this->setData(i, T.getData(j)); 00389 } 00390 return *this; 00391 }
| Array1D& STK::Array1D< TYPE >::operator= | ( | const TYPE & | v | ) | [inline] |
operator= : set the container to a constant value.
| v | the value to set |
Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.
Definition at line 396 of file STK_Array1D.h.
00397 { 00398 for (Integer i=this->first(); i<=this->last(); i++) 00399 this->setData(i, v); 00400 return *this; 00401 }
| Array1D& STK::Array1D< TYPE >::operator= | ( | const ITContainer1D< TYPE, LEAF > & | T | ) | [inline] |
operator = : overwrite the ArrayHo with the ITContainer1D T. We resize the object if this and T does not have the same size but if they have the same size, we don't modify the range of the object.
| T | the container to copy |
Definition at line 410 of file STK_Array1D.h.
00411 { // We have to resize if this and T does not have the same size 00412 // but if they have the same size, we don't scale the index 00413 if (this->size()!=T.size()) this->resize(T.getRange()); 00414 00415 // copy without ovelapping 00416 if (this->first() < T.first()) 00417 { for (Integer j=this->first(), i=T.first(); i<=T.last(); j++, i++) 00418 this->setData(j, T[i]); 00419 } 00420 else 00421 { for (Integer j=this->last(), i=T.last(); i>=T.first(); j--, i--) 00422 this->setData(j, T[i]); 00423 } 00424 return *this; 00425 }
1.5.8