ArrayBaseT< TYPE > Class Template Reference
#include <Arrays.h>
Inheritance diagram for ArrayBaseT< TYPE >:

Detailed Description
template<class TYPE>
class ArrayBaseT< TYPE >
Dynamic array template base class.
This is an auxiliary template base class for DArray} and TArray} implementing some shared functions which {depend} on the type of the array elements (this is contrary to ArrayBase}). It's not supposed to be constructed by hands. Use DArray} and TArray} instead.
Definition at line 449 of file Arrays.h.
Public Member Functions | |
| virtual | ~ArrayBaseT (void) |
Arrays.h | |
Files #"Arrays.h"# and #"Arrays.cpp"# implement three array template classes. Class TArray} implements an array of objects of trivial types such as char#, int#, float#, etc. It is faster than general implementation for any type done in DArray} because it does not cope with element's constructors, destructors and copy operators. Although implemented as a template, which makes it possible to incorrectly use TArray} with non-trivial classes, it should not be done. A lot of things is shared by these three arrays. That is why there are more base classes: {itemize} ArrayBase} defines functions independent of the elements type ArrayBaseT} template class defining functions shared by DArray} and TArray} {itemize} The main difference between GArray} (now obsolete) and these ones is the copy-on-demand strategy, which allows you to copy array objects without copying the real data. It's the same thing, which has been implemented in GString} long ago: as long as you don't try to modify the underlying data, it may be shared between several copies of array objects. As soon as you attempt to make any changes, a private copy is created automatically and transparently for you - the procedure, that we call "copy-on-demand". Also, please note that now there is no separate class, which does fast sorting. Both TArray} (dynamic array for trivial types) and DArray} (dynamic array for arbitrary types) can sort their elements. { Historical comments} --- Leon chose to implement his own arrays because the STL classes were not universally available and the compilers were rarely able to deal with such a template galore. Later it became clear that there is no really good reason why arrays should be derived from containers. It was also suggested to create separate arrays implementation for simple classes and do the copy-on-demand strategy, which would allow to assign array objects without immediate copying of their elements. At this point DArray} and TArray} should only be used when it is critical to have the copy-on-demand feature. The GArray} implementation is a lot more efficient. Template array classes.
| |
| TYPE & | operator[] (int n) |
| const TYPE & | operator[] (int n) const |
| operator TYPE * () | |
| operator const TYPE * () const | |
| operator const TYPE * () | |
| void | ins (int n, const TYPE &val, unsigned int howmany=1) |
| void | sort () |
| void | sort (int lo, int hi) |
Protected Member Functions | |
| ArrayBaseT (void) | |
Member Function Documentation
| void ArrayBaseT< TYPE >::ins | ( | int | n, | |
| const TYPE & | val, | |||
| unsigned int | howmany = 1 | |||
| ) | [inline] |
Insert new elements into an array.
This function inserts howmany# elements at position n# into the array. The initial value val# is copied into the new elements. 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.
- Parameters:
-
n subscript of the first inserted element. val initial value of the new elements. howmany number of elements to insert.
| ArrayBaseT< TYPE >::operator const TYPE * | ( | ) | const [inline] |
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.
| ArrayBaseT< TYPE >::operator TYPE * | ( | ) | [inline] |
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.
| const TYPE & ArrayBaseT< TYPE >::operator[] | ( | int | n | ) | const [inline] |
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 DArray<TYPE>#.
Reimplemented in DPArray< TYPE >.
| TYPE & ArrayBaseT< TYPE >::operator[] | ( | int | n | ) | [inline] |
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.
Reimplemented in DPArray< TYPE >.
| void ArrayBaseT< TYPE >::sort | ( | int | lo, | |
| int | hi | |||
| ) |
Sort array elements in subscript range lo# to hi#.
Sort all array elements whose subscripts are in range lo#..hi# in ascending order. 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. Array elements are compared using the less-or-equal comparison operator for type TYPE#.
- Parameters:
-
lo low bound for the subscripts of the elements to sort. hi high bound for the subscripts of the elements to sort.
| void ArrayBaseT< TYPE >::sort | ( | ) |
The documentation for this class was generated from the following file:

