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
00027
00035 class SIM_API cMessageHeap : public cObject
00036 {
00037 public:
00043 class Iterator
00044 {
00045 private:
00046 cMessageHeap *q;
00047 int pos;
00048
00049 public:
00053 Iterator(const cMessageHeap& mh) {q=const_cast<cMessageHeap*>(&mh);pos=1;}
00054
00058 void init(const cMessageHeap& mh) {q=const_cast<cMessageHeap*>(&mh);pos=1;}
00059
00063 cMessage *operator()() {return q->h[pos];}
00064
00069 cMessage *operator++(int) {return pos<=q->n ? q->h[++pos] : NULL;}
00070
00074 bool end() const {return (bool)(pos>q->n);}
00075 };
00076
00077 friend class Iterator;
00078
00079 private:
00080 cMessage **h;
00081 int n;
00082 int size;
00083 unsigned long insertcntr;
00084
00085
00086 void shiftup(int from=1);
00087
00088 public:
00091
00095 cMessageHeap(const cMessageHeap& msgq);
00096
00100 cMessageHeap(const char *name=NULL, int size=128);
00101
00105 virtual ~cMessageHeap();
00106
00111 cMessageHeap& operator=(const cMessageHeap& msgqueue);
00113
00116
00121 virtual cObject *dup() const {return new cMessageHeap(*this);}
00122
00127 virtual std::string info() const;
00128
00133 virtual void forEachChild(cVisitor *v);
00134
00135
00137
00140
00144 void insert(cMessage *event);
00145
00150 cMessage *peekFirst() const;
00151
00156 cMessage *getFirst();
00157
00162 cMessage *get(cMessage *event);
00163
00168 void sort();
00169
00173 void clear();
00174
00178 int length() const {return n;}
00179
00183 bool empty() const {return n==0;}
00185 };
00186
00187 #endif
00188