GCpp general purpose C++ library
version 1.0
|
#include <GListT.hh>
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 () |
![]() | |
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 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. | |
![]() | |
u_int | options |
Collection option flags. | |
u_int | count_item |
Number of objects in the collection. | |
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.
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:
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.
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).
Default constructor.
opts | option flags |
References GListT< T >::current_item, GListT< T >::first_item, GDebugConst, and GListT< T >::last_item.
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.
list | list 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().
Copy constructor with different options.
list | list to copy |
opts | option flags |
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().
Destructor: the list is emptied.
References GDebugDest.
|
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.
item | pointer 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().
|
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).
ptr | object pointer |
except | pointer on an iterator that is excluded from the search |
References GIterT< T >::item_ptr, and GListIterT< T >::next_item.
|
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 |
Referenced by GIntervalList::Add().
|
protectedvirtual |
Internal function identical to __Add function, except that the object is inserted before current element.
item | pointer 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 >::__AddSorted(), and GSortListT< T >::__Insert().
|
protectedvirtual |
Internal function to move current element down, without check.
References GListIterT< T >::next_item.
|
protectedvirtual |
Internal function to move current element up, without check.
References GListIterT< T >::previous_item.
|
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.
iter | iterator to swap with current |
References GIterT< T >::item_ptr, and GIterT< T >::SetFlags().
|
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.
|
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.
obj_ptr | object pointer |
References GClassWarning, GDebugClass, gcollection::gDelete, and GGetString().
Referenced by GIntervalList::Add(), and GListT< T >::GListT().
|
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.
obj_ref | object given by reference |
References GClassWarning, GDebugClass, gcollection::gDeepCopy, gcollection::gDelete, and GGetString().
|
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.
obj_ptr | object pointer |
Referenced by GTreeNodeT< T >::CreateList(), and GGetFileList().
|
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.
obj_ref | object given by reference |
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...
n | element number in the list |
References GClassError, GGetString(), and GListIterT< T >::next_item.
|
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=().
|
inline |
Return the iterator on current list element, or a Null iterator if the list is empty.
Referenced by GSortListT< T >::__AddSorted().
|
virtual |
Function that remove all objects from the list.
Implements GCollectionT< T >.
References GDebugClass.
|
inlinevirtual |
Return the iterator at end of the list (on last element). The function does not change current iterator.
|
inlinevirtual |
Check if an object belongs to the list.
ptr | object pointer |
|
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.
ptr | object pointer |
|
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.
ptr | object pointer |
|
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.
ptr | object pointer |
References GIterT< T >::item_ptr, and GListIterT< T >::previous_item.
|
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.
ptr | object pointer |
References GIterT< T >::item_ptr, and GListIterT< T >::next_item.
|
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.
ptr | object pointer |
References GIterT< T >::item_ptr, and GListIterT< T >::previous_item.
|
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().
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.
n | element number in the list |
References GListIterT< T >::next_item.
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.
|
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.
obj_ptr | object pointer |
References GClassWarning, GDebugClass, gcollection::gDelete, and GGetString().
Referenced by GIntervalList::Add().
|
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.
obj_ref | object given by reference |
References GClassWarning, GDebugClass, gcollection::gDeepCopy, gcollection::gDelete, and GGetString().
Macro from GCpp library that defines the following functions:
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().
|
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).
n | requested move |
|
virtual |
Move current element at end of the list, if it is allowed.
|
inlinevirtual |
Move current element down, if it is allowed.
|
virtual |
Move current element at top of the list, if it is allowed.
|
inlinevirtual |
Move current element up, if it is allowed.
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.
|
inlinestatic |
Returns a Null iterator (with NULL object pointer).
Referenced by GSortListT< T >::__AddSorted(), GListT< T >::GListT(), and GListT< T >::operator=().
Affectation operator. The initial list is emptied.
list | list to copy. |
References GListT< T >::Begin(), GDebugClass, gcollection::gDelete, GCollectionT< T >::GetOptions(), GIterT< T >::IsFlagOn(), and GListT< T >::Null().
|
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.
obj_ptr | object pointer |
|
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.
obj_ref | object given by reference |
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.
|
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().
|
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.
ptr | pointer to the object to remove from the list |
all | if true, if the object is several times in the list, all corresponding elements are removed |
Reimplemented in GIntervalList.
|
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.
|
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.
ptr | pointer to the object to take out of the list |