19 #ifndef _CLASSARRAY_H_ 20 #define _CLASSARRAY_H_ 91 return data[thesize-1];
98 return data[thesize-1];
136 assert(i <= thesize);
143 assert(thesize == j + n);
149 data[j + n] = data[j];
161 for(
int j = 0; j < n; j++ )
173 for(
int j = 0; j < t.
size(); j++ )
179 void remove(
int n = 0,
int m = 1)
184 assert(n + m <=
size());
186 for(
int j = n + m; j <
size(); j++ )
187 data[j - m] = data[j];
220 assert(memFactor >= 1);
222 if( newsize > themax )
223 reMax(
int(memFactor * newsize), newsize);
224 else if( newsize < 0 )
248 ptrdiff_t
reMax(
int newMax = 1,
int newSize = -1)
257 if( newMax < newSize )
261 if( newMax == themax )
273 for( i = 0; i <
size() && i < newSize; i++ )
274 new (&(newMem[i])) T(data[i]);
277 for( ; i < newMax; i++ )
278 new (&(newMem[i])) T();
281 ptrdiff_t pshift =
reinterpret_cast<char*
>(newMem) - reinterpret_cast<char*>(data);
284 for( i = themax-1; i >= 0; i-- )
304 for(
int i = 0; i <
size(); i++ )
305 data[i] = rhs.
data[i];
316 #ifdef ENABLE_CONSISTENCY_CHECKS 319 || (themax < thesize)
321 || (memFactor < 1.0) )
329 : thesize(old.thesize)
332 , memFactor(old.memFactor)
339 for( i = 0; i <
size(); i++ )
340 new (&(data[i])) T(old.
data[i]);
343 for( ; i <
max(); i++ )
344 new (&(data[i])) T();
357 explicit ClassArray(
int p_size = 0,
int p_max = 0,
double p_fac = 1.2)
361 thesize = (p_size < 0) ? 0 : p_size;
363 if( p_max > thesize )
366 themax = (thesize == 0) ? 1 : thesize;
371 for(
int i = 0; i <
max(); i++ )
372 new (&(data[i])) T();
382 for(
int i = themax-1; i >= 0; i-- )
391 #endif // _CLASSARRAY_H_ Memory allocation routines.
ClassArray(const ClassArray &old)
Copy constructor.
void insert(int i, const ClassArray< T > &t)
Inserts all elements from t before i 'th element.
void insert(int i, int n, const T t[])
Inserts n elements from t before i 'the element.
double memFactor
memory extension factor.
bool isConsistent() const
Consistency check.
T & last()
Reference to last element.
const T & operator[](int n) const
Reference to n 'th const element.
void spx_alloc(T &p, int n=1)
Allocate memory.
int thesize
number of used elements in array data
int size() const
Returns number of elements.
const T * get_const_ptr() const
Gets a const C pointer to the data.
Safe arrays of class objects.Class ClassArray provides safe arrays of general C++ objects (in contras...
void append(const ClassArray< T > &t)
Appends all elements from t.
int max() const
Returns maximum number of elements.
const T & last() const
Reference to last const element.
void reSize(int newsize)
Resets size to newsize.
Debugging, floating point type and parameter definitions.
ClassArray & operator=(const ClassArray &rhs)
Assignment operator.
void append(int n, const T t[])
Appends n elements from t.
T * get_ptr()
Gets a C pointer to the data.
void removeLast(int m=1)
Removes m last elements.
Everything should be within this namespace.
virtual ~ClassArray()
Destructor.
T & operator[](int n)
Reference to n 'th element.
int themax
the length of array data and
ptrdiff_t reMax(int newMax=1, int newSize=-1)
Resets maximum number of elements.
T * data
the array of elements
void insert(int i, int n)
Inserts n uninitialized elements before i 'th element.
void append(const T &t)
Appends element t.
#define MSGinconsistent(name)
void spx_free(T &p)
Release memory.
void clear()
Removes all elements.
ClassArray(int p_size=0, int p_max=0, double p_fac=1.2)
Default constructor.