1 #ifndef CORE_Array2D_HPP
2 #define CORE_Array2D_HPP
15 mVector=
new T[mCapacity];
16 mRowIndices=
new int[mRowsCapacity];
29 if (mHasToBeDeleted) {
30 if (mVector!=
null)
delete[] mVector;
31 if (mRowIndices!=
null)
delete[] mRowIndices;
41 int size=n*p*mCapacityFactor;
42 T *newVector=
new T[size];
44 for (
int i=0;i<mCapacity;i++) {
45 newVector[i]=mVector[i];
47 for (
int i=mCapacity;i<size;i++) {
50 if (mHasToBeDeleted && (mVector!=
null) )
delete[] mVector;
57 if (n>mRowsCapacity) {
58 int size=getValuesNumber();
59 mRowsCapacity=n*mCapacityFactor+1;
60 int *rows=
new int[mRowsCapacity];
61 for (
int i=0;i<=mRowsNumber;i++) {
62 rows[i]=mRowIndices[i];
64 for (
int i=mRowsNumber+1;i<mRowsCapacity;i++) {
69 if (mHasToBeDeleted && (mRowIndices!=
null))
delete[] mRowIndices;
81 int *rowIndices=mRowIndices;
82 for (
int i=0;i<n-1;i++) {
94 if (mRowIndices[mRowsNumber]<mCapacity) {
96 mCapacity=mRowIndices[mRowsNumber];
97 T *newVector=
new T[mCapacity];
98 for (
int i=0;i<mCapacity;i++) {
99 newVector[i]=mVector[i];
101 if (mHasToBeDeleted && (mVector!=
null) )
delete[] mVector;
104 if (mRowsCapacity>mRowsNumber+1) {
105 mRowsCapacity=mRowsNumber+1;
106 int *newIndices=
new int[mRowsCapacity];
107 for (
int i=0;i<=mRowsNumber;i++) {
108 newIndices[i]=mRowIndices[i];
110 if (mHasToBeDeleted)
delete [] mRowIndices;
111 mRowIndices=newIndices;
113 mHasToBeDeleted=
true;
118 if (
this==&src)
return;
124 if (mCapacity==0) mCapacity=1;
126 if (mHasToBeDeleted) {
127 if (mVector!=
null)
delete[] mVector;
128 if (mRowIndices!=
null)
delete[] mRowIndices;
132 mRowsCapacity=mRowsNumber+1;
133 mRowIndices=
new int[mRowsCapacity];
134 mVector=
new T[mCapacity];
137 const T *srcV=src[0];
138 for (
int i=0;i<mCapacity-1;i++) {
147 int *curR=mRowIndices;
149 for (
int i=0;i<mRowsCapacity-1;i++) {
155 mHasToBeDeleted=
true;
162 int n=getValuesNumber();
163 int nRows=getRowsNumber();
167 const int *inds=&mRowIndices[1];
169 for (
int i=0;i<nRows;i++) {
170 const T * vs=(*this)[i];
174 for (
int j=0;j<p;j++) {
tString toString() const
return the string associated to the string
Definition: CORE_String.h:150
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
CORE_Array2D()
build an array of T*
Definition: CORE_Array2D.hpp:9
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 int * getRowIndices() const
get the row indices
Definition: CORE_Array2D.h:388
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
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:142
#define tString
Definition: types.h:36
int getValuesNumber() const
return the size of the array
Definition: CORE_Array2D.h:355
void resize()
fit to the size
Definition: CORE_Array2D.hpp:93