00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CLLIST_H
00023 #define __CLLIST_H
00024
00025 #include "cobject.h"
00026
00027
00028 class cLinkedList;
00029 class cLinkedListIterator;
00030
00031
00032
00033
00034
00035
00036 struct sLLElem
00037 {
00038 void *item;
00039 sLLElem *prev, *next;
00040 };
00041
00042
00043
00054 class SIM_API cLinkedList : public cObject
00055 {
00056 friend class cLinkedListIterator;
00057
00058 private:
00059 sLLElem *headp, *tailp;
00060 int n;
00061
00062 VoidDelFunc delfunc;
00063 VoidDupFunc dupfunc;
00064 size_t itemsize;
00065
00066
00067
00068 protected:
00069
00070
00071
00072 sLLElem *find_llelem(void *item) const;
00073
00074
00075 void insbefore_llelem(sLLElem *p, void *item);
00076
00077
00078 void insafter_llelem(sLLElem *p, void *item);
00079
00080
00081 void *remove_llelem(sLLElem *p);
00082
00083 public:
00086
00093 cLinkedList(const cLinkedList& llist);
00094
00098 explicit cLinkedList(const char *name=NULL);
00099
00103 virtual ~cLinkedList();
00104
00112 cLinkedList& operator=(const cLinkedList& queue);
00114
00117
00121 virtual const char *className() const {return "cLinkedList";}
00122
00128 virtual cObject *dup() const {return new cLinkedList(*this);}
00129
00134 virtual void info(char *buf);
00135
00140 virtual const char *inspectorFactoryName() const {return "cLinkedListIFC";}
00141
00147 virtual int netPack();
00148
00154 virtual int netUnpack();
00156
00159
00178 void config( VoidDelFunc _delfunc, VoidDupFunc _dupfunc, size_t _itemsize=0);
00179
00183 void insert(void *item);
00184
00189 void insertBefore(void *where, void *item);
00190
00195 void insertAfter(void *where, void *item);
00196
00201 void *head() const {return n!=0 ? headp->item : NULL;}
00202
00207 void *tail() const {return n!=0 ? tailp->item : NULL;}
00208
00213 void *remove(void *item);
00214
00219 void *pop();
00220
00224 int length() const {return n;}
00225
00229 bool empty() const {return n==0;}
00230
00234 bool contains(void *item) const {return find_llelem(item)!=NULL;}
00235
00240 void clear();
00242 };
00243
00244
00245
00256 class SIM_API cLinkedListIterator
00257 {
00258 private:
00259 sLLElem *p;
00260
00261 public:
00267 cLinkedListIterator(const cLinkedList& q, int athead=1)
00268 {p=&q ? (athead ? q.headp : q.tailp) : NO(sLLElem);}
00269
00273 void init(const cLinkedList& q, int athead=1)
00274 {p=&q ? (athead ? q.headp : q.tailp) : NO(sLLElem);}
00275
00279 void *operator()() const {return p->item;}
00280
00285 bool end() const {return (bool)(p==NULL);}
00286
00290 void *operator++(int) {sLLElem *t=p; if(p) p=p->next; return t->item;}
00291
00295 void *operator--(int) {sLLElem *t=p; if(p) p=p->prev; return t->item;}
00296 };
00297
00298 #endif
00299