C++ main module for emicrom Package  1.0
CORE_Array2D.h
Go to the documentation of this file.
1 #ifndef CORE_Array2D_H
2 #define CORE_Array2D_H
3 
4 #include "CORE_ArrayList.h"
5 
23 template < class T>
24 class CORE_Array2D : public CORE_ArrayList<T> {
25 
26 private:
27 
28 
29  // number of rows
31 
32 
33  // the index of row i. The util size of the values is mRowIndices[mRowsNumber];
34  // the size if mRowCapacity > mRowsNumber+1
38 
39 
40  // CONSTRUCTORS
41 public:
44  CORE_Array2D();
45 
46 
47  // DESTRUCTORS
50  virtual ~CORE_Array2D();
51 
52 
53 
54 public:
55  // OPERATOR
56 
61  const T* operator[](const tUIndex& i) const {
62  ASSERT_IN(i<mRowCapacity);
63  return &CORE_ArrayList<T>::operator[](mRowIndices[i]);
64  };
65 
70  T* operator[](const tUIndex& i) {
71  ASSERT_IN(i<mRowCapacity);
72  return &CORE_ArrayList<T>::operator[](mRowIndices[i]);
73  };
74 
80  const T& operator()(const tUIndex& i,const tUIndex& j) {
81  ASSERT_IN(i<mRowCapacity);
82  return CORE_ArrayList<T>::operator[](mRowIndices[i]+j);
83  };
89  const T& operator()(const tUIndex& i,const tUIndex& j) const {
90  ASSERT_IN(i<mRowCapacity);
91  return CORE_ArrayList<T>::operator[](mRowIndices[i]+j);
92  };
93 
94 
95 
98  static inline boost::shared_ptr<CORE_Array2D<T> > New() {
99  boost::shared_ptr<CORE_Array2D<T> > p(new CORE_Array2D<T>(),CORE_Object::Delete());
100  return p;
101  };
102 
103 private:
107  void allocateRows(const tUIndex& n);
108 
111  void desallocateRows();
112 
113  // set METHODS
114  // ============
115 public:
118  virtual void clear(){
119  setSize(0,0);
120  };
121 
126  void setSize(const tUIndex& nRows,const tUIndex& nCols);
127 
132  void reserve(const tUIndex& nRows,const tUIndex& nCols);
133 
136  virtual void fitToSize();
137 
138 
139 
143  void copy(const CORE_Array2D<T>& v);
144 
148  inline void copy(const CORE_Array2D<T>* v){
149  if (v!=null) copy(*v);
150  else clear();
151  };
152 
153 
157  void setRowsNumber(const tUIndex& nRows);
158 
163  void setRowSize(const tUIndex& i,const tUIndex& n);
164 
171  void setValues(const tUIndex& nvs,const T* vs,const tUIndex& nrs,const tUIndex* rs);
172 
173 
176  void setValuesByReference(const tUIndex& nvs,T* vs,const tUIndex& nrs,tUIndex* rs);
177 
180  inline void set(const tUIndex& i,const tUIndex& j,const T& obj) {
181  (*this)(i,j)=obj;
182  };
183 
187  void addRow(const tUIndex& rowSize);
188 
189 
195  template<class Q>
196  void setRowValue(const tUIndex& i,const tUIndex& p,const Q* vs);
197 
198 
203  template<class Q>
204  void setRowValue(const tUIndex& i,const vector<Q>& vs);
205 
210  template<class Q>
211  void setRowValue(const tUIndex& i,const CORE_Array<Q>& vs);
212 
213 
218  template<class Q>
219  void setRowValue(const tUIndex& i,const CORE_Vector<Q>& vs);
220 
221 
222 
227  inline void add(const tUIndex& iRow,
228  const T& obj){
229  //get the index to add
230  tUIndex *i0=&mRowIndices[iRow];
231  tUIndex index=(*i0)+getColumnsNumber(iRow);
232  //insert the element obj at index index
233  this->insertAtIndex(index,obj);
234 
235  //update the row indices
236  i0++;
237  for (tUIndex i=iRow+1;i<=mRowsNumber;i++) {
238  (*i0)++;
239  i0++;
240  }
241  };
242 
243 
244 
245 
246 
247  // get METHODS
248  // ============
249 
253  inline const tUIndex& getValuesNumber() const {
254  return CORE_Array<T>::getSize();
255  };
256 
261  inline tUIndex getRowSize(const tUIndex& i) const {
262  ASSERT_IN(i<mRowCapacity);
263  return mRowIndices[i+1]-mRowIndices[i];
264  };
269  inline tUIndex getColumnsNumber(const tUIndex& i) const {
270  return getRowSize(i);
271  };
272 
276  inline const T* getRow(const tUIndex& i) const{
277  return (*this)[i];
278  };
282  inline T* getRow(const tUIndex& i) {
283  return (*this)[i];
284  };
285 
288  inline const T* getValues() const {
289  return getRow(0);
290  };
293  inline T* getValues() {
294  return getRow(0);
295  };
296 
300  inline const tUIndex* getRowIndices() const {
301  return mRowIndices;
302  };
306  inline const tUIndex& getRowsNumber() const {
307  return mRowsNumber;
308  };
309 
310 
311  // other METHODS
312 
313 
317  tString toString() const;
318 
319 
320 };
321 
322 #include "CORE_Array2D.hpp"
323 
335 
336 
348 
349 #endif
CORE_Array2D< tInt > CORE_IntArray2D
Definition: CORE_Array2D.h:326
const tUIndex & getRowsNumber() const
get the rows number
Definition: CORE_Array2D.h:306
void allocateRows(const tUIndex &n)
allocate the rows array indices
Definition: CORE_Array2D.hpp:40
const tUIndex & getSize() const
return the size of the array for reading
Definition: CORE_Array.h:1018
static boost::shared_ptr< CORE_Array2D< T > > New()
New constructor. return a shared pointer of CORE_Array2D.
Definition: CORE_Array2D.h:98
CORE_Array2D< tBoolean > CORE_BooleanArray2D
Definition: CORE_Array2D.h:327
void copy(const CORE_Array2D< T > &v)
copy the array 2D
Definition: CORE_Array2D.hpp:135
T * getValues()
get the values
Definition: CORE_Array2D.h:293
this class describes an array
Definition: CORE_Vector.h:19
virtual void fitToSize()
fit to size
Definition: CORE_Array2D.hpp:125
void copy(const CORE_Array2D< T > *v)
copy the pointer of array 2D
Definition: CORE_Array2D.h:148
void add(const tUIndex &iRow, const T &obj)
add an element at the end of row at index iRow
Definition: CORE_Array2D.h:227
virtual ~CORE_Array2D()
destroy an array of T*
Definition: CORE_Array2D.hpp:22
const T * getRow(const tUIndex &i) const
get a pointer to the first element of row
Definition: CORE_Array2D.h:276
tUIndex getRowSize(const tUIndex &i) const
return the size of the row at index i
Definition: CORE_Array2D.h:261
CORE_Array2D()
build an array of T*
Definition: CORE_Array2D.hpp:9
const T & operator()(const tUIndex &i, const tUIndex &j)
get the element at index i,j
Definition: CORE_Array2D.h:80
tUIndex mRowCapacity
Definition: CORE_Array2D.h:36
#define tBoolean
Definition: types.h:139
void insertAtIndex(const tUIndex &i, const T &v)
insert the object at index i
Definition: CORE_ArrayList.hpp:122
virtual void clear()
clear the array
Definition: CORE_Array2D.h:118
#define null
Definition: types.h:144
const T & operator()(const tUIndex &i, const tUIndex &j) const
get the element at index i,j
Definition: CORE_Array2D.h:89
TYPEDEF_SPTR(CORE_DoubleArray2D)
CORE_Array2D< tInteger > CORE_IntegerArray2D
Definition: CORE_Array2D.h:333
const T & operator[](const tUIndex &i) const
get the i-th element Assert in (i>-1) Assert in (i<size());
Definition: CORE_Array.h:164
CORE_Array2D< tComplex > CORE_ComplexArray2D
Definition: CORE_Array2D.h:329
void reserve(const tUIndex &nRows, const tUIndex &nCols)
reserve of the 2D array of size nRows x nCols
Definition: CORE_Array2D.hpp:100
void desallocateRows()
desallocate the rows
Definition: CORE_Array2D.hpp:28
const T * getValues() const
get the values
Definition: CORE_Array2D.h:288
void setRowsNumber(const tUIndex &nRows)
set the rows number
Definition: CORE_Array2D.hpp:111
this class describes an array
Definition: CORE_Array.h:19
CORE_Array2D< tDouble > CORE_DoubleArray2D
Definition: CORE_Array2D.h:324
this class describes an array of arrays ordered by rows The array like this 0 1 2 3 4 ...
Definition: CORE_Array2D.h:24
#define tUIndex
Definition: types.h:126
const T * operator[](const tUIndex &i) const
get the pointer the i-th row
Definition: CORE_Array2D.h:61
void addRow(const tUIndex &rowSize)
add a row of size row size at end
Definition: CORE_Array2D.hpp:328
const tUIndex * getRowIndices() const
get the row indices
Definition: CORE_Array2D.h:300
#define tString
Definition: types.h:135
CORE_Array2D< tUInteger > CORE_UIntegerArray2D
Definition: CORE_Array2D.h:334
tUIndex mRowsNumber
Definition: CORE_Array2D.h:30
CORE_Array2D< tChar > CORE_CharArray2D
Definition: CORE_Array2D.h:325
void setValues(const tUIndex &nvs, const T *vs, const tUIndex &nrs, const tUIndex *rs)
set the values
Definition: CORE_Array2D.hpp:161
void setRowSize(const tUIndex &i, const tUIndex &n)
the the size of the row at index i
Definition: CORE_Array2D.hpp:196
void setRowValue(const tUIndex &i, const tUIndex &p, const Q *vs)
set row value to vs array
Definition: CORE_Array2D.hpp:311
Definition: CORE_ArrayList.h:12
T * getRow(const tUIndex &i)
get the pointer to first element at row
Definition: CORE_Array2D.h:282
CORE_Array2D< tSInt > CORE_ShortArray2D
Definition: CORE_Array2D.h:331
void setValuesByReference(const tUIndex &nvs, T *vs, const tUIndex &nrs, tUIndex *rs)
set the values by reference
Definition: CORE_Array2D.hpp:179
CORE_Array2D< tFlag > CORE_FlagArray2D
Definition: CORE_Array2D.h:330
CORE_Array2D< tReal > CORE_RealArray2D
Definition: CORE_Array2D.h:328
tBoolean mIsPrivateRowAllocated
Definition: CORE_Array2D.h:35
T * operator[](const tUIndex &i)
get pointer to the first element of rows i
Definition: CORE_Array2D.h:70
CORE_Array2D< tString > CORE_StringArray2D
Definition: CORE_Array2D.h:332
void setSize(const tUIndex &nRows, const tUIndex &nCols)
set the size of the 2D array n rows of n columns
Definition: CORE_Array2D.hpp:90
tString toString() const
turn the array 2D into string
Definition: CORE_Array2D.hpp:339
const tUIndex & getValuesNumber() const
return the number of values
Definition: CORE_Array2D.h:253
#define ASSERT_IN(a)
Definition: types.h:196
tUIndex * mRowIndices
Definition: CORE_Array2D.h:37
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
tUIndex getColumnsNumber(const tUIndex &i) const
return the number of columns of the row at index i
Definition: CORE_Array2D.h:269