00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CMSGHEAP_H
00020 #define __CMSGHEAP_H
00021
00022 #include "cobject.h"
00023
00024 class cMessage;
00025
00026
00034 class SIM_API cMessageHeap : public cObject
00035 {
00036 public:
00042 class Iterator
00043 {
00044 private:
00045 cMessageHeap *q;
00046 int pos;
00047
00048 public:
00052 Iterator(const cMessageHeap& mh) {q=const_cast<cMessageHeap*>(&mh);pos=1;}
00053
00057 void init(const cMessageHeap& mh) {q=const_cast<cMessageHeap*>(&mh);pos=1;}
00058
00062 cMessage *operator()() {return q->h[pos];}
00063
00068 cMessage *operator++(int) {return pos<=q->n ? q->h[++pos] : NULL;}
00069
00073 bool end() const {return (bool)(pos>q->n);}
00074 };
00075
00076 friend class Iterator;
00077
00078 private:
00079 cMessage **h;
00080 int n;
00081 int size;
00082 unsigned long insertcntr;
00083
00084
00085 void shiftup(int from=1);
00086
00087 public:
00090
00094 cMessageHeap(const cMessageHeap& msgq);
00095
00099 cMessageHeap(const char *name=NULL, int size=128);
00100
00104 virtual ~cMessageHeap();
00105
00110 cMessageHeap& operator=(const cMessageHeap& msgqueue);
00112
00115
00120 virtual cPolymorphic *dup() const {return new cMessageHeap(*this);}
00121
00126 virtual std::string info() const;
00127
00132 virtual void forEachChild(cVisitor *v);
00133
00134
00136
00139
00143 void insert(cMessage *event);
00144
00149 cMessage *peekFirst() const;
00150
00155 cMessage *getFirst();
00156
00161 cMessage *get(cMessage *event);
00162
00169 cMessage *peek(int m);
00170
00175 void sort();
00176
00180 void clear();
00181
00185 int length() const {return n;}
00186
00190 bool empty() const {return n==0;}
00192 };
00193
00194 #endif
00195