cArray Class Reference
[Container classes]

#include <carray.h>

Inheritance diagram for cArray:

cObject cPolymorphic List of all members.

Detailed Description

Container object that holds objects derived from cObject.

cArray stores the pointers of the objects inserted instead of making copies. cArray works as an array, but if it gets full, it grows automatically by a specified delta.

By default, cArray's destructor deletes all contained objects. This behaviour can be changed by calling takeOwnership(false) before inserting objects. More precisely, the behaviour can be controlled per-object: the insertion-time state of the takeOwnership flag will determine whether the inserted object will be deleted by the cArray destructor or not.


Public Member Functions

Constructors, destructor, assignment.
 cArray (const cArray &list)
 cArray (const char *name=NULL, int siz=0, int dt=10)
virtual ~cArray ()
cArrayoperator= (const cArray &list)
Redefined cObject member functions
virtual cPolymorphicdup () const
virtual std::string info () const
virtual void forEachChild (cVisitor *v)
virtual void netPack (cCommBuffer *buffer)
virtual void netUnpack (cCommBuffer *buffer)
Container functions.
int items () const
void clear ()
int add (cObject *obj)
int addAt (int m, cObject *obj)
int set (cObject *obj)
int find (cObject *obj) const
int find (const char *objname) const
cObjectget (int m)
cObjectget (const char *objname)
const cObjectget (int m) const
const cObjectget (const char *objname) const
cObjectoperator[] (int m)
cObjectoperator[] (const char *objname)
const cObjectoperator[] (int m) const
const cObjectoperator[] (const char *objname) const
bool exist (int m) const
bool exist (const char *objname) const
cObjectremove (int m)
cObjectremove (const char *objname)
cObjectremove (cObject *obj)
Ownership control flag.
The ownership control flag is to be used by derived container classes. If the flag is set, the container should take() any object that is inserted into it.

void takeOwnership (bool tk)
bool takeOwnership () const

Classes

class  Iterator
 Walks along a cArray. More...


Constructor & Destructor Documentation

cArray::cArray const cArray list  ) 
 

Copy constructor.

Contained objects that are owned by cArray (that is, whose owner() is the cArray) will be duplicated so that the new cArray will have its own copy of them.

cArray::cArray const char *  name = NULL,
int  siz = 0,
int  dt = 10
[explicit]
 

Constructor.

The initial size of the container and the delta (by which the size will grow if it gets full) can be specified.

virtual cArray::~cArray  )  [virtual]
 

Destructor.

The contained objects that were owned by the container will be deleted.


Member Function Documentation

int cArray::add cObject obj  ) 
 

Inserts the object into the array.

Only the pointer of the object will be stored. The return value is the object's index in the array.

int cArray::addAt int  m,
cObject obj
 

Inserts the object into the array at the given position.

If the position is occupied, the function throws a cRuntimeError. The return value is the object's index in the array.

void cArray::clear  ) 
 

As a result, the container will be empty.

Contained objects that were owned by the container will be deleted.

virtual cPolymorphic* cArray::dup  )  const [inline, virtual]
 

Duplication and assignment work all right with cArray.

Contained objects that are owned by cArray will be duplicated so that the new cArray will have its own copy of them.

Reimplemented from cObject.

bool cArray::exist const char *  objname  )  const [inline]
 

Returns true if the array contains an object with the given name, otherwise false.

bool cArray::exist int  m  )  const [inline]
 

Returns true if position m is used in the array, otherwise false.

int cArray::find const char *  objname  )  const
 

Returns the index of the first item in the array that has the name pointed to by s (cObject::isName() is used.

) If no such item was found, -1 is returned.

int cArray::find cObject obj  )  const
 

Searches the array for the pointer of the object passed and returns the index of the first match.

If the object was not found, -1 is returned.

virtual void cArray::forEachChild cVisitor v  )  [virtual]
 

Calls v->visit(this) for each contained object.

See cObject for more details.

Reimplemented from cObject.

const cObject* cArray::get const char *  objname  )  const
 

Returns reference to the first object in the array with name s.

Returns NULL if no object with the given name was found.

const cObject* cArray::get int  m  )  const
 

Returns reference to the mth object in the array.

Returns NULL if the mth position is not used.

cObject* cArray::get const char *  objname  ) 
 

Returns reference to the first object in the array with name s.

Returns NULL if no object with the given name was found.

cObject* cArray::get int  m  ) 
 

Returns reference to the mth object in the array.

Returns NULL if the mth position is not used.

virtual std::string cArray::info  )  const [virtual]
 

Produces a one-line description of object contents into the buffer passed as argument.

See cObject for more details.

Reimplemented from cPolymorphic.

int cArray::items  )  const [inline]
 

Returns the index of last used position+1.

This is the same as the number of contained objects if there are no 'holes' in the array. (Removals may create holes.)

virtual void cArray::netPack cCommBuffer buffer  )  [virtual]
 

Serializes the object into a PVM or MPI send buffer.

Used by the simulation kernel for parallel execution. See cObject for more details.

Reimplemented from cObject.

virtual void cArray::netUnpack cCommBuffer buffer  )  [virtual]
 

Deserializes the object from a PVM or MPI receive buffer Used by the simulation kernel for parallel execution.

See cObject for more details.

Reimplemented from cObject.

cArray& cArray::operator= const cArray list  ) 
 

Assignment operator.

The name member doesn't get copied; see cObject's operator=() for more details. Duplication and assignment work all right with cArray. Contained objects that are owned by cArray will be duplicated so that the new cArray will have its own copy of them.

const cObject* cArray::operator[] const char *  objname  )  const [inline]
 

The same as get(const char *).

With the indexing operator, cArray can be used as a vector.

const cObject* cArray::operator[] int  m  )  const [inline]
 

The same as get(int).

With the indexing operator, cArray can be used as a vector.

cObject* cArray::operator[] const char *  objname  )  [inline]
 

The same as get(const char *).

With the indexing operator, cArray can be used as a vector.

cObject* cArray::operator[] int  m  )  [inline]
 

The same as get(int).

With the indexing operator, cArray can be used as a vector.

cObject* cArray::remove cObject obj  ) 
 

Removes the object given with its index/name/pointer from the container, and returns the same pointer.

If the object was not found, NULL is returned. (If the object was owned by the container, drop() is called.)

cObject* cArray::remove const char *  objname  ) 
 

Removes the object given with its index/name/pointer from the container.

(If the object was owned by the container, drop() is called.)

cObject* cArray::remove int  m  ) 
 

Removes the object given with its index/name/pointer from the container.

(If the object was owned by the container, drop() is called.)

int cArray::set cObject obj  ) 
 

Inserts the object into the array.

If the array already contains an object with the same name, it will be replaced (hashtable-like behavior.) The replaced object, if it was owned by the container, is deleted using discard(). The return value is the object's index in the array.

bool cArray::takeOwnership  )  const [inline]
 

Returns the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it.

void cArray::takeOwnership bool  tk  )  [inline]
 

Sets the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it.


The documentation for this class was generated from the following file:
Generated on Sat Oct 21 17:47:56 2006 for OMNeT++/OMNEST Simulation Library by  doxygen 1.4.6