62 return &mVector[mRowIndices[i]];
72 return &mVector[mRowIndices[i]];
77 static inline boost::shared_ptr<CORE_Array2D<T> >
New() {
98 void setSize(
const int& n,
const int& p);
117 inline void setValues(
const int& nvs,
const T* vs,
const int& nrs,
const int* rs) {
118 if (mHasToBeDeleted && (mVector!=
null) )
delete[] mVector;
125 if (mCapacity==0) mCapacity=1;
126 mVector=
new T[mCapacity];
130 for (
int i=0;i<nvs-1;i++) {
138 if (mHasToBeDeleted && (mRowIndices!=
null))
delete[] mRowIndices;
140 if (nrs==0) mRowsCapacity=1;
141 mRowIndices=
new int[mRowsCapacity];
142 int *inds=mRowIndices;
144 for (
int i=0;i<nrs-1;i++) {
154 mHasToBeDeleted=
true;
160 inline void setValues(
const int& nvs,T* vs,
const int& nrs,
int* rs,
const tBoolean& toBeDeleted) {
163 if (mHasToBeDeleted && (mVector!=
null) )
delete[] mVector;
166 if (mHasToBeDeleted && (mRowIndices!=
null) )
delete[] mRowIndices;
175 mHasToBeDeleted=toBeDeleted;
181 inline void set(
const int& i,
const int& j,
const T& obj) {
190 int newSize=size+rowSize;
191 if (newSize>mCapacity) {
192 int n=newSize*mCapacityFactor;
194 T *newVector=
new T[n];
196 for (
int i=0;i<mCapacity;i++) {
197 newVector[i]=mVector[i];
199 for (
int i=mCapacity;i<n;i++) {
202 if (mHasToBeDeleted && (mVector!=
null) ) {
207 mHasToBeDeleted=
true;
211 if (mRowsNumber+1>mRowsCapacity) {
212 mRowsCapacity=(mRowsNumber+1)*mCapacityFactor+1;
214 int *rows=
new int[mRowsCapacity];
215 for (
int i=0;i<mRowsNumber;i++) {
216 rows[i]=mRowIndices[i];
218 for (
int i=mRowsNumber;i<mRowsCapacity;i++) {
221 if (mHasToBeDeleted && (mRowIndices!=
null) )
delete[] mRowIndices;
223 mHasToBeDeleted=
true;
227 mRowIndices[mRowsNumber]=newSize;
237 int newValuesNumber=n+p;
241 for (
int i=r+1;i<mRowsNumber;i++)
244 if (newValuesNumber>mCapacity) {
246 int n=newValuesNumber*mCapacityFactor;
248 T *newVector=
new T[n];
250 for (
int i=0;i<mCapacity;i++) {
251 newVector[i]=mVector[i];
253 for (
int i=mCapacity;i<n;i++) {
256 if (mHasToBeDeleted && (mVector!=
null) )
delete[] mVector;
259 mHasToBeDeleted=
true;
263 if (mRowIndices[r+1]!=newValuesNumber) {
266 const T *curP=curN-p;
267 const T *curR=&mVector[mRowIndices[r+1]];
275 T *curN=&mVector[mRowIndices[r+1]];
276 const T *curP=curN-p;
290 T *v=mVector[mRowIndices[i]];
292 for (
int j=0;j<p-1;j++) {
304 T *v=mVector[mRowIndices[i]];
305 if (p>0)
for (
int j=0;j<p-1;j++) {*v=vs[j];v++;};*v=vs[p-1];
314 T *v=mVector[mRowIndices[i]];
315 if (p>0)
for (
int j=0;j<p-1;j++) {*v=(T) vs[j];v++;};*v=vs[p-1];
323 T *v=mVector[mRowIndices[i]];
325 for (
int j=0;j<p-1;j++) {
336 inline void add(
const int& i,
341 mVector[mRowIndices[i]+p]=obj;
356 return mRowIndices[mRowsNumber];
361 int *rowp=&mRowIndices[i+1];
363 return (*rowp)-(*row);
367 inline const T*
getRow(
const int& i)
const{
400 return mCapacityFactor;
void addRow(const int &rowSize)
add a row
Definition: CORE_Array2D.h:186
static boost::shared_ptr< CORE_Array2D< T > > New()
New constructor. return a shared pointer of CORE_Array2D.
Definition: CORE_Array2D.h:77
int getCapacity() const
get capacity
Definition: CORE_Array2D.h:404
CORE_Array2D< tBoolean > CORE_BooleanArray2D
Definition: CORE_Array2D.h:424
void setRowValue(const int &i, const CORE_Vector< Q > &vs)
set row value
Definition: CORE_Array2D.h:320
T * getValues()
get the values
Definition: CORE_Array2D.h:382
this class describes an array
Definition: CORE_Vector.h:18
virtual ~CORE_Array2D()
destroy an array of T*
Definition: CORE_Array2D.hpp:28
void copy(const CORE_Array2D< T > &src)
void copy
Definition: CORE_Array2D.hpp:117
int getCapacityFactor() const
get capacity factor
Definition: CORE_Array2D.h:399
this class describes a list
Definition: CORE_List.h:12
void set(const int &i, const int &j, const T &obj)
set the object at the index i
Definition: CORE_Array2D.h:181
CORE_Array2D()
build an array of T*
Definition: CORE_Array2D.hpp:9
void setValues(const int &nvs, const T *vs, const int &nrs, const int *rs)
set the values
Definition: CORE_Array2D.h:117
T * getRow(const int &i)
get row
Definition: CORE_Array2D.h:372
void setValues(const int &nvs, T *vs, const int &nrs, int *rs, const tBoolean &toBeDeleted)
set the values by reference
Definition: CORE_Array2D.h:160
CORE_Array2D< double > CORE_DoubleArray2D
Definition: CORE_Array2D.h:421
#define tBoolean
Definition: types.h:35
CORE_Array2D< int > CORE_IntArray2D
Definition: CORE_Array2D.h:423
void setRowValue(const int &i, const int &p, const T *vs)
set row value
Definition: CORE_Array2D.h:288
virtual void clear()
clear the array
Definition: CORE_Array2D.h:348
void setSize(const int &n, const int &p)
set the size of the 2D array n rows of n columns
Definition: CORE_Array2D.hpp:77
#define null
Definition: types.h:13
int getRowsNumber() const
get the rows number
Definition: CORE_Array2D.h:393
void setCapacity(const int &n, const int &p)
set total capacity of nRows & nColumns by row
Definition: CORE_Array2D.hpp:36
const T * operator[](int i) const
get the i-th row Assert in (i>-1) Assert in (i
Definition: CORE_Array2D.h:59
TYPEDEF_SPTR(CORE_DoubleArray2D)
const int * getRowIndices() const
get the row indices
Definition: CORE_Array2D.h:388
CORE_Array2D< tInteger > CORE_IntegerArray2D
Definition: CORE_Array2D.h:430
void setRowValue(const int &i, const vector< T > &vs)
set row value
Definition: CORE_Array2D.h:301
CORE_Array2D< tComplex > CORE_ComplexArray2D
Definition: CORE_Array2D.h:426
void copy(const CORE_Array2D< T > *src)
void copy
Definition: CORE_Array2D.h:109
void setRowSize(const int &r, const int &s)
set the row size
Definition: CORE_Array2D.h:233
T * operator[](int i)
get the i-th element Assert in (i>-1) Assert in (i
Definition: CORE_Array2D.h:69
void add(const int &i, const T &obj)
add an element at the end of row at index i
Definition: CORE_Array2D.h:336
int getRowSize(const int &i) const
return the size of the array at index i
Definition: CORE_Array2D.h:360
this class describes an array
Definition: CORE_Array.h:18
CORE_Array2D< tRelativeInteger > CORE_RelativeIntegerArray2D
Definition: CORE_Array2D.h:431
int getSize() const
return the size of the array
Definition: CORE_Array.h:226
this class describes an array of arrays
Definition: CORE_Array2D.h:13
tString toString() const
turn the array into string
Definition: CORE_Array2D.hpp:160
void setRowValue(const int &i, const CORE_Array< Q > &vs)
set row value
Definition: CORE_Array2D.h:311
CORE_Array2D< tCharacter > CORE_CharacterArray2D
Definition: CORE_Array2D.h:422
void setCapacityFactor(const int &i)
set capacity factor
Definition: CORE_Array2D.h:86
int getSize() const
return the size of the vector
Definition: CORE_Vector.h:387
#define tString
Definition: types.h:36
const T * getValues() const
get the values
Definition: CORE_Array2D.h:377
int getValuesNumber() const
return the size of the array
Definition: CORE_Array2D.h:355
CORE_Array2D< tShort > CORE_ShortArray2D
Definition: CORE_Array2D.h:428
void resize()
fit to the size
Definition: CORE_Array2D.hpp:93
CORE_Array2D< tFlag > CORE_FlagArray2D
Definition: CORE_Array2D.h:427
CORE_Array2D< tReal > CORE_RealArray2D
Definition: CORE_Array2D.h:425
const T * getRow(const int &i) const
get row
Definition: CORE_Array2D.h:367
CORE_Array2D< tString > CORE_StringArray2D
Definition: CORE_Array2D.h:429
#define ASSERT_IN(a)
Definition: types.h:82
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106