21 mVector=
new T[mCapacity];
34 mVector=
new T[mCapacity];
48 mVector=
new T[mCapacity];
52 for (
int i=0;i<mSize;i++) mVector[i]=(T) values[i];
59 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
71 mCVector=&mVector[mStartIndex];
77 if ((dim>=INT_MAX)||(dim<0))
81 if (dim==mCapacity)
return;
84 T *newVector=
new T[dim];
90 int p=mSize+mStartIndex;
93 for (
int i=0;i<n;i++) newVector[i]=mVector[i];
96 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
100 mCVector=&mVector[mStartIndex];
108 if ((mSize==mCapacity) && (mStartIndex==0))
return;
110 T *newVector=
new T[mSize];
112 for (
int i=0;i<mSize;i++)
113 newVector[i]=mCVector[i];
114 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
123 if ((n==mCapacity) && (mStartIndex==0)) {
128 T *newVector=
new T[n];
130 for (
int i=0;i<n;i++)
131 newVector[i]=mCVector[i];
132 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
143 if (mSize==n)
return;
145 int dim=mStartIndex+n;
147 if (dim<=mCapacity) mSize=n;
158 int dim=mSize+mStartIndex;
159 if (mCapacity<=dim) {
160 mCapacity=mStartIndex+(mSize+1)*mCapacityFactor;
162 T *newVector=
new T[mCapacity];
165 for (
int i=0;i<dim;i++) newVector[i]=mVector[i];
166 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
168 mCVector=&mVector[mStartIndex];
177 if ((v[0]!=
'[') && (v[0]!=
'('))
return;
181 int n=str->getTokensCount();
182 int newDim=n+fromIndex;
184 if (newDim>mCapacity) setCapacity(newDim);
187 setStartIndex(fromIndex);
194 while (str->hasNextToken()) {
202 const int& fromIndex) {
208 int newDim=narray+fromIndex;
211 if (newDim>mCapacity) setCapacity(newDim);
214 setStartIndex(fromIndex);
220 for (
int i=0;i<narray;i++) mCVector[i]=array[i];
226 int newDim=narray+fromIndex;
229 if (newDim>mCapacity) setCapacity(newDim);
232 setStartIndex(fromIndex);
238 for (
int i=0;i<narray;i++) mCVector[i]=values[i];
242 int narray=values.size();
243 int newDim=narray+fromIndex;
246 if (newDim>mCapacity) setCapacity(newDim);
249 setStartIndex(fromIndex);
255 for (
int i=0;i<narray;i++) mCVector[i]=values[i];
265 for (
int i=0;i<mSize;i++) {
272 hasExisted=(mSize!=k);
279 if (index>=size())
return false;
280 if (index<0)
return false;
282 for (
int i=index;i<n;i++)
283 mCVector[i]=mCVector[i+1];
290 if (n>=mSize)
return;
291 mCapacity=n+mStartIndex;
292 if ((mCapacity>=INT_MAX) || (mCapacity<0))
throw CORE_Exception(
"common/core",
"CORE_Array::contractToLastElement(const int& n)",
"capacity too big !"+
CORE_Integer::toString(mCapacity));
293 T *newVector=
new T[mCapacity];
296 int k=mSize-1+mStartIndex;
297 for (
int i=mCapacity-1;i>=0;i--) {
298 newVector[i]=mVector[k];
302 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
304 mCVector=&mVector[mStartIndex];
309 int dim=mSize+mStartIndex;
311 for (
int i=mSize;i>index;i--)
312 mCVector[i]=mCVector[i-1];
316 int n=index+mStartIndex;
317 mCapacity+=mCapacityFactor*mSize;
318 if ((mCapacity>=INT_MAX)|| (mCapacity<0))
throw CORE_Exception(
"common/core",
"CORE_Array::insert(const int& index,const T& obj)",
"capacity too big !"+
CORE_Integer::toString(mCapacity));
319 T *newVector=
new T[mCapacity];
323 for (
int i=0;i<n;i++) newVector[i]=mVector[i];
327 for (
int i=n+1;i<=dim;i++)
328 newVector[i]=mVector[i-1];
329 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
331 mCVector=&mVector[mStartIndex];
345 if (obj<mCVector[0]) {
348 }
else if (obj==mCVector[0]) {
349 if (evenIfEqual)
return insert(0,obj);
352 if (obj>mCVector[sf]) {
355 }
else if (obj==mCVector[sf]) {
356 if (evenIfEqual)
return insert(mSize-1,obj);
362 if (obj>mCVector[i]) si=i;
363 else if (obj==mCVector[i]) {
364 if (evenIfEqual)
return insert(i,obj);
369 if (obj==mCVector[sf]) {
370 if (evenIfEqual)
return insert(sf,obj);
373 if (obj==mCVector[si]) {
374 if (evenIfEqual)
return insert(si,obj);
377 return insert(sf,obj);
386 if (obj<mCVector[si]) {
389 if (obj>mCVector[sf]) {
395 if (obj>mCVector[i]) si=i;
396 else if (obj==mCVector[i])
return i;
399 if (mCVector[sf]==obj)
return sf;
400 if (mCVector[si]==obj)
return si;
410 if (obj<mCVector[si]) {
413 if (obj==mCVector[si]) {
416 if (obj>=mCVector[sf]) {
422 if (obj>mCVector[i]) si=i;
423 else if (obj==mCVector[i]) {
425 for (
int k=i-1;k>=0;k--)
426 if (obj!=mCVector[k])
return k+1;
431 if (mCVector[sf]==obj) {
432 for (
int k=sf-1;k>=0;k--)
433 if (obj!=mCVector[k])
return k+1;
436 if (mCVector[si]==obj) {
437 for (
int k=si-1;k>=0;k--)
438 if (obj!=mCVector[k])
return k+1;
441 for (
int k=si-1;k>=0;k--)
442 if (obj!=mCVector[k])
return k+1;
454 if (obj<mCVector[0]) {
457 if (obj==mCVector[0]) {
458 for (
int k=1;k<n;k++)
459 if (obj!=mCVector[k])
return k-1;
462 if (obj>=mCVector[sf]) {
468 if (obj>mCVector[i]) si=i;
469 else if (obj==mCVector[i]) {
471 for (
int k=i+1;k<n;k++)
472 if (obj!=mCVector[k])
return k-1;
478 if (mCVector[sf]==obj) {
479 for (
int k=sf+1;k<n;k++)
480 if (obj!=mCVector[k])
return k-1;
483 if (mCVector[si]==obj) {
484 for (
int k=si+1;k<n;k++)
485 if (obj!=mCVector[k])
return k-1;
488 for (
int k=sf+1;k<n;k++)
489 if (obj!=mCVector[k])
return k-1;
498 for (
int i=0;i<mid;i++) {
500 mCVector[i]=mCVector[j];
513 int newDim=mStartIndex+newSize;
515 if (newDim<mCapacity) {
517 for (
int i=mSize;i<newSize;i++) {
518 mCVector[i]=array[k];
523 mCapacity=mStartIndex+newSize*mCapacityFactor;
524 if ((mCapacity>=INT_MAX)|| (mCapacity<0))
throw CORE_Exception(
"common/core",
"CORE_Array::merge(const CORE_Array<T>& obj)",
"capacity too big !"+
CORE_Integer::toString(mCapacity));
525 T *newVector=
new T[mCapacity];
529 for (
int i=mStartIndex+mSize-1;i>=0;i--) newVector[i]=mVector[i];
532 for (
int i=mStartIndex+mSize;i<newDim;i++) {
533 newVector[i]=array[k];
537 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
539 mCVector=&mVector[mStartIndex];
548 for (
int i=0;i<dim;i++) {
561 for (
int i=dim-1;i>index+1;i--) {
562 mCVector[i]=mCVector[i-1];
571 int nIndices=indices.
getSize();
572 int nValues=values.getSize();
574 for (
int i=0;i<nValues;i++)
575 nValuesToAdd+=values[i]->getSize();
578 int dim=mStartIndex+mSize+nValuesToAdd;
580 T* newValues=
new T[dim];
583 int cur_newValues=dim-1;
584 int cur_indices=nIndices-1;
585 int cur_mVector=mStartIndex+mSize-1;
588 while (cur_indices>-1) {
589 insertIndex=indices[cur_indices]+mStartIndex;
593 for (
int i=cur_mVector;i>insertIndex;i--) {
594 newValues[cur_newValues]=mVector[i];
598 cur_mVector=insertIndex;
604 for (
int i=nVals-1;i>=0;i--) {
605 newValues[cur_newValues]=vals[i];
616 for (
int i=cur_mVector;i>=mStartIndex;i--) {
617 newValues[cur_newValues]=mVector[i];
624 mSize=dim-mStartIndex;
627 if ((mVector!=
null) && (mHasToBeDeleted))
delete[] mVector;
629 mCVector=&mVector[mStartIndex];
646 if (compare(items[i],
655 while ((j>=h) && (!compare(items[j-h],
676 if (compare(obj,values[0],order)) {
681 if (compare(values[sf],obj,order)) {
686 if (compare(values[0],obj,
"=")) {
689 if (compare(values[sf],obj,
"=")) {
698 if (compare(values[i],obj,
"=")) {
700 }
else if (compare(values[i],obj,order)) {
705 if (compare(obj,values[sf],
"=")) {
708 if (compare(obj,values[si],
"=")) {
void addAfterIndex(const int &index, const T &v)
add an element after index
Definition: CORE_Array.hpp:558
tString toString() const
return the string associated to the string
Definition: CORE_String.h:150
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
int getCapacity() const
return the memory allocation size of the array
Definition: CORE_Array.h:229
this class describes a list
Definition: CORE_List.h:12
int getSupIndex(const T &v) const
get the sup index of value return -1 if no value less than v
Definition: CORE_Array.hpp:447
int getCapacityFactor() const
get the capacity factor
Definition: CORE_Array.h:216
#define tBoolean
Definition: types.h:35
#define null
Definition: types.h:13
const T * getCompleteValues(int &s) const
get the values of the complete vector
Definition: CORE_Array.h:396
void reverse()
reverse the vector
Definition: CORE_Array.hpp:494
static void parse(const tString &str, unsigned char &c)
parse unsigned char c in str
Definition: CORE_String.h:418
const T & get(const int &i) const
get the value at index i Assert in (i>-1) Assert in (i
Definition: CORE_Array.h:181
void add(const T &obj)
add an element at the end re-allocate the array if capacity too small
Definition: CORE_Array.hpp:157
static int search(const T *values, const int &n, const T &value, const tString &order)
search the value in values array ordered in order
Definition: CORE_Array.hpp:666
void setSize(const int &n)
set the size of the array
Definition: CORE_Array.hpp:141
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
tBoolean remove()
remove the last element
Definition: CORE_Array.h:486
virtual ~CORE_Array()
destroy an array of T*
Definition: CORE_Array.hpp:57
this class describes an array
Definition: CORE_Array.h:18
int insertInOrder(const T &obj, const tBoolean &evenIfEqual)
insert the object in increasing order
Definition: CORE_Array.hpp:337
int getStartIndex() const
get start index
Definition: CORE_Array.h:220
int getSize() const
return the size of the array
Definition: CORE_Array.h:226
void sort()
sort the array in an increasing order
Definition: CORE_Array.h:540
void copy(const CORE_Array< T > &src)
void copy
Definition: CORE_Array.hpp:64
CORE_Array()
build an array of T*
Definition: CORE_Array.hpp:29
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:142
int getInfIndex(const T &v) const
get the inf index of value return -1 if no value less than v
Definition: CORE_Array.hpp:404
tString toString() const
turn the array into string
Definition: CORE_Array.hpp:544
int insert(const int &i, const T &obj)
insert the object at index i re-allocate the array if capacity too small
Definition: CORE_Array.hpp:308
#define tString
Definition: types.h:36
void merge(const CORE_Array< T > &array)
merge the array in this
Definition: CORE_Array.hpp:507
static SP::CORE_String New()
create a class String
Definition: CORE_String.h:96
void resize()
resize the array to the util size
Definition: CORE_Array.hpp:107
int getIndex(const T &v) const
get the index of value return -1 if no value in index
Definition: CORE_Array.hpp:380
void setCapacity(const int &c)
set the capacity of the vector
Definition: CORE_Array.hpp:76
void setValues(const CORE_Array< T > &array, const int &fromIndex)
Definition: CORE_Array.hpp:201
void contractToLastElements(const int &n)
keep only the last n elements of the array and set its capacity also to n
Definition: CORE_Array.hpp:289
tBoolean removeAtIndex(const int &i)
Definition: CORE_Array.hpp:278
void addAfterIndices(const CORE_Array< int > &indices, CORE_SharedPointersList< CORE_Array< T > > &values)
add alements after indices
Definition: CORE_Array.hpp:568