GCpp general purpose C++ library  version 1.0
GSortListT.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file GSortListT.hh
3  *
4  * Include file for GSortListT template class.
5  */
6 //======================================================================
7 
8 #ifndef G_SORT_LIST_T_HH
9 #define G_SORT_LIST_T_HH
10 
11 #include "GListT.hh"
12 
13 //======================================================================
14 /*! \class GSortListT
15  *
16  * Template class to define a sortable list of objects.
17  *
18  * If the gcollection::gAlwaysSorted flags are set, then elements are inserted
19  * at their sorted position, and cannot be moved.
20  * Else they are inserted at current position, like in the base class,
21  * and the list is sorted only if the Sort() function is called.
22  *
23  * The objects class must define the \b Compare() function, on which the
24  * sorting is based (returning -1, 0 or 1).
25  *
26  * See \ref gcpp_templates for more information about the template classes.
27  */
28 template <class T> class GSortListT : public GListT<T>
29 {
30  //------------------------------------------------------------
31  /*! \object_doc */
33  //------------------------------------------------------------
34 
35  using GCollectionT<T>::options;
36  using GListT<T>::current_item;
37  using GListT<T>::first_item;
38  using GListT<T>::last_item;
39  using GListT<T>::Null;
40  using GListT<T>::Begin;
41  using GListT<T>::End;
42 
43  public:
44  //------------------------------------------------------------
45  // Constructor / Destructor / Affectation
46  GSortListT ( u_int fl = 0 );
47  GSortListT ( const GSortListT<T> & list );
48  GSortListT ( const GListT<T> & list );
49  GSortListT ( const GListT<T> & list, u_int fl );
50  GSortListT<T> & operator = ( const GListT<T> & list );
51  virtual ~GSortListT ( );
52 
53  //------------------------------------------------------------
54  virtual void ReverseSort ( );
55  virtual int Compare ( const T & obj1, const T & obj2 ) const;
56 
57  virtual void Sort ( );
58  virtual bool IsSorted ( ) const;
59 
60  //------------------------------------------------------------
61  // internal functions
62  protected:
63  virtual GListIterT<T> __Add ( T * item ); // redefined from GListT
64  virtual GListIterT<T> __Insert ( T * item ); // redefined from GListT
65  virtual GListIterT<T> __AddSorted ( T * item );
66 };
67 
68 //----------------------------------------------------------------------
69 // Inline and template functions
70 #include "icc/GSortListT.icc"
71 
72 
73 //======================================================================
74 #endif
virtual void ReverseSort()
Definition: GSortListT.icc:70
GListIterT< T > ** last_item
Iterator on last object in the list.
Definition: GListT.hh:75
virtual GListIterT< T > End() const
Definition: GListT.icc:112
Definition: GListIterT.hh:21
Definition: GListIterT.hh:13
Definition: GSortListT.hh:28
virtual GListIterT< T > Begin() const
Definition: GListT.icc:104
virtual GListIterT< T > __AddSorted(T *item)
Definition: GSortListT.icc:219
virtual int Compare(const T &obj1, const T &obj2) const
Definition: GSortListT.icc:86
Definition: GCollectionT.hh:115
u_int options
Collection option flags.
Definition: GCollectionT.hh:123
virtual GListIterT< T > __Insert(T *item)
Definition: GSortListT.icc:199
#define GObject(T)
Definition: GClassDefine.hh:65
GListIterT< T > ** current_item
Iterator on current object in the list.
Definition: GListT.hh:76
GListIterT< T > ** first_item
Iterator on first object in the list.
Definition: GListT.hh:74
static GListIterT< T > Null()
Definition: GListT.icc:119
virtual bool IsSorted() const
Definition: GSortListT.icc:147
unsigned int u_int
Definition: GTypes.hh:38
virtual void Sort()
Definition: GSortListT.icc:91
virtual GListIterT< T > __Add(T *item)
Definition: GSortListT.icc:179