28 #ifndef _CLASSARRAY_H_ 29 #define _CLASSARRAY_H_ 100 return data[thesize - 1];
107 return data[thesize - 1];
145 assert(i <= thesize);
152 assert(thesize == j + n);
158 data[j + n] = data[j];
170 for(
int j = 0; j < n; j++)
182 for(
int j = 0; j < t.
size(); j++)
188 void remove(
int n = 0,
int m = 1)
193 assert(n + m <=
size());
195 for(
int j = n + m; j <
size(); j++)
196 data[j - m] = data[j];
229 assert(memFactor >= 1);
232 reMax(
int(memFactor * newsize), newsize);
257 ptrdiff_t
reMax(
int newMax = 1,
int newSize = -1)
283 for(i = 0; i <
size() && i < newSize; i++)
284 new(&(newMem[i])) T(data[i]);
287 for(; i < newMax; i++)
288 new(&(newMem[i])) T();
291 ptrdiff_t pshift =
reinterpret_cast<char*
>(newMem) - reinterpret_cast<char*>(data);
294 for(i = themax - 1; i >= 0; i--)
314 for(
int i = 0; i <
size(); i++)
315 data[i] = rhs.
data[i];
326 #ifdef ENABLE_CONSISTENCY_CHECKS 330 || (themax < thesize)
332 || (memFactor < 1.0))
341 : thesize(old.thesize)
344 , memFactor(old.memFactor)
352 for(i = 0; i <
size(); i++)
353 new(&(data[i])) T(old.
data[i]);
356 for(; i <
max(); i++)
370 explicit ClassArray(
int p_size = 0,
int p_max = 0,
double p_fac = 1.2)
374 thesize = (p_size < 0) ? 0 : p_size;
379 themax = (thesize == 0) ? 1 : thesize;
384 for(
int i = 0; i <
max(); i++)
395 for(
int i = themax - 1; i >= 0; i--)
404 #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.
#define SPX_MSG_INCONSISTENT(name)
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.
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.