carray.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CARRAY_H
00021 #define __CARRAY_H
00022
00023 #include "cownedobject.h"
00024
00025 NAMESPACE_BEGIN
00026
00027
00042 class SIM_API cArray : public cOwnedObject
00043 {
00044 public:
00048 class Iterator
00049 {
00050 private:
00051 cArray *array;
00052 int k;
00053
00054 public:
00060 Iterator(const cArray& a, bool athead=true) {init(a, athead);}
00061
00065 void init(const cArray& a, bool athead=true);
00066
00071 cObject *operator()() {return array->get(k);}
00072
00076 bool end() const {return k<0 || k>=array->size();}
00077
00086 cObject *operator++(int);
00087
00096 cObject *operator--(int);
00097 };
00098
00099 private:
00100 enum {FL_TKOWNERSHIP = 4};
00101 cObject **vect;
00102 int capacity;
00103 int delta;
00104 int firstfree;
00105 int last;
00106
00107 private:
00108 void copy(const cArray& other);
00109
00110 public:
00113
00119 cArray(const cArray& list);
00120
00125 explicit cArray(const char *name=NULL, int capacity=0, int delta=10);
00126
00131 virtual ~cArray();
00132
00140 cArray& operator=(const cArray& list);
00142
00145
00151 virtual cArray *dup() const {return new cArray(*this);}
00152
00157 virtual std::string info() const;
00158
00163 virtual void forEachChild(cVisitor *v);
00164
00170 virtual void parsimPack(cCommBuffer *buffer);
00171
00177 virtual void parsimUnpack(cCommBuffer *buffer);
00179
00182
00188 int size() const {return last+1;}
00189
00194 void clear();
00195
00199 int getCapacity() const {return capacity;}
00200
00205 void setCapacity(int capacity);
00206
00212 int add(cObject *obj);
00213
00219 int addAt(int m, cObject *obj);
00220
00228 int set(cObject *obj);
00229
00235 int find(cObject *obj) const;
00236
00242 int find(const char *objname) const;
00243
00248 cObject *get(int m);
00249
00254 cObject *get(const char *objname);
00255
00260 const cObject *get(int m) const;
00261
00266 const cObject *get(const char *objname) const;
00267
00272 cObject *operator[](int m) {return get(m);}
00273
00278 cObject *operator[](const char *objname) {return get(objname);}
00279
00284 const cObject *operator[](int m) const {return get(m);}
00285
00290 const cObject *operator[](const char *objname) const {return get(objname);}
00291
00295 bool exist(int m) const {return m>=0 && m<=last && vect[m]!=NULL;}
00296
00301 bool exist(const char *objname) const {return find(objname)!=-1;}
00302
00308 cObject *remove(int m);
00309
00315 cObject *remove(const char *objname);
00316
00323 cObject *remove(cObject *obj);
00325
00333
00346 void setTakeOwnership(bool tk) {setFlag(FL_TKOWNERSHIP,tk);}
00347
00353 bool getTakeOwnership() const {return flags&FL_TKOWNERSHIP;}
00355 };
00356
00357 NAMESPACE_END
00358
00359
00360 #endif
00361