28 #ifndef _CHAINCON_EXTARRAY_H_ 29 #define _CHAINCON_EXTARRAY_H_ 33 #include "chomp/system/config.h" 41 template <
class ElemT>
77 template <
class ElemT>
84 template <
class ElemT>
92 template <
class ElemT>
96 for (int_t i = 0; i <
len; ++ i)
101 template <
class ElemT>
110 arr =
new ElemT [len];
111 for (int_t i = 0; i < len; ++ i)
112 arr [i] = other. arr [i];
121 template <
class ElemT>
125 throw "Negative offset requested for an extensible array.";
129 arr =
new ElemT [len];
133 int_t lenNew = len << 1;
136 ElemT *arrNew =
new ElemT [lenNew];
137 for (int_t i = 0; i < len; ++ i)
138 arrNew [i] = arr [i];
146 template <
class ElemT>
150 throw "Negative offset while reading an extensible array.";
152 throw "Offset too large while reading an extensible array.";
156 template <
class ElemT>
161 other. len = lenTemp;
162 ElemT *arrTemp = arr;
164 other. arr = arrTemp;
169 #endif // _CHAINCON_EXTARRAY_H_ A simple extendible array that extends automatically when needed.
int_t len
The length of the allocated array.
ElemT & operator[](int_t n)
Accesses a given element, and extends the array if necessary.
void swap(extarray< ElemT > &other)
Swaps contents with another extensible array.
ElemT * arr
The array of elements.
extarray()
Default constructor.
extarray< ElemT > & operator=(const extarray< ElemT > &other)
Assignment operator.