81 assert(n >= 0 && n < num);
87 assert(n >= 0 && n < num);
131 assert(newdata != 0);
134 for(k = 0; k < i; ++k)
136 new(&(newdata[k])) T();
137 newdata[k] = data[k];
142 for(; k < i + n; ++k)
143 new(&(newdata[k])) T();
146 for(k = i; k <
num; ++k)
148 new(&(newdata[n + k])) T();
149 newdata[n + k] = data[k];
162 void insert(
int i,
int n,
const T* p_array)
166 for(n--; n >= 0; --n)
167 data[n + i] = p_array[n];
173 int n = p_array.
size();
176 for(n--; n >= 0; --n)
177 data[n + i] = p_array.
data[n];
185 void remove(
int n = 0,
int m = 1)
187 assert(n >= 0 && m >= 0);
194 assert(num ==
size());
195 m -= (n + m <=
num) ? 0 : n + m - num;
200 assert(newdata != 0);
203 for(k = num - 1; k >= n + m; --k)
205 new(&(newdata[k - m])) T();
206 newdata[k - m] = data[k];
217 new(&(newdata[k])) T();
218 newdata[k] = data[k];
228 for(k = m - 1; k >= 0; --k)
237 assert((data == 0) == (num == 0));
267 remove(newsize, num - newsize);
268 else if(newsize > num)
287 for(
int i = 0; i <
num; ++i)
288 data[i] = rhs.
data[i];
313 for(k = 0; k <
num; ++k)
332 for(k = 0; k <
num; ++k)
335 data[k] = old.
data[k];
360 #ifdef ENABLE_CONSISTENCY_CHECKS 362 if(num < 0 || (num > 0 && data == 0))
Memory allocation routines.
int size() const
return the number of elements.
bool isConsistent() const
consistency check
const T & operator[](int n) const
reference n 'th element.
Safe arrays of arbitrary types.Class Array provides safe arrays of arbitrary type. Array elements are accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by.
void insert(int i, int n, const T *p_array)
insert n elements from p_array before i 'th element.
T * data
the array of elements
void clear()
remove all elements.
void append(const Array< T > &p_array)
append all elements from p_array.
void spx_alloc(T &p, int n=1)
Allocate memory.
Array< T > & operator=(const Array< T > &rhs)
assignment operator.
void insert(int i, const Array< T > &p_array)
insert all elements from p_array before i 'th element.
T & operator[](int n)
reference n 'th element.
Everything should be within this namespace.
void reSize(int newsize)
reset the number of elements.
void append(int n, const T *p_array)
append n elements from p_array.
Array(const Array< T > &old)
copy constructor
Array(int n=0)
default constructor.
void append(int n)
append n uninitialized elements.
#define MSGinconsistent(name)
void insert(int i, int n)
int num
the length of array data
void spx_free(T &p)
Release memory.