Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | Related Pages

cmsgheap.h

00001 //==========================================================================
00002 //  CMSGHEAP.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cMessageHeap : future event set, implemented as heap
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992-2005 Andras Varga
00014 
00015   This file is distributed WITHOUT ANY WARRANTY. See the file
00016   `license' for details on this and other legal matters.
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;             // pointer to the 'heap'  (h[0] always empty)
00081     int n;                    // number of elements in the heap
00082     int size;                 // size of allocated h array
00083     unsigned long insertcntr; // counts insertions
00084 
00085     // internal
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     // no netPack() and netUnpack()
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 

Generated on Fri Apr 1 12:25:32 2005 for OMNeT++/OMNEST Simulation Library by  doxygen 1.3.9.1