Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

carray.h

00001 //==========================================================================
00002 //   CARRAY.H  - header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cBag      : expandable array to store small no-class items
00009 //    cArray    : flexible array to store cObject objects
00010 //
00011 //==========================================================================
00012 
00013 /*--------------------------------------------------------------*
00014   Copyright (C) 1992-2001 Andras Varga
00015   Technical University of Budapest, Dept. of Telecommunications,
00016   Stoczek u.2, H-1111 Budapest, Hungary.
00017 
00018   This file is distributed WITHOUT ANY WARRANTY. See the file
00019   `license' for details on this and other legal matters.
00020 *--------------------------------------------------------------*/
00021 
00022 #ifndef __CARRAY_H
00023 #define __CARRAY_H
00024 
00025 #include "cobject.h"
00026 
00027 //=== classes declared here
00028 class  cArray;
00029 class  cBag;
00030 
00031 //==========================================================================
00032 
00046 class SIM_API cBag : public cObject
00047 {
00048   private:
00049     char *vect;
00050     int elemsize;
00051     int size;
00052     int delta;
00053     int lastused;
00054     int firstfree;
00055 
00056   public:
00059 
00063     cBag(const cBag& bag);
00064 
00070     explicit cBag(const char *name=NULL, int esiz=4,int siz=0,int delt=5);
00071 
00075     virtual ~cBag()  {clear();}
00076 
00081     cBag& operator=(const cBag& bag);
00083 
00086 
00090     virtual const char *className() const {return "cBag";}
00091 
00096     virtual cObject *dup() const  {return new cBag(*this);}
00097 
00102     virtual void info(char *buf);
00103 
00108     virtual const char *inspectorFactoryName() const {return "cBagIFC";}
00109 
00115     virtual int netPack();
00116 
00122     virtual int netUnpack();
00124 
00127 
00132     void setup(int esiz, int siz, int delt=5);
00133 
00137     void clear();
00138 
00144     int items() const {return lastused+1;}
00145 
00151     int add(void *obj);
00152 
00156     int addAt(int m, void *obj);
00157 
00163     int find(void *obj) const;
00164 
00169     void *get(int m);
00170 
00175     const void *get(int m) const;
00176 
00181     void *operator[](int m)
00182           {return get(m);}
00183 
00188     const void *operator[](int m) const
00189       {return get(m);}
00190 
00195     bool isUsed(int m) const;
00196 
00200     void *remove(int m);
00202 };
00203 
00204 //==========================================================================
00205 
00217 class SIM_API cArray : public cObject
00218 {
00219   private:
00220     cObject **vect;   // vector of objects
00221     int size;         // size of vector
00222     int delta;        // if needed, grows by delta
00223     int firstfree;    // first free position in vect[]
00224     int last;         // last used position
00225 
00226   public:
00229 
00236     cArray(const cArray& list);
00237 
00242     explicit cArray(const char *name=NULL, int siz=0, int dt=10);
00243 
00248     virtual ~cArray();
00249 
00257     cArray& operator=(const cArray& list);
00259 
00262 
00266     virtual const char *className() const {return "cArray";}
00267 
00273     virtual cObject *dup() const  {return new cArray(*this);}
00274 
00279     virtual void info(char *buf);
00280 
00285     virtual const char *inspectorFactoryName() const {return "cArrayIFC";}
00286 
00291     virtual void forEach(ForeachFunc f);
00292 
00298     virtual int netPack();
00299 
00305     virtual int netUnpack();
00307 
00310 
00316     int items() const {return last+1;}
00317 
00322     void clear();
00323 
00329     int add(cObject *obj);
00330 
00335     int addAt(int m,cObject *obj);
00336 
00342     int find(cObject *obj) const;
00343 
00349     int find(const char *objname) const;
00350 
00355     cObject *get(int m);
00356 
00361     cObject *get(const char *objname);
00362 
00367     const cObject *get(int m) const;
00368 
00373     const cObject *get(const char *objname) const;
00374 
00379     cObject *operator[](int m)
00380       {return get(m);}
00381 
00386     cObject *operator[](const char *objname)
00387       {return get(objname);}
00388 
00393     const cObject *operator[](int m) const
00394       {return get(m);}
00395 
00400     const cObject *operator[](const char *objname) const
00401       {return get(objname);}
00402 
00406     bool exist(int m) const
00407       {return m>=0 && m<=last && vect[m]!=NULL;}
00408 
00413     bool exist(const char *objname) const
00414       {return find(objname)!=-1;}
00415 
00421     cObject *remove(int m);
00422 
00428     cObject *remove(const char *objname);
00429 
00435     cObject *remove(cObject *obj);
00437 };
00438 
00439 #endif
00440 

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