GCpp general purpose C++ library  version 1.0
GListT.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file GListT.hh
3  *
4  * Include file for GListT template class.
5  */
6 //======================================================================
7 
8 #ifndef G_LIST_T_HH
9 #define G_LIST_T_HH
10 
11 #include "GCollectionT.hh"
12 #include "GListIterT.hh"
13 
14 //======================================================================
15 /*! \class GListT
16  *
17  * Template class to define list of objects.
18  *
19  * For the list, \ref first_item and \ref last_item allow to keep a constant
20  * algorithm speed when navigating through the list.
21  *
22  * The \b current_item is an index indicating current position in the list.
23  * This is the reference position to add, insert, remove elements...
24  *
25  * The \ref first_item, \ref last_item and \b current_item are defined as
26  * pointers to iterators, so that their content can be changed even in
27  * constant list object (to allow to navigate in the list, which requires
28  * to change the index)
29  *
30  * See \ref gcpp_templates for more information about the behaviour of
31  * collection template classes.
32  *
33  *
34  * \par Adding and removing objects
35  *
36  * The functions Add, Insert, Append and Prepend insert objects (either by
37  * pointer or by reference, respectively after current position, before
38  * current position, at the end of the list, at the beginning of the list.
39  *
40  * Default behaviour (if no other option is selected, see gcollection
41  * namespace) is the following:
42  * - if an object is added by pointer, it is adopted by the list, and
43  * deleted when removed from the list.
44  * - if an object is added by reference, it is not deleted when removed,
45  * and the calling program may ensure that the object lives as long as it
46  * used in the list.
47  *
48  * The functions Remove does what the function name obviously mean.
49  * If the object was adopted by the list, it is deleted.
50  *
51  * The Take functions take an object out of the list, but do not delete
52  * it if it was adopted.
53  *
54  *
55  * \par Internal functions
56  *
57  * The internal functions are defined to adapt the behaviour of the
58  * list to the options.
59  * This behaviour may also be sophisticated in derived classes
60  * (see GSortListT and GNamedListT).
61  *
62  *
63  * \image html GListT.png
64  *
65  */
66 template <class T> class GListT : public GCollectionT<T>
67 {
68  //------------------------------------------------------------
69  /*! \object_doc */
71  //------------------------------------------------------------
72 
73  protected:
74  GListIterT<T> ** first_item; ///< Iterator on first object in the list
75  GListIterT<T> ** last_item; ///< Iterator on last object in the list
76  GListIterT<T> ** current_item; ///< Iterator on current object in the list
77 
78  public:
79  //------------------------------------------------------------
80  // Constructor / Destructor / Affectation
81  GListT ( u_int opts = 0 );
82  GListT ( const GListT<T> & list );
83  GListT ( const GListT<T> & list, u_int opts );
84 
85  GListT<T> & operator = ( const GListT<T> & list );
86 
87  virtual ~GListT ( );
88 
89  //------------------------------------------------------------
90  public:
91  virtual GListIterT<T> Begin ( ) const;
92  virtual GListIterT<T> End ( ) const;
93  static GListIterT<T> Null ( );
94 
95  virtual bool Exist ( const T * ptr ) const;
96  virtual GListIterT<T> Find ( const T * ptr ) const;
97  virtual GListIterT<T> FindNext ( const T * ptr ) const;
98  virtual GListIterT<T> FindPrevious ( const T * ptr ) const;
99  virtual GListIterT<T> FindFirst ( const T * ptr ) const;
100  virtual GListIterT<T> FindLast ( const T * ptr ) const;
101 
102  GListIterT<T> Current ( ) const;
103  GListIterT<T> Previous ( ) const;
104  GListIterT<T> Next ( ) const;
105  GListIterT<T> First ( ) const;
106  GListIterT<T> Last ( ) const;
107 
108  GListIterT<T> Goto ( u_int n = 0 ) const;
109  T & At ( u_int n ) const;
110  int Index ( ) const;
111 
112  //------------------------------------------------------------
113  virtual int Move ( int n );
114  virtual bool MoveUp ( );
115  virtual bool MoveDown ( );
116  virtual bool MoveTop ( );
117  virtual bool MoveBottom ( );
118 
119  //------------------------------------------------------------
120  virtual GListIterT<T> Add ( T * obj_ptr );
121  virtual GListIterT<T> Insert ( T * obj_ptr );
122  virtual GListIterT<T> Append ( T * obj_ptr );
123  virtual GListIterT<T> Prepend ( T * obj_ptr );
124 
125  virtual GListIterT<T> Add ( T & obj_ptr );
126  virtual GListIterT<T> Insert ( T & obj_ptr );
127  virtual GListIterT<T> Append ( T & obj_ptr );
128  virtual GListIterT<T> Prepend ( T & obj_ptr );
129 
130  virtual T * Take ( );
131  virtual T * Take ( const T * ptr );
132  virtual bool Remove ( );
133  virtual bool Remove ( const T * ptr, bool all = true );
134  virtual void Empty ( );
135 
136  //------------------------------------------------------------
137  // internal functions
138  protected:
139  virtual GListIterT<T> * __Exist ( const T * ptr, GListIterT<T> * except = NULL ) const;
140  virtual GListIterT<T> * __Find ( const T * ptr, GListIterT<T> * except = NULL ) const;
141  virtual GListIterT<T> __Add ( T * item );
142  virtual GListIterT<T> __Insert ( T * item );
143  virtual T * __Take ( );
144  virtual void __Swap ( GListIterT<T> * iter );
145  virtual bool __MoveUp ( );
146  virtual bool __MoveDown ( );
147 
148  //------------------------------------------------------------
149 
150 };
151 
152 //----------------------------------------------------------------------
153 // Inline functions
154 #include "icc/GListT.icc"
155 
156 //======================================================================
157 #endif
virtual T * Take()
Definition: GListT.icc:584
virtual bool MoveDown()
Definition: GListT.icc:368
GListIterT< T > ** last_item
Iterator on last object in the list.
Definition: GListT.hh:75
virtual GListIterT< T > End() const
Definition: GListT.icc:112
virtual GListIterT< T > Append(T *obj_ptr)
Definition: GListT.icc:562
Definition: GListIterT.hh:21
GListIterT< T > Current() const
Definition: GListT.icc:208
Definition: GListIterT.hh:13
virtual GListIterT< T > Add(T *obj_ptr)
Definition: GListT.icc:412
virtual GListIterT< T > FindPrevious(const T *ptr) const
Definition: GListT.icc:162
virtual GListIterT< T > Prepend(T *obj_ptr)
Definition: GListT.icc:542
virtual bool __MoveDown()
Definition: GListT.icc:881
virtual GListIterT< T > Insert(T *obj_ptr)
Definition: GListT.icc:477
virtual GListIterT< T > Begin() const
Definition: GListT.icc:104
virtual GListIterT< T > * __Find(const T *ptr, GListIterT< T > *except=NULL) const
Definition: GListT.icc:689
virtual GListIterT< T > * __Exist(const T *ptr, GListIterT< T > *except=NULL) const
Definition: GListT.icc:669
Definition: GCollectionT.hh:115
#define GObject(T)
Definition: GClassDefine.hh:65
virtual bool MoveTop()
Definition: GListT.icc:377
virtual int Move(int n)
Definition: GListT.icc:325
GListIterT< T > ** current_item
Iterator on current object in the list.
Definition: GListT.hh:76
virtual bool MoveUp()
Definition: GListT.icc:359
virtual GListIterT< T > Find(const T *ptr) const
Definition: GListT.icc:134
virtual bool Exist(const T *ptr) const
Definition: GListT.icc:126
virtual void __Swap(GListIterT< T > *iter)
Definition: GListT.icc:851
virtual bool __MoveUp()
Definition: GListT.icc:865
virtual GListIterT< T > FindFirst(const T *ptr) const
Definition: GListT.icc:181
GListIterT< T > First() const
Definition: GListT.icc:248
GListIterT< T > Goto(u_int n=0) const
Definition: GListT.icc:270
virtual GListIterT< T > FindNext(const T *ptr) const
Definition: GListT.icc:143
GListIterT< T > Previous() const
Definition: GListT.icc:217
virtual void Empty()
Definition: GListT.icc:653
virtual bool MoveBottom()
Definition: GListT.icc:390
GListIterT< T > ** first_item
Iterator on first object in the list.
Definition: GListT.hh:74
static GListIterT< T > Null()
Definition: GListT.icc:119
virtual GListIterT< T > FindLast(const T *ptr) const
Definition: GListT.icc:189
GListIterT< T > Last() const
Definition: GListT.icc:256
T & At(u_int n) const
Definition: GListT.icc:289
unsigned int u_int
Definition: GTypes.hh:38
int Index() const
Definition: GListT.icc:306
virtual GListIterT< T > __Add(T *item)
Definition: GListT.icc:705
virtual T * __Take()
Definition: GListT.icc:812
GListIterT< T > Next() const
Definition: GListT.icc:233
virtual bool Remove()
Definition: GListT.icc:605
virtual GListIterT< T > __Insert(T *item)
Definition: GListT.icc:758