00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CLLIST_H
00021 #define __CLLIST_H
00022
00023 #include "cobject.h"
00024
00025
00037 class SIM_API cLinkedList : public cObject
00038 {
00039
00040 struct Elem
00041 {
00042 void *item;
00043 Elem *prev, *next;
00044 };
00045
00046 public:
00053 class Iterator
00054 {
00055 private:
00056 Elem *p;
00057
00058 public:
00064 Iterator(const cLinkedList& q, bool athead=true)
00065 {p=&q ? (athead ? q.headp : q.tailp) : NULL;}
00066
00070 void init(const cLinkedList& q, bool athead=true)
00071 {p=&q ? (athead ? q.headp : q.tailp) : NULL;}
00072
00076 void *operator()() const {return p->item;}
00077
00082 bool end() const {return (bool)(p==NULL);}
00083
00087 void *operator++(int) {if (!p) return NULL; Elem *t=p; p=p->next; return t->item;}
00088
00092 void *operator--(int) {if (!p) return NULL; Elem *t=p; p=p->prev; return t->item;}
00093 };
00094
00095 friend class Iterator;
00096
00097 private:
00098 Elem *headp, *tailp;
00099 int n;
00100
00101 VoidDelFunc delfunc;
00102 VoidDupFunc dupfunc;
00103 size_t itemsize;
00104
00105
00106
00107 protected:
00108
00109
00110
00111 Elem *find_llelem(void *item) const;
00112
00113
00114 void insbefore_llelem(Elem *p, void *item);
00115
00116
00117 void insafter_llelem(Elem *p, void *item);
00118
00119
00120 void *remove_llelem(Elem *p);
00121
00122 public:
00125
00132 cLinkedList(const cLinkedList& llist);
00133
00137 explicit cLinkedList(const char *name=NULL);
00138
00142 virtual ~cLinkedList();
00143
00151 cLinkedList& operator=(const cLinkedList& queue);
00153
00156
00162 virtual cObject *dup() const {return new cLinkedList(*this);}
00163
00168 virtual void info(char *buf);
00169
00175 virtual int netPack();
00176
00182 virtual int netUnpack();
00184
00187
00206 void config( VoidDelFunc _delfunc, VoidDupFunc _dupfunc, size_t _itemsize=0);
00207
00211 void insert(void *item);
00212
00217 void insertBefore(void *where, void *item);
00218
00223 void insertAfter(void *where, void *item);
00224
00229 void *head() const {return n!=0 ? headp->item : NULL;}
00230
00235 void *tail() const {return n!=0 ? tailp->item : NULL;}
00236
00241 void *remove(void *item);
00242
00247 void *pop();
00248
00252 int length() const {return n;}
00253
00257 bool empty() const {return n==0;}
00258
00262 bool contains(void *item) const {return find_llelem(item)!=NULL;}
00263
00268 void clear();
00270 };
00271
00272
00273 #endif
00274