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

#include <GListT.hh>

Inheritance diagram for GListT< T >:
GCollectionT< T > GSortListT< T > GNamedListT< T >

Public Member Functions

template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
virtual GListT< T > * Clone () const
 
virtual const char * ClassName () const
 
 GListT (u_int opts=0)
 
 GListT (const GListT< T > &list)
 
 GListT (const GListT< T > &list, u_int opts)
 
GListT< T > & operator= (const GListT< T > &list)
 
virtual ~GListT ()
 
virtual GListIterT< T > Begin () const
 
virtual GListIterT< T > End () const
 
virtual bool Exist (const T *ptr) const
 
virtual GListIterT< T > Find (const T *ptr) const
 
virtual GListIterT< T > FindNext (const T *ptr) const
 
virtual GListIterT< T > FindPrevious (const T *ptr) const
 
virtual GListIterT< T > FindFirst (const T *ptr) const
 
virtual GListIterT< T > FindLast (const T *ptr) const
 
GListIterT< T > Current () const
 
GListIterT< T > Previous () const
 
GListIterT< T > Next () const
 
GListIterT< T > First () const
 
GListIterT< T > Last () const
 
GListIterT< T > Goto (u_int n=0) const
 
T & At (u_int n) const
 
int Index () const
 
virtual int Move (int n)
 
virtual bool MoveUp ()
 
virtual bool MoveDown ()
 
virtual bool MoveTop ()
 
virtual bool MoveBottom ()
 
virtual GListIterT< T > Add (T *obj_ptr)
 
virtual GListIterT< T > Insert (T *obj_ptr)
 
virtual GListIterT< T > Append (T *obj_ptr)
 
virtual GListIterT< T > Prepend (T *obj_ptr)
 
virtual GListIterT< T > Add (T &obj_ptr)
 
virtual GListIterT< T > Insert (T &obj_ptr)
 
virtual GListIterT< T > Append (T &obj_ptr)
 
virtual GListIterT< T > Prepend (T &obj_ptr)
 
virtual T * Take ()
 
virtual T * Take (const T *ptr)
 
virtual bool Remove ()
 
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 GetSize () const
 
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 GListIterT< T > Null ()
 
- Static Public Member Functions inherited from GCollectionT< T >
static const char * StaticClassName ()
 

Protected Member Functions

virtual GListIterT< T > * __Exist (const T *ptr, GListIterT< T > *except=NULL) const
 
virtual GListIterT< T > * __Find (const T *ptr, GListIterT< T > *except=NULL) const
 
virtual GListIterT< T > __Add (T *item)
 
virtual GListIterT< T > __Insert (T *item)
 
virtual T * __Take ()
 
virtual void __Swap (GListIterT< T > *iter)
 
virtual bool __MoveUp ()
 
virtual bool __MoveDown ()
 

Protected Attributes

GListIterT< T > ** first_item
 Iterator on first object in the list.
 
GListIterT< T > ** last_item
 Iterator on last object in the list.
 
GListIterT< T > ** current_item
 Iterator on current object in the list.
 
- 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 GListT< T >

Template class to define list of objects.

For the list, first_item and last_item allow to keep a constant algorithm speed when navigating through the list.

The current_item is an index indicating current position in the list. This is the reference position to add, insert, remove elements...

The first_item, last_item and current_item are defined as pointers to iterators, so that their content can be changed even in constant list object (to allow to navigate in the list, which requires to change the index)

See GCpp template classes for more information about the behaviour of collection template classes.

Adding and removing objects

The functions Add, Insert, Append and Prepend insert objects (either by pointer or by reference, respectively after current position, before current position, at the end of the list, at the beginning of the list.

Default behaviour (if no other option is selected, see gcollection namespace) is the following:

  • if an object is added by pointer, it is adopted by the list, and deleted when removed from the list.
  • if an object is added by reference, it is not deleted when removed, and the calling program may ensure that the object lives as long as it used in the list.

The functions Remove does what the function name obviously mean. If the object was adopted by the list, it is deleted.

The Take functions take an object out of the list, but do not delete it if it was adopted.

Internal functions

The internal functions are defined to adapt the behaviour of the list to the options. This behaviour may also be sophisticated in derived classes (see GSortListT and GNamedListT).

GListT.png

Constructor & Destructor Documentation

template<class T >
GListT< T >::GListT ( u_int  opts = 0)
inline

Default constructor.

Parameters
optsoption flags

References GListT< T >::current_item, GListT< T >::first_item, GDebugConst, and GListT< T >::last_item.

template<class T>
GListT< T >::GListT ( const GListT< T > &  list)

Copy constructor. The object from the initial list are dupplicated if they were adopted in the original list, else they are added by reference in the current list.

Parameters
listlist to copy

References GListT< T >::Add(), GListT< T >::Begin(), GListT< T >::current_item, GListT< T >::first_item, GDebugConst, gcollection::gDelete, GIterT< T >::IsFlagOn(), GListT< T >::last_item, and GListT< T >::Null().

template<class T>
GListT< T >::GListT ( const GListT< T > &  list,
u_int  opts 
)
template<class T >
GListT< T >::~GListT ( )
inlinevirtual

Destructor: the list is emptied.

References GDebugDest.

Member Function Documentation

template<class T>
GListIterT< T > GListT< T >::__Add ( T *  item)
protectedvirtual

Internal function to add an object to the list, after current iterator. Current iterator is moved to the added object. If the object has been successfully added, the function return the corresponding iterator, else it returns Null.

Parameters
itempointer to the object to add

Reimplemented in GTreeBranchT< T >, GNamedListT< T >, GNamedListT< GTreeNodeT< T > >, GNamedListT< GItem >, GSortListT< T >, GSortListT< GTreeNodeT< T > >, GSortListT< GItem >, and GSortListT< GString >.

References GClassWarning, GDebugClass, GGetString(), GGetStringHexa(), gcollection::gUniqueItem, GIterT< T >::item_ptr, GListIterT< T >::next_item, and GListIterT< T >::previous_item.

Referenced by GSortListT< T >::__Add(), and GSortListT< T >::__AddSorted().

template<class T>
GListIterT< T > * GListT< T >::__Exist ( const T *  ptr,
GListIterT< T > *  except = NULL 
) const
protectedvirtual

Internal function to check if an object pointer exists in the list. The function does not change current iterator.

An iterator can be excluded from the search (for example, to search the list except current iterator, before delete).

Parameters
ptrobject pointer
exceptpointer on an iterator that is excluded from the search

References GIterT< T >::item_ptr, and GListIterT< T >::next_item.

template<class T>
GListIterT< T > * GListT< T >::__Find ( const T *  ptr,
GListIterT< T > *  except = NULL 
) 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

Referenced by GIntervalList::Add().

template<class T>
GListIterT< T > GListT< T >::__Insert ( T *  item)
protectedvirtual
template<class T >
bool GListT< T >::__MoveDown ( )
protectedvirtual

Internal function to move current element down, without check.

References GListIterT< T >::next_item.

template<class T >
bool GListT< T >::__MoveUp ( )
protectedvirtual

Internal function to move current element up, without check.

References GListIterT< T >::previous_item.

template<class T>
void GListT< T >::__Swap ( GListIterT< T > *  iter)
protectedvirtual

Swap the object referred by current and argument iterators. The iterator flags are also swapped. The internal function does not check that pointers are valid.

Parameters
iteriterator to swap with current

References GIterT< T >::item_ptr, and GIterT< T >::SetFlags().

template<class T >
T * GListT< T >::__Take ( )
protectedvirtual

Internal function to take current object out of the list 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.

Reimplemented in GTreeBranchT< T >.

References GListIterT< T >::next_item, and GListIterT< T >::previous_item.

template<class T>
GListIterT< T > GListT< T >::Add ( T *  obj_ptr)
virtual

The function add the object given by its pointer after current element in the list. The object is adopted by the list and will be deleted when removed from the list.

Parameters
obj_ptrobject pointer

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

Referenced by GIntervalList::Add(), and GListT< T >::GListT().

template<class T>
GListIterT< T > GListT< T >::Add ( T &  obj_ref)
virtual

The function add the object by reference after current element in the list. The object is considered external to the list and is not deleted when removed.

Parameters
obj_refobject given by reference

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

template<class T>
GListIterT< T > GListT< T >::Append ( T *  obj_ptr)
virtual

The function add the object given by its pointer after current element in the list. The object is adopted by the list and will be deleted when removed from the list.

Parameters
obj_ptrobject pointer

Referenced by GTreeNodeT< T >::CreateList(), and GGetFileList().

template<class T>
GListIterT< T > GListT< T >::Append ( T &  obj_ref)
virtual

The function add the object by reference after current element in the list. The object is considered external to the list and is not deleted when removed.

Parameters
obj_refobject given by reference
template<class T >
T & GListT< T >::At ( u_int  n) const

Move current index to element n in the list (starting at 0), and return the object (by reference). On an empty list, this may result in a crash. If the list is empty, or if n is greater than the number of elements in the list, the function may result in a crash...

Parameters
nelement number in the list

References GClassError, GGetString(), and GListIterT< T >::next_item.

template<class T >
GListIterT< T > GListT< T >::Begin ( ) const
inlinevirtual

Return the iterator at beginning of the list (on first element). The function does not change current iterator.

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

template<class T >
GListIterT< T > GListT< T >::Current ( ) const
inline

Return the iterator on current list element, or a Null iterator if the list is empty.

Referenced by GSortListT< T >::__AddSorted().

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

Function that remove all objects from the list.

Implements GCollectionT< T >.

References GDebugClass.

template<class T >
GListIterT< T > GListT< T >::End ( ) const
inlinevirtual

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

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

Check if an object belongs to the list.

Parameters
ptrobject pointer
template<class T>
GListIterT< T > GListT< T >::Find ( const T *  ptr) const
virtual

Check if an object belongs to the list, 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>
GListIterT< T > GListT< T >::FindFirst ( const T *  ptr) const
inlinevirtual

Search for the first element pointing to ptr in the list, and returns the iterator to this element. If the object is found, the current iterator is moved.

Parameters
ptrobject pointer
template<class T>
GListIterT< T > GListT< T >::FindLast ( const T *  ptr) const
inlinevirtual

Search for the last element pointing to ptr in the list, and returns the iterator to this element. If the object is found, the current iterator is moved.

Parameters
ptrobject pointer

References GIterT< T >::item_ptr, and GListIterT< T >::previous_item.

template<class T>
GListIterT< T > GListT< T >::FindNext ( const T *  ptr) const
inlinevirtual

Search for the next element pointing to ptr in the list, and returns the iterator to this element. If the object is found, the current iterator is moved.

Parameters
ptrobject pointer

References GIterT< T >::item_ptr, and GListIterT< T >::next_item.

template<class T>
GListIterT< T > GListT< T >::FindPrevious ( const T *  ptr) const
inlinevirtual

Search for the previous element pointing to ptr in the list, and returns the iterator to this element. If the object is found, the current iterator is moved.

Parameters
ptrobject pointer

References GIterT< T >::item_ptr, and GListIterT< T >::previous_item.

template<class T >
GListIterT< T > GListT< T >::First ( ) const
inline

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

Referenced by GSortListT< T >::__AddSorted(), GIntervalList::FromFirst(), and GIntervalList::ToFirst().

template<class T >
GListIterT< T > GListT< T >::Goto ( u_int  n = 0) const

Move current index to element n in the list (starting at 0) and return the iterator. If the list is empty, or if n is greater than the number of elements in the list, a Null iterator is returned.

Parameters
nelement number in the list

References GListIterT< T >::next_item.

template<class T >
int GListT< T >::Index ( ) const

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

References GListIterT< T >::previous_item.

template<class T>
GListIterT< T > GListT< T >::Insert ( T *  obj_ptr)
virtual

The function inserts the object given by its pointer before current element in the list. The object is adopted by the list and will be deleted when removed from the list.

Parameters
obj_ptrobject pointer

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

Referenced by GIntervalList::Add().

template<class T>
GListIterT< T > GListT< T >::Insert ( T &  obj_ref)
virtual

The function inserts the object by reference before current element in the list. The object is considered external to the list and is not deleted when removed.

Parameters
obj_refobject given by reference

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

template<class T>
template<class Q >
bool GListT< 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 >
GListIterT< T > GListT< T >::Last ( ) const

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

Referenced by GIntervalList::FromLast(), and GIntervalList::ToLast().

template<class T >
int GListT< T >::Move ( int  n)
virtual

Move current element in the list, backward if
n is negative, or forward if n is positive. The function returns the effective move (if end of list is reached, the move is interrupted).

Parameters
nrequested move
template<class T >
bool GListT< T >::MoveBottom ( )
virtual

Move current element at end of the list, if it is allowed.

template<class T >
bool GListT< T >::MoveDown ( )
inlinevirtual

Move current element down, if it is allowed.

template<class T >
bool GListT< T >::MoveTop ( )
virtual

Move current element at top of the list, if it is allowed.

template<class T >
bool GListT< T >::MoveUp ( )
inlinevirtual

Move current element up, if it is allowed.

template<class T >
GListIterT< T > GListT< 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 >
GListIterT< T > GListT< T >::Null ( )
inlinestatic

Returns a Null iterator (with NULL object pointer).

Referenced by GSortListT< T >::__AddSorted(), GListT< T >::GListT(), and GListT< T >::operator=().

template<class T>
GListT< T > & GListT< T >::operator= ( const GListT< T > &  list)

Affectation operator. The initial list is emptied.

Parameters
listlist to copy.

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

template<class T>
GListIterT< T > GListT< T >::Prepend ( T *  obj_ptr)
virtual

The function inserts the object given by its pointer before current element in the list. The object is adopted by the list and will be deleted when removed from the list.

Parameters
obj_ptrobject pointer
template<class T>
GListIterT< T > GListT< T >::Prepend ( T &  obj_ref)
virtual

The function inserts the object by reference before current element in the list. The object is considered external to the list and is not deleted when removed.

Parameters
obj_refobject given by reference
template<class T >
GListIterT< T > GListT< 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 GListT< T >::Remove ( )
virtual

The function removes the current element from the list. If the delete flag from the iterator is set, the object is deleted. The current iterator is moved to the next element.

Reimplemented in GIntervalList, and GItemList.

References GDebugClass, gcollection::gDelete, GGetString(), GIterT< T >::IsFlagOn(), and GIterT< T >::item_ptr.

Referenced by GIntervalList::Add().

template<class T>
bool GListT< T >::Remove ( const T *  ptr,
bool  all = true 
)
virtual

Removes an object given by its pointer ptr, from the list. 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 list
allif true, if the object is several times in the list, all corresponding elements are removed

Reimplemented in GIntervalList.

template<class T >
T * GListT< T >::Take ( )
inlinevirtual

Take current object out of the list. 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 * GListT< T >::Take ( const T *  ptr)
virtual

Take an object given by its pointer ptr object out of the list (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 list

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