clinkedlist.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CLINKEDLIST_H
00020 #define __CLINKEDLIST_H
00021
00022 #include "cownedobject.h"
00023
00024 NAMESPACE_BEGIN
00025
00026 #ifdef _MSC_VER
00027 #pragma warning(push, 0) // deprecation warnings inside the header
00028 #endif
00029
00030 #if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ >= 3
00031
00032
00033
00034
00035 #define CLINKEDLIST_DEPRECATED
00036 #else
00037 #define CLINKEDLIST_DEPRECATED _OPPDEPRECATED
00038 #endif
00039
00054 class SIM_API CLINKEDLIST_DEPRECATED cLinkedList : public cOwnedObject
00055 {
00056
00057 struct Elem
00058 {
00059 void *item;
00060 Elem *prev, *next;
00061 };
00062
00063 public:
00064
00071 class CLINKEDLIST_DEPRECATED Iterator
00072 {
00073 private:
00074 Elem *p;
00075
00076 public:
00082 Iterator(const cLinkedList& q, bool athead=true)
00083 {p = athead ? q.headp : q.tailp;}
00084
00088 void init(const cLinkedList& q, bool athead=true)
00089 {p = athead ? q.headp : q.tailp;}
00090
00094 void *operator()() const {return p->item;}
00095
00100 bool end() const {return (bool)(p==NULL);}
00101
00105 void *operator++(int) {if (!p) return NULL; Elem *t=p; p=p->next; return t->item;}
00106
00110 void *operator--(int) {if (!p) return NULL; Elem *t=p; p=p->prev; return t->item;}
00111 };
00112
00113 friend class Iterator;
00114
00115 private:
00116 Elem *headp, *tailp;
00117 int n;
00118
00119 VoidDelFunc delfunc;
00120 VoidDupFunc dupfunc;
00121 size_t itemsize;
00122
00123
00124
00125
00126 private:
00127 void copy(const cLinkedList& other);
00128
00129 protected:
00130
00131
00132
00133 Elem *find_llelem(void *item) const;
00134
00135
00136 void insbefore_llelem(Elem *p, void *item);
00137
00138
00139 void insafter_llelem(Elem *p, void *item);
00140
00141
00142 void *remove_llelem(Elem *p);
00143
00144 public:
00147
00154 cLinkedList(const cLinkedList& llist);
00155
00159 explicit cLinkedList(const char *name=NULL);
00160
00164 virtual ~cLinkedList();
00165
00173 cLinkedList& operator=(const cLinkedList& queue);
00175
00178
00184 virtual cLinkedList *dup() const {return new cLinkedList(*this);}
00185
00190 virtual std::string info() const;
00191
00197 virtual void parsimPack(cCommBuffer *buffer);
00198
00204 virtual void parsimUnpack(cCommBuffer *buffer);
00206
00209
00228 void config( VoidDelFunc _delfunc, VoidDupFunc _dupfunc, size_t _itemsize=0);
00229
00233 void insert(void *item);
00234
00239 void insertBefore(void *where, void *item);
00240
00245 void insertAfter(void *where, void *item);
00246
00251 void *head() const {return n!=0 ? headp->item : NULL;}
00252
00257 void *tail() const {return n!=0 ? tailp->item : NULL;}
00258
00263 void *remove(void *item);
00264
00269 void *pop();
00270
00274 int getLength() const {return n;}
00275
00279 bool isEmpty() const {return n==0;}
00280
00284 int length() const {return getLength();}
00285
00289 bool empty() const {return isEmpty();}
00290
00294 bool contains(void *item) const {return find_llelem(item)!=NULL;}
00295
00300 void clear();
00302 };
00303
00304 #ifdef _MSC_VER
00305 #pragma warning(pop)
00306 #endif
00307
00308
00309 NAMESPACE_END
00310
00311
00312 #endif
00313