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);
223 reMax(
int(memFactor * newsize), newsize);
248 ptrdiff_t
reMax(
int newMax = 1,
int newSize = -1)
274 for(i = 0; i <
size() && i < newSize; i++)
275 new(&(newMem[i])) T(data[i]);
278 for(; i < newMax; i++)
279 new(&(newMem[i])) T();
282 ptrdiff_t pshift =
reinterpret_cast<char*
>(newMem) - reinterpret_cast<char*>(data);
285 for(i = themax - 1; i >= 0; i--)
305 for(
int i = 0; i <
size(); i++)
306 data[i] = rhs.
data[i];
317 #ifdef ENABLE_CONSISTENCY_CHECKS 321 || (themax < thesize)
323 || (memFactor < 1.0))
332 : thesize(old.thesize)
335 , memFactor(old.memFactor)
343 for(i = 0; i <
size(); i++)
344 new(&(data[i])) T(old.
data[i]);
347 for(; i <
max(); i++)
361 explicit ClassArray(
int p_size = 0,
int p_max = 0,
double p_fac = 1.2)
365 thesize = (p_size < 0) ? 0 : p_size;
370 themax = (thesize == 0) ? 1 : thesize;
375 for(
int i = 0; i <
max(); i++)
386 for(
int i = themax - 1; i >= 0; i--)
395 #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.