/* Array.H: simple array template class */ #ifndef _VRML_ARRAY_H_ #define _VRML_ARRAY_H_ #include template class array { protected: T *s; int chunksz; // copies the used source string elements void copy(const array& src) { s = new T[src.size]; for (int i=0; i wouldn't find it on Irix6.2 void init (int len, T *t) { if (len > 0) { s = new T[len]; chunksz = len; if (t) { // copy the elements if there are given any for (int i=0; i0) init(len, t); } // copy constructor array(const array& src) { copy(src); } // assignement: the source string elements are copied array& operator=(const array& src) { if (this != &src) { delete [] s; copy(src); } return *this; } // destructor: also calls the destructor for the array elements. virtual ~array() { delete [] s; } // returns the i-th element, no range checking. Reference returned is only // valid until the next expansion. inline T& operator[](int i) const { return s[i]; } // appends an element to the end of the array, size is increased by one. // Returns a reference to the new element. The returned reference is only // valid until the next time the array is expanded. inline T& append(const T& elem) { if (size >= allocsz) { if (chunksz != 0) expand(chunksz); else if (size>15) expand(size); else expand(1); } s[size++] = elem; return s[size-1]; } // reserves 'extra' array cells at the end of the array. To be filled in by // the user. size is increased by 'extra'. inline void grow(int extra) { if (size+extra > allocsz) expand(size+extra-allocsz); size += extra; } friend ostream& operator<<(ostream& s, array& ar) { s << '['; for (int i=0; i