Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cmsgheap.h

00001 //==========================================================================
00002 //   CMSGHEAP.H  - header for
00003 //                             OMNeT++
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-2001 Andras Varga
00014   Technical University of Budapest, Dept. of Telecommunications,
00015   Stoczek u.2, H-1111 Budapest, Hungary.
00016 
00017   This file is distributed WITHOUT ANY WARRANTY. See the file
00018   `license' for details on this and other legal matters.
00019 *--------------------------------------------------------------*/
00020 
00021 #ifndef __CMSGHEAP_H
00022 #define __CMSGHEAP_H
00023 
00024 #include "cobject.h"
00025 
00026 class cMessage;
00027 
00028 //==========================================================================
00029 
00037 class SIM_API cMessageHeap : public cObject
00038 {
00039     friend class cMessageHeapIterator;
00040   private:
00041     cMessage **h;             // pointer to the 'heap'  (h[0] always empty)
00042     int n;                    // number of elements in the heap
00043     int size;                 // size of allocated h array
00044     unsigned long insertcntr; // counts insertions
00045 
00046     // internal
00047     void shiftup(int from=1);
00048 
00049   public:
00052 
00056     cMessageHeap(const cMessageHeap& msgq);
00057 
00061     cMessageHeap(const char *name=NULL, int size=128);
00062 
00066     virtual ~cMessageHeap();
00067 
00072     cMessageHeap& operator=(const cMessageHeap& msgqueue);
00074 
00077 
00081     virtual const char *className() const {return "cMessageHeap";}
00082 
00087     virtual cObject *dup() const  {return new cMessageHeap(*this);}
00088 
00093     virtual void info(char *buf);
00094 
00099     virtual const char *inspectorFactoryName() const {return "cMessageHeapIFC";}
00100 
00105     virtual void forEach(ForeachFunc f);
00106 
00107     // no netPack() and netUnpack()
00109 
00112 
00116     void insert(cMessage *event);
00117 
00121     cMessage *peekFirst() const;
00122 
00127     cMessage *getFirst();
00128 
00132     cMessage *get(cMessage *event);
00133 
00138     void sort();
00139 
00143     void clear();
00144 
00148     int length() const {return n;}
00149 
00153     bool empty() const {return n==0;}
00155 };
00156 
00157 //==========================================================================
00158 
00164 class SIM_API cMessageHeapIterator
00165 {
00166   private:
00167     cMessageHeap *q;
00168     int pos;
00169   public:
00170 
00174     cMessageHeapIterator(const cMessageHeap& mh)  {q=const_cast<cMessageHeap*>(&mh);pos=1;} //FIXME: not correct?
00175 
00179     void init(const cMessageHeap& mh) {q=const_cast<cMessageHeap*>(&mh);pos=1;}
00180 
00184     cMessage *operator()()      {return q->h[pos];}
00185 
00190     cMessage *operator++(int)   {return pos<=q->n ? q->h[++pos] : NO(cMessage);}
00191 
00195     bool end() const                  {return (bool)(pos>q->n);}
00196 };
00197 
00198 #endif
00199 

Generated at Sat May 4 15:45:48 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001