GCpp general purpose C++ library  version 1.0
GVectT< T > Class Template Reference

#include <GVectT.hh>

Inheritance diagram for GVectT< T >:
GCollectionT< T >

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 ()
 
- Public Member Functions inherited from GCollectionT< T >
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 Public Member Functions inherited from GCollectionT< T >
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_intcurrent_index
 Index of current object in the vector.
 
u_int capacity
 Current size of the pointers array.
 
- Protected Attributes inherited from GCollectionT< T >
u_int options
 Collection option flags.
 
u_int count_item
 Number of objects in the collection.
 

Detailed Description

template<class T>
class GVectT< T >

Template class to define vector (array) of objects.

See GCpp template classes for more information about the template classes.

GVectT.png

Constructor & Destructor Documentation

template<class T >
GVectT< T >::GVectT ( u_int  size = 0,
u_int  opts = 0 
)
inline

Default constructor.

Parameters
sizeinitial size
optsoption flags

References GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, and GVectT< T >::iter_array.

template<class T >
GVectT< T >::GVectT ( u_int  size,
T &  data,
u_int  opts = 0 
)
inline

Constructor with data initialisation by reference. The data is added for each element by reference (not adopted).

Parameters
sizeinitial size
datadata initialisation object
optsoption flags

References GVectT< T >::Assign(), GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, and GVectT< T >::iter_array.

template<class T >
GVectT< T >::GVectT ( u_int  size,
T *  data,
u_int  opts = 0 
)
inline

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.

Parameters
sizeinitial size
datadata initialisation object pointer
optsoption flags

References GVectT< T >::Assign(), GVectT< T >::capacity, GVectT< T >::current_index, GDebugConst, and GVectT< T >::iter_array.

template<class T >
GVectT< T >::GVectT ( const GVectT< T > &  vector)

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.

Parameters
vectorvector 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().

template<class T >
GVectT< T >::GVectT ( const GVectT< T > &  vector,
u_int  opts 
)
template<class T >
GVectT< T >::~GVectT ( )
inlinevirtual

Destructor: the vector is emptied.

References GDebugDest.

Member Function Documentation

template<class T >
GVectIterT< T > GVectT< T >::__Assign ( T *  item,
u_int  index 
)
protectedvirtual

Base function to set a vector element.

Parameters
itemobject to put in the vector
indexindex of vector element

References gcollection::gAutoResize, GClassWarning, GDebugClass, GGetString(), and gcollection::gUniqueItem.

template<class T >
void GVectT< T >::__AutoResize ( u_int  size)
protectedvirtual

Function used for automatic resize. The new allocated size is given as argument, except if gcollection::gDoubleSize option is set.

Parameters
sizenew requested size

References gcollection::gDoubleSize.

template<class T >
int GVectT< T >::__Exist ( const T *  ptr,
int  except = -1 
) const
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).

Parameters
ptrobject pointer
exceptindex of object excluded from search
template<class T >
int GVectT< T >::__Find ( const T *  ptr,
int  except = -1 
) const
protectedvirtual

Internal function identical to __Exist() function, except that it moves the current iterator if the object is found.

Parameters
ptrobject pointer
exceptpointer on an iterator that is excluded from the search
template<class T >
void GVectT< T >::__Shift ( u_int  ind1,
u_int  ind2,
int  n = 1 
)
protectedvirtual

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.

Note
Obviously, this function creates holes in the vector (thst its role...)
Parameters
ind1first index of shifted elements (included)
ind2last index of shifted elements (included)
nshift value

References gcollection::gAutoResize, and gcollection::gShiftRemove.

template<class T >
T * GVectT< T >::__Take ( )
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.

template<class T >
GVectIterT< T > GVectT< T >::Assign ( T *  obj_ptr)
inlinevirtual

Set a vector element with an object given by pointer (adopted), at current position. The current position is moved one step forward.

Parameters
obj_ptrobject pointer

Referenced by GVectT< T >::GVectT().

template<class T >
GVectIterT< T > GVectT< T >::Assign ( T *  obj_ptr,
u_int  index 
)
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.

Parameters
obj_ptrobject pointer
indexvector position to assign

References GClassWarning, GDebugClass, gcollection::gDelete, and GGetString().

template<class T >
GVectIterT< T > GVectT< T >::Assign ( T &  obj_ref)
inlinevirtual

Set a vector element with an object given by pointer (adopted), at current position. The current position is moved one step forward.

Parameters
obj_refobject given by reference
template<class T >
GVectIterT< T > GVectT< T >::Assign ( T &  obj_ref,
u_int  index 
)
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.

Parameters
obj_refobject given by reference
indexvector position to assign

References GDebugClass, gcollection::gDeepCopy, gcollection::gDelete, and GGetString().

template<class T >
T & GVectT< T >::At ( u_int  n) const
inline

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...

Parameters
nelement number in the vector

References GClassError, and GGetString().

template<class T >
GVectIterT< T > GVectT< T >::Begin ( ) const
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=().

template<class T >
void GVectT< T >::Empty ( )
virtual

Function that remove all objects from the vector.

Implements GCollectionT< T >.

References gcollection::gShiftRemove.

template<class T >
GVectIterT< T > GVectT< T >::End ( ) const
inlinevirtual

Return the iterator at end of the vector (on last element). The function does not change current iterator.

template<class T >
bool GVectT< T >::Exist ( const T *  ptr) const
inlinevirtual

Check if an object belongs to the vector.

Parameters
ptrobject pointer
template<class T >
int GVectT< T >::Find ( const T *  ptr) const
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.

Parameters
ptrobject pointer
template<class T >
GVectIterT< T > GVectT< T >::First ( ) const
inline

Move current iterator to first element and returns it. If the vector is empty a Null iterator is returned.

template<class T >
u_int GVectT< T >::GetCapacity ( ) const
inlinevirtual

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=().

template<class T >
const GIterT< T > * GVectT< T >::GetIterPtr ( u_int  i) const
virtual

Return the pointer on an element of the vector iterator array.

Parameters
ielement index
template<class T >
GIterT< T > * GVectT< T >::GetIterPtr ( u_int  i)
virtual

Return the pointer on an element of the vector iterator array.

Parameters
ielement index
template<class T >
u_int GVectT< T >::GetSize ( ) const
inlinevirtual

Return the allocated size of the vector. The effective size is given by the GetSize() function from GCollectionT.

Reimplemented from GCollectionT< T >.

template<class T >
GVectIterT< T > GVectT< T >::Goto ( u_int  n = 0) const
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.

Parameters
nelement number in the vector
template<class T >
int GVectT< T >::Index ( ) const
inline

Return the index of current element (starting at 0). If the vector is empty, the function returns -1.

template<class T>
template<class Q >
bool GVectT< T >::IsInstanceOf ( ) const
inline

Macro from GCpp library that defines the following functions:

  • ClassName(): return the real class name of the object
  • StaticClassName(): return the used class name of the object (that may be a base class of the real object).
  • IsInstanceOf<T>(): return true if the current object is an instance of the template class name argument
  • Clone(): return an allocated copy of the object.
template<class T >
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.

template<class T >
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.

template<class T >
GVectIterT< T > GVectT< T >::Null ( )
inlinestatic

Returns a Null iterator (with NULL object pointer).

Referenced by GVectT< T >::GVectT(), and GVectT< T >::operator=().

template<class T >
GVectT< T > & GVectT< T >::operator= ( const GVectT< T > &  vector)

Affectation operator. The initial vector is emptied.

Parameters
vectorvector to copy.

References GVectT< T >::Begin(), GDebugClass, gcollection::gDelete, GVectT< T >::GetCapacity(), GCollectionT< T >::GetOptions(), GIterT< T >::IsFlagOn(), and GVectT< T >::Null().

template<class T >
T & GVectT< T >::operator[] ( u_int  n) const
inlinevirtual

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...

Parameters
nelement number in the vector

References GClassError, and GGetString().

template<class T >
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.

template<class T >
bool GVectT< T >::Remove ( )
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().

template<class T >
bool GVectT< T >::Remove ( u_int  index)
virtual

The function removes the element at argument index from the vector. If the delete flag from the iterator is set, the object is deleted.

template<class T >
bool GVectT< T >::Remove ( const T *  ptr,
bool  all = true 
)
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.

Parameters
ptrpointer to the object to remove from the vector
allif true, if the object is several times in the vector, all corresponding elements are removed
template<class T >
u_int GVectT< T >::Resize ( u_int  new_size)
virtual

Modify the vector capacity. If the requested size is smaller than current capacity, it is not modified. The function returns the resulting capacity.

Parameters
new_sizerequested allocation size

References GDebugClass, and GGetString().

template<class T >
T * GVectT< T >::Take ( )
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.

template<class T >
T * GVectT< T >::Take ( const T *  ptr)
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.

Parameters
ptrpointer to the object to take out of the vector

The documentation for this class was generated from the following files: