GCpp general purpose C++ library  version 1.0
GCollectionT.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file GCollectionT.hh
3  *
4  * Include file for GCollection base template class.
5  */
6 //======================================================================
7 
8 #ifndef G_COLLECTION_T_HH
9 #define G_COLLECTION_T_HH
10 
11 #include "GGlobal.hh"
12 #include "GLogMessage.hh"
13 
14 /*! Define values for collections behaviour flags.
15  */
16 namespace gcollection
17 {
18 
19  //------------------------------------------------------------
20  /** @name Iterator flags */
21  //@{
22 
23  /*! Iterator flag inicating that the object must be deleted when removed
24  * from the collection.
25  */
26  static const u_int gDelete = 0x00000001;
27 
28  //@}
29 
30  //------------------------------------------------------------
31  /** @name General collections options */
32  //@{
33 
34  /*! Indicates that if an object is added to the collection by reference,
35  * a copy of the object is made (with Clone() function), and the new
36  * object is adopted by the list.
37  */
38  static const u_int gDeepCopy = 0x00001000;
39 
40  /*! An object must not be refered several times in the same collection
41  * (default check is based on pointer comparison, but for named objects
42  * it may be based on objects names).*/
43  static const u_int gUniqueItem = 0x00002000;
44 
45  /*! The position of elements cannot be moved once inserted.*/
46  static const u_int gFixed = 0x00020000;
47 
48  /*! The collection can be sorted: the comparison function (Compare) must be
49  * defined.*/
50  static const u_int gIsSortable = 0x00010000;
51 
52  /*! The objects are entered sorted and the collection remains sorted
53  * (objects cannot be moved).*/
54  static const u_int gAlwaysSorted = 0x00030000;
55 
56  /*! The sorting is done in reverse order.*/
57  static const u_int gReverseSort = 0x00050000;
58 
59  //@}
60 
61  //------------------------------------------------------------
62  /** @name Vectors collections options */
63  //@{
64 
65  /*! For vector collections, indicates that when an object is removed
66  * the other elements are moved to avoid creating holes (NULL pointers
67  * to objects).
68  */
69  static const u_int gShiftRemove = 0x00100000;
70 
71  /*! For vector collections, indicates that when vector capacity is
72  * exceeded, the vector is automatically resized.
73  * It is resized only for what is required, except if gcollection::gDoubleSize
74  * bit is set.
75  */
76  static const u_int gAutoResize = 0x00200000;
77 
78  /*! For vector collections, indicates that when vector capacity is
79  * automatically increased, it is doubled.
80  */
81  static const u_int gDoubleSize = 0x00400000;
82 
83  //@}
84 
85  //------------------------------------------------------------
86  /** @name Named objects collections options */
87  //@{
88 
89  /*! For named objects collections, only one object with a given name
90  * can be in the collection.*/
91  static const u_int gUniqueName = 0x01000000;
92 
93  /*! For named objects collections, the names comparison is not case
94  * sensitive.*/
95  static const u_int gNoCaseSensitive = 0x02000000;
96 
97  /*! For named objects collections, the sorting is based on dictionary
98  * sorting, not on ascii codes.*/
99  static const u_int gDictSort = 0x04000000;
100 
101  //@}
102 }
103 
104 //======================================================================
105 /*! \class GCollectionT
106  *
107  * This is a base class for collections of objects that are instances
108  * of the class \b T.
109  * The class is abstract.
110  *
111  * See \ref gcpp_templates for more information about the template classes.
112  *
113  */
114 
115 template <class T> class GCollectionT
116 {
117  //----------------------------------------------------------------------
118  /*! \object_doc */
120  //----------------------------------------------------------------------
121 
122  protected:
123  u_int options; ///< Collection option flags
124  u_int count_item; ///< Number of objects in the collection
125 
126  //------------------------------------------------------------
127  // Constructor / Destructor / Affectation
128  public:
129  GCollectionT ( u_int flg = 0 );
130  virtual ~GCollectionT ( );
131 
132  //------------------------------------------------------------
133  virtual u_int GetSize ( ) const;
134  virtual u_int GetCount ( ) const;
135  virtual u_int GetOptions ( ) const;
136 
137  // option bits check
138  bool CheckOptions ( u_int opts ) const;
139 
140  // for sortable collections
141  bool FixPositionOption ( ) const;
142  bool IsSortable ( ) const;
143  bool IsAlwaysSorted ( ) const;
144  bool IsReverseSorted ( ) const;
145 
146  // for named objects collections
147  bool UniqueNameOption ( ) const;
148  bool IsCaseSensitive ( ) const;
149  bool DictSortOption ( ) const;
150 
151  /*! Pure virtual function to empty the collection.*/
152  virtual void Empty ( ) = 0;
153 };
154 
155 //----------------------------------------------------------------------
156 // Inline functions
157 #include "icc/GCollectionT.icc"
158 
159 //======================================================================
160 #endif
bool CheckOptions(u_int opts) const
Definition: GCollectionT.icc:40
u_int count_item
Number of objects in the collection.
Definition: GCollectionT.hh:124
static const u_int gNoCaseSensitive
Definition: GCollectionT.hh:95
virtual u_int GetSize() const
Definition: GCollectionT.icc:28
static const u_int gDeepCopy
Definition: GCollectionT.hh:38
static const u_int gDoubleSize
Definition: GCollectionT.hh:81
static const u_int gIsSortable
Definition: GCollectionT.hh:50
bool DictSortOption() const
Definition: GCollectionT.icc:72
bool IsSortable() const
Definition: GCollectionT.icc:50
static const u_int gReverseSort
Definition: GCollectionT.hh:57
static const u_int gUniqueItem
Definition: GCollectionT.hh:43
Definition: GCollectionT.hh:115
u_int options
Collection option flags.
Definition: GCollectionT.hh:123
bool UniqueNameOption() const
Definition: GCollectionT.icc:63
bool IsAlwaysSorted() const
Definition: GCollectionT.icc:54
#define GObjectV(T)
Definition: GClassDefine.hh:77
static const u_int gFixed
Definition: GCollectionT.hh:46
virtual void Empty()=0
static const u_int gAlwaysSorted
Definition: GCollectionT.hh:54
static const u_int gDictSort
Definition: GCollectionT.hh:99
static const u_int gUniqueName
Definition: GCollectionT.hh:91
static const u_int gDelete
Definition: GCollectionT.hh:26
bool IsReverseSorted() const
Definition: GCollectionT.icc:58
virtual u_int GetCount() const
Definition: GCollectionT.icc:32
bool FixPositionOption() const
Definition: GCollectionT.icc:46
virtual u_int GetOptions() const
Definition: GCollectionT.icc:36
static const u_int gAutoResize
Definition: GCollectionT.hh:76
unsigned int u_int
Definition: GTypes.hh:38
bool IsCaseSensitive() const
Definition: GCollectionT.icc:67
static const u_int gShiftRemove
Definition: GCollectionT.hh:69