template<class TYPE> class GArrayTemplate: protected GArrayBase

Common base class for all dynamic arrays.

Inheritance:


Public Methods

[more]int size() const
Returns the number of elements in the array.
[more]int lbound() const
Returns the lower bound of the valid subscript range.
[more]int hbound() const
Returns the upper bound of the valid subscript range.
[more]inline TYPE& operator[](int const n)
Returns a reference to the array element for subscript n.
[more]inline const TYPE& operator[](int n) const
Returns a constant reference to the array element for subscript n.
[more] operator TYPE* ()
Returns a pointer for reading or writing the array elements.
[more] operator const TYPE* () const
Returns a pointer for reading (but not modifying) the array elements.
[more]void empty()
Erases the array contents.
[more]void touch(int n)
Extends the subscript range so that it contains n.
[more]void resize(int hibound)
Resets the valid subscript range to 0---hibound.
[more]void resize(int lobound, int hibound)
Resets the valid subscript range to lobound---hibound.
[more]void shift(int disp)
Shifts the valid subscript range.
[more]void del(int n, int howmany=1)
Deletes array elements.
[more]void ins(int n, int howmany=1)
Insert new elements into an array.
[more]void ins(int n, const TYPE &val, int howmany=1)
Insert new elements into an array.
[more]void steal(GArrayTemplate &ga)
Steals contents from array ga.
[more]void sort()
Sort array elements.
[more]void sort(int lo, int hi)
Sort array elements in subscript range lo to hi.


Documentation

Common base class for all dynamic arrays. Class GArrayTemplate implements all methods for manipulating arrays of type TYPE. You should not however create instances of this class. You should instead use class GArray, GTArray or GPArray.
oint size() const
Returns the number of elements in the array.

oint lbound() const
Returns the lower bound of the valid subscript range.

oint hbound() const
Returns the upper bound of the valid subscript range.

oinline TYPE& operator[](int const n)
Returns a reference to the array element for subscript n. This reference can be used for both reading (as "a[n]") and writing (as "a[n]=v") an array element. This operation will not extend the valid subscript range: an exception GException is thrown if argument n is not in the valid subscript range.

oinline const TYPE& operator[](int n) const
Returns a constant reference to the array element for subscript n. This reference can only be used for reading (as "a[n]") an array element. This operation will not extend the valid subscript range: an exception GException is thrown if argument n is not in the valid subscript range. This variant of operator[] is necessary when dealing with a const GArray<TYPE>.

o operator TYPE* ()
Returns a pointer for reading or writing the array elements. This pointer can be used to access the array elements with the same subscripts and the usual bracket syntax. This pointer remains valid as long as the valid subscript range is unchanged. If you change the subscript range, you must stop using the pointers returned by prior invocation of this conversion operator.

o operator const TYPE* () const
Returns a pointer for reading (but not modifying) the array elements. This pointer can be used to access the array elements with the same subscripts and the usual bracket syntax. This pointer remains valid as long as the valid subscript range is unchanged. If you change the subscript range, you must stop using the pointers returned by prior invocation of this conversion operator.

ovoid empty()
Erases the array contents. All elements in the array are destroyed. The valid subscript range is set to the empty range.

ovoid touch(int n)
Extends the subscript range so that it contains n. This function does nothing if n is already int the valid subscript range. If the valid range was empty, both the lower bound and the upper bound are set to n. Otherwise the valid subscript range is extended to encompass n. This function is very handy when called before setting an array element:
       int lineno=1;
       GArray<GString> a;
       while (! end_of_file()) { 
         a.touch(lineno); 
         a[lineno++] = read_a_line(); 
       }
      

ovoid resize(int hibound)
Resets the valid subscript range to 0---hibound. This function may destroy some array elements and may construct new array elements with the null constructor. Setting hibound to -1 resets the valid subscript range to the empty range.

ovoid resize(int lobound, int hibound)
Resets the valid subscript range to lobound---hibound. This function may destroy some array elements and may construct new array elements with the null constructor. Setting lobound to 0 and hibound to -1 resets the valid subscript range to the empty range.

ovoid shift(int disp)
Shifts the valid subscript range. Argument disp is added to both bounds of the valid subscript range. Array elements previously located at subscript x will now be located at subscript x+disp.

ovoid del(int n, int howmany=1)
Deletes array elements. The array elements corresponding to subscripts n...n+howmany-1 are destroyed. All array elements previously located at subscripts greater or equal to n+howmany are moved to subscripts starting with n. The new subscript upper bound is reduced in order to account for this shift.

ovoid ins(int n, int howmany=1)
Insert new elements into an array. This function inserts howmany elements at position n into the array. These elements are constructed using the default constructor for type TYPE. All array elements previously located at subscripts n and higher are moved to subscripts n+howmany and higher. The upper bound of the valid subscript range is increased in order to account for this shift.

ovoid ins(int n, const TYPE &val, int howmany=1)
Insert new elements into an array. The new elements are constructed by copying element val using the copy constructor for type TYPE. See ins(int n, unsigned int howmany=1).

ovoid steal(GArrayTemplate &ga)
Steals contents from array ga. After this call, array ga is empty, and this array contains everything previously contained in ga.

ovoid sort()
Sort array elements. Sort all array elements in ascending order according to the less-or-equal comparison operator for type TYPE.

ovoid sort(int lo, int hi)
Sort array elements in subscript range lo to hi. Sort all array elements whose subscripts are in range lo to hi in ascending order according to the less-or-equal comparison operator for type TYPE. The other elements of the array are left untouched. An exception is thrown if arguments lo and hi are not in the valid subscript range.


Direct child classes:
GTArray
GPArray
GArray

Alphabetic index HTML hierarchy of classes or Java


DjVu is a trademark of LizardTech, Inc.
All other products mentioned are registered trademarks or trademarks of their respective companies.