00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __CLIST_H
00039 #define __CLIST_H
00040
00041
00042
00044 #if _MSC_VER >= 1300
00045 #include <iostream>
00046 #else
00047 #include <iostream.h>
00048 #endif
00049
00050
00051
00052 template <class ObjectType>
00053 class CList;
00054
00055
00057 template <class ObjectType>
00058 class CListContainer
00059
00060 {
00061 public:
00062
00063
00064 CListContainer(ObjectType* pTmp)
00065 : m_pNext(NULL), m_pPrev(NULL), m_pObject(pTmp) {};
00066
00067
00068 ~CListContainer() {};
00069
00070
00071 CListContainer* getNext() { return m_pNext; };
00072 CListContainer* getPrev() { return m_pPrev; };
00073
00074 ObjectType* getObject() { return m_pObject; };
00075
00076 friend class CList<ObjectType>;
00077
00078 protected:
00079
00080 CListContainer* m_pNext;
00081 CListContainer* m_pPrev;
00082
00083 ObjectType* const m_pObject;
00084
00085
00086 void setNext(CListContainer* pTmp) { m_pNext = pTmp; };
00087 void setPrev(CListContainer* pTmp) { m_pPrev = pTmp; };
00088 };
00089
00090
00092
00103 template <class ObjectType>
00104 class CList
00105
00106 {
00107 public:
00108
00110 CList();
00111
00113 CList(const CList &cSource);
00114
00116 ~CList();
00117
00118
00121 CListContainer<ObjectType>* getFirst() const { return m_pFirst; };
00122
00125 CListContainer<ObjectType>* getLast() const { return m_pLast; };
00126
00128 int getNumObjects() const { return m_nNumObjects; };
00129
00131 int insertAsFirst(ObjectType *pObj);
00132
00134 int insertAsLast(ObjectType *pObj);
00135
00138 int insertAfter(CListContainer<ObjectType> *pThere, ObjectType *pObject);
00139
00143 CListContainer<ObjectType>* find(ObjectType *pObj) const;
00144
00146 int remove(CListContainer<ObjectType> *pRemove);
00147
00150 int remove(ObjectType *pObj);
00151
00155 CList<ObjectType>* getFullDuplicate() const;
00156
00159 void clear(int nFlag=0);
00160
00161
00162
00163 ObjectType &operator [](int nIndex) const;
00164
00165
00166
00167 CListContainer<ObjectType> *operator()(int nIndex) const;
00168
00170 const CList &operator+(const CList &cSource);
00171
00174 CList &operator=(const CList &cSource);
00175
00176
00177
00178 protected:
00179
00180 int m_nNumObjects;
00181
00182 CListContainer<ObjectType>* m_pFirst;
00183 CListContainer<ObjectType>* m_pLast;
00184
00185
00186
00187 void init() {
00188 setFirst(NULL);
00189 setLast(NULL);
00190 setNumObjects(0);
00191 };
00192 void setFirst(CListContainer<ObjectType>* pTmp)
00193 { m_pFirst = pTmp; };
00194 void setLast(CListContainer<ObjectType>* pTmp)
00195 { m_pLast = pTmp; };
00196 void setNumObjects(int nTmp)
00197 { m_nNumObjects = nTmp; };
00198
00199 void increaseNumObjects()
00200 {
00201 setNumObjects(getNumObjects() + 1);
00202 return;
00203 }
00204 void decreaseNumObjects()
00205 {
00206 setNumObjects(getNumObjects() - 1);
00207 return;
00208 }
00209 };
00210
00211
00212 #if defined(__GNUC__)
00213 #include "CList.cpp"
00214 #endif
00215
00216 #endif