GCpp general purpose C++ library
version 1.0
|
#include <GVectT.hh>
Public Member Functions | |
template<class Q > | |
bool | IsInstanceOf () const |
template<class Q > | |
bool | IsInstanceOf () |
virtual GVectT< T > * | Clone () const |
virtual const char * | ClassName () const |
GVectT (u_int size=0, u_int opts=0) | |
GVectT (u_int size, T &data, u_int opts=0) | |
GVectT (u_int size, T *data, u_int opts=0) | |
GVectT (const GVectT< T > &vector) | |
GVectT (const GVectT< T > &vector, u_int opts) | |
GVectT< T > & | operator= (const GVectT< T > &vector) |
virtual | ~GVectT () |
virtual u_int | GetSize () const |
virtual u_int | GetCapacity () const |
virtual u_int | Resize (u_int new_size) |
virtual const GIterT< T > * | GetIterPtr (u_int i) const |
virtual GIterT< T > * | GetIterPtr (u_int i) |
virtual GVectIterT< T > | Begin () const |
virtual GVectIterT< T > | End () const |
virtual bool | Exist (const T *ptr) const |
virtual int | Find (const T *ptr) const |
GVectIterT< T > | Previous () const |
GVectIterT< T > | Next () const |
GVectIterT< T > | First () const |
GVectIterT< T > | Last () const |
GVectIterT< T > | Goto (u_int n=0) const |
T & | At (u_int n) const |
virtual T & | operator[] (u_int n) const |
int | Index () const |
virtual GVectIterT< T > | Assign (T *obj_ptr) |
virtual GVectIterT< T > | Assign (T *obj_ptr, u_int index) |
virtual GVectIterT< T > | Assign (T &obj_ptr) |
virtual GVectIterT< T > | Assign (T &obj_ptr, u_int index) |
virtual T * | Take () |
virtual T * | Take (const T *ptr) |
virtual bool | Remove () |
virtual bool | Remove (u_int index) |
virtual bool | Remove (const T *ptr, bool all=true) |
virtual void | Empty () |
![]() | |
template<class Q > | |
bool | IsInstanceOf () const |
template<class Q > | |
bool | IsInstanceOf () |
GCollectionT (u_int flg=0) | |
virtual | ~GCollectionT () |
virtual u_int | GetCount () const |
virtual u_int | GetOptions () const |
bool | CheckOptions (u_int opts) const |
bool | FixPositionOption () const |
bool | IsSortable () const |
bool | IsAlwaysSorted () const |
bool | IsReverseSorted () const |
bool | UniqueNameOption () const |
bool | IsCaseSensitive () const |
bool | DictSortOption () const |
Static Public Member Functions | |
static const char * | StaticClassName () |
static GVectIterT< T > | Null () |
![]() | |
static const char * | StaticClassName () |
Protected Member Functions | |
virtual int | __Exist (const T *ptr, int except=-1) const |
virtual int | __Find (const T *ptr, int except=-1) const |
virtual void | __AutoResize (u_int size) |
virtual void | __Shift (u_int ind1, u_int ind2, int n=1) |
virtual GVectIterT< T > | __Assign (T *item, u_int index) |
virtual T * | __Take () |
Protected Attributes | |
GIterT< T > * | iter_array |
Array of iterators. | |
u_int * | current_index |
Index of current object in the vector. | |
u_int | capacity |
Current size of the pointers array. | |
![]() | |
u_int | options |
Collection option flags. | |
u_int | count_item |
Number of objects in the collection. | |
Template class to define vector (array) of objects.
See GCpp template classes for more information about the template classes.
Default constructor.
size | initial size |
opts | option flags |
References GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, and GVectT< T >::iter_array.
Constructor with data initialisation by reference. The data is added for each element by reference (not adopted).
size | initial size |
data | data initialisation object |
opts | option flags |
References GVectT< T >::Assign(), GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, and GVectT< T >::iter_array.
Constructor with data initialisation by pointer. The data is cloned before being added for each element by pointer (and adopted). Note that the argument itself is not deleted by the vector.
size | initial size |
data | data initialisation object pointer |
opts | option flags |
References GVectT< T >::Assign(), GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, and GVectT< T >::iter_array.
Copy constructor. The object from the initial vector are dupplicated if they were adopted in the original vector, else they are added by reference in the current vector.
vector | vector to copy |
References GVectT< T >::Assign(), GVectT< T >::Begin(), GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, gcollection::gDelete, GVectT< T >::GetCapacity(), GIterT< T >::IsFlagOn(), GVectT< T >::iter_array, and GVectT< T >::Null().
Copy constructor with different options.
vector | vector to copy |
opts | option flags |
References GVectT< T >::Assign(), GVectT< T >::Begin(), GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, gcollection::gDelete, GVectT< T >::GetCapacity(), GIterT< T >::IsFlagOn(), GVectT< T >::iter_array, and GVectT< T >::Null().
Destructor: the vector is emptied.
References GDebugDest.
|
protectedvirtual |
Base function to set a vector element.
item | object to put in the vector |
index | index of vector element |
References gcollection::gAutoResize, GClassWarning, GDebugClass, GGetString(), and gcollection::gUniqueItem.
Function used for automatic resize. The new allocated size is given as argument, except if gcollection::gDoubleSize option is set.
size | new requested size |
References gcollection::gDoubleSize.
|
protectedvirtual |
Internal function to check if an object pointer exists in the vector. The function does not change current iterator.
An index can be excluded from the search (for example, to search the vector except current iterator, before delete).
ptr | object pointer |
except | index of object excluded from search |
|
protectedvirtual |
Internal function identical to __Exist() function, except that it moves the current iterator if the object is found.
ptr | object pointer |
except | pointer on an iterator that is excluded from the search |
Base function that shifts all elements from the vector. If elements may disappear at top or end of vector, they are removed from the vector. Nevertheless, if option gcollection::gAutoResize is set and elements are shifted towards the end of the vector, the size is increased in order to keep them. The sign of the argument determines in which direction the elements are shifted: to the top if negative, to the end if positive.
ind1 | first index of shifted elements (included) |
ind2 | last index of shifted elements (included) |
n | shift value |
References gcollection::gAutoResize, and gcollection::gShiftRemove.
|
protectedvirtual |
Internal function to take current object out of the vector In any case, the object is not deleted (even if the delete flag of the iterator is set). The function returns the pointer to the object.
References gcollection::gShiftRemove.
|
inlinevirtual |
Set a vector element with an object given by pointer (adopted), at current position. The current position is moved one step forward.
obj_ptr | object pointer |
Referenced by GVectT< T >::GVectT().
|
virtual |
Set a vector element with an object given by pointer (adopted), at index argument position. If successful, the current position is moved to this position.
obj_ptr | object pointer |
index | vector position to assign |
References GClassWarning, GDebugClass, gcollection::gDelete, and GGetString().
|
inlinevirtual |
Set a vector element with an object given by pointer (adopted), at current position. The current position is moved one step forward.
obj_ref | object given by reference |
|
virtual |
Set a vector element with an object given by pointer (adopted), at index argument position. If successful, the current position is moved to this position.
obj_ref | object given by reference |
index | vector position to assign |
References GDebugClass, gcollection::gDeepCopy, gcollection::gDelete, and GGetString().
Move current index to element n in the vector (starting at 0), and return the object (by reference). On an empty vector, this may result in a crash. If the vector is empty, or if n is greater than the number of elements in the vector, the function may result in a crash...
n | element number in the vector |
References GClassError, and GGetString().
|
inlinevirtual |
Return the iterator at beginning of the vector (on first element). The function does not change current iterator.
Referenced by GVectT< T >::GVectT(), and GVectT< T >::operator=().
|
virtual |
Function that remove all objects from the vector.
Implements GCollectionT< T >.
References gcollection::gShiftRemove.
|
inlinevirtual |
Return the iterator at end of the vector (on last element). The function does not change current iterator.
|
inlinevirtual |
Check if an object belongs to the vector.
ptr | object pointer |
|
inlinevirtual |
Check if an object belongs to the vector, and returns the iterator to this element (first one found). If the object is found, the current iterator is moved.
ptr | object pointer |
|
inline |
Move current iterator to first element and returns it. If the vector is empty a Null iterator is returned.
Return the allocated size of the vector. The effective size is given by the GetSize() function from GCollectionT.
Referenced by GVectT< T >::GVectT(), and GVectT< T >::operator=().
Return the pointer on an element of the vector iterator array.
i | element index |
Return the pointer on an element of the vector iterator array.
i | element index |
Return the allocated size of the vector. The effective size is given by the GetSize() function from GCollectionT.
Reimplemented from GCollectionT< T >.
|
inline |
Move current index to element n in the vector (starting at 0) and return the iterator. If the vector is empty, or if n is greater than the number of elements in the vector, a Null iterator is returned.
n | element number in the vector |
|
inline |
Return the index of current element (starting at 0). If the vector is empty, the function returns -1.
Macro from GCpp library that defines the following functions:
GVectIterT< T > GVectT< T >::Last | ( | ) | const |
Move current iterator to last element and returns it. If the vector is empty a Null iterator is returned.
GVectIterT< T > GVectT< T >::Next | ( | ) | const |
Move current iterator to next element and returns it. If there is no next element, current iterator is not changed and a Null iterator is returned.
|
inlinestatic |
Returns a Null iterator (with NULL object pointer).
Referenced by GVectT< T >::GVectT(), and GVectT< T >::operator=().
Affectation operator. The initial vector is emptied.
vector | vector to copy. |
References GVectT< T >::Begin(), GDebugClass, gcollection::gDelete, GVectT< T >::GetCapacity(), GCollectionT< T >::GetOptions(), GIterT< T >::IsFlagOn(), and GVectT< T >::Null().
Same as the function At, except that the current index in the vector is not modified. If the vector is empty, or if n is greater than the number of elements in the vector, the function may result in a crash...
n | element number in the vector |
References GClassError, and GGetString().
GVectIterT< T > GVectT< T >::Previous | ( | ) | const |
Move current iterator to previous element and returns it. If there is no previous element, current iterator is not changed and a Null iterator is returned.
|
virtual |
The function removes the current element from the vector. If the delete flag from the iterator is set, the object is deleted.
References GDebugClass, gcollection::gDelete, and GGetString().
The function removes the element at argument index from the vector. If the delete flag from the iterator is set, the object is deleted.
|
virtual |
Removes an object given by its pointer ptr, from the vector. Since several elements may correspond to the same object, they can all be removed, according to the all argument.
ptr | pointer to the object to remove from the vector |
all | if true, if the object is several times in the vector, all corresponding elements are removed |
Modify the vector capacity. If the requested size is smaller than current capacity, it is not modified. The function returns the resulting capacity.
new_size | requested allocation size |
References GDebugClass, and GGetString().
|
inlinevirtual |
Take current object out of the vector. In any case, the object is not deleted (even if the delete flag of the iterator is set). The function returns the pointer to the object.
|
virtual |
Take an object given by its pointer ptr object out of the vector (the first occurence found, in case there are several). In any case, the object is not deleted (even if the delete flag of the iterator is set). The function returns the pointer to the object.
ptr | pointer to the object to take out of the vector |