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-2003 Andras Varga
    00015
    00016   This file is distributed WITHOUT ANY WARRANTY. See the file
    00017   `license' for details on this and other legal matters.
    00018 *--------------------------------------------------------------*/
    00019
    00020 #ifndef __CARRAY_H
    00021 #define __CARRAY_H
    00022
    00023 #include "cobject.h"
    00024
    00025
    00039 class SIM_API cBag : public cObject
    00040 {
    00041   private:
    00042     char *vect;
    00043     int elemsize;
    00044     int size;
    00045     int delta;
    00046     int lastused;
    00047     int firstfree;
    00048
    00049   public:
    00052
    00056     cBag(const cBag& bag);
    00057
    00063     explicit cBag(const char *name=NULL, int esiz=4,int siz=0,int delt=5);
    00064
    00068     virtual ~cBag()  {clear();}
    00069
    00074     cBag& operator=(const cBag& bag);
    00076
    00079
    00084     virtual cObject *dup() const  {return new cBag(*this);}
    00085
    00090     virtual void info(char *buf);
    00091
    00097     virtual int netPack();
    00098
    00104     virtual int netUnpack();
    00106
    00109
    00114     void setup(int esiz, int siz, int delt=5);
    00115
    00119     void clear();
    00120
    00126     int items() const {return lastused+1;}
    00127
    00133     int add(void *obj);
    00134
    00138     int addAt(int m, void *obj);
    00139
    00145     int find(void *obj) const;
    00146
    00151     void *get(int m);
    00152
    00157     const void *get(int m) const;
    00158
    00163     void *operator[](int m)
    00164           {return get(m);}
    00165
    00170     const void *operator[](int m) const
    00171       {return get(m);}
    00172
    00177     bool isUsed(int m) const;
    00178
    00182     void *remove(int m);
    00184 };
    00185
    00186 //==========================================================================
    00187
    00199 class SIM_API cArray : public cObject
    00200 {
    00201   private:
    00202     cObject **vect;   // vector of objects
    00203     int size;         // size of vector
    00204     int delta;        // if needed, grows by delta
    00205     int firstfree;    // first free position in vect[]
    00206     int last;         // last used position
    00207
    00208   public:
    00211
    00218     cArray(const cArray& list);
    00219
    00224     explicit cArray(const char *name=NULL, int siz=0, int dt=10);
    00225
    00230     virtual ~cArray();
    00231
    00239     cArray& operator=(const cArray& list);
    00241
    00244
    00250     virtual cObject *dup() const  {return new cArray(*this);}
    00251
    00256     virtual void info(char *buf);
    00257
    00261     virtual void forEach(ForeachFunc f);
    00262
    00268     virtual int netPack();
    00269
    00275     virtual int netUnpack();
    00277
    00280
    00286     int items() const {return last+1;}
    00287
    00292     void clear();
    00293
    00299     int add(cObject *obj);
    00300
    00306     int addAt(int m,cObject *obj);
    00307
    00315     int set(cObject *obj);
    00316
    00322     int find(cObject *obj) const;
    00323
    00329     int find(const char *objname) const;
    00330
    00335     cObject *get(int m);
    00336
    00341     cObject *get(const char *objname);
    00342
    00347     const cObject *get(int m) const;
    00348
    00353     const cObject *get(const char *objname) const;
    00354
    00359     cObject *operator[](int m)
    00360       {return get(m);}
    00361
    00366     cObject *operator[](const char *objname)
    00367       {return get(objname);}
    00368
    00373     const cObject *operator[](int m) const
    00374       {return get(m);}
    00375
    00380     const cObject *operator[](const char *objname) const
    00381       {return get(objname);}
    00382
    00386     bool exist(int m) const
    00387       {return m>=0 && m<=last && vect[m]!=NULL;}
    00388
    00393     bool exist(const char *objname) const
    00394       {return find(objname)!=-1;}
    00395
    00401     cObject *remove(int m);
    00402
    00408     cObject *remove(const char *objname);
    00409
    00416     cObject *remove(cObject *obj);
    00418 };
    00419
    00420 #endif
    00421