OMNeT++ Simulation Library  6.0.3
cArray Class Reference

#include <carray.h>

Description

Vector-like container for objects derived from cObject.

cArray stores pointers of objects. When the array is full, the its capacity grows automatically by a delta.

Ownership of cOwnedObjects may be controlled by invoking setTakeOwnership() prior to inserting objects. Objects that cannot track their ownership (cObject but not cOwnedObject) are always treated as owned. Whether an object is owned or not affects the operation of the destructor, clean(), the copy constructor and the dup() method.

Inheritance diagram for cArray:
cOwnedObject cNamedObject cObject

Classes

class  Iterator
 Iterates through elements in a cArray, skipping holes (slots containing nullptr). More...
 

Public Member Functions

Constructors, destructor, assignment.
 cArray (const cArray &list)
 
 cArray (const char *name=nullptr, int capacity=0, int delta=10)
 
virtual ~cArray ()
 
cArrayoperator= (const cArray &list)
 
Redefined cObject member functions
virtual cArraydup () const override
 
virtual std::string str () const override
 
virtual void forEachChild (cVisitor *v) override
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) override
 
Container functions.
virtual int size () const
 
virtual void clear ()
 
virtual int getCapacity () const
 
virtual void setCapacity (int capacity)
 
virtual int add (cObject *obj)
 
virtual int addAt (int m, cObject *obj)
 
virtual int set (cObject *obj)
 
virtual int find (cObject *obj) const
 
virtual int find (const char *objname) const
 
virtual cObjectget (int m)
 
virtual cObjectget (const char *objname)
 
virtual const cObjectget (int m) const
 
virtual const cObjectget (const char *objname) const
 
cObjectoperator[] (int m)
 
cObjectoperator[] (const char *objname)
 
const cObjectoperator[] (int m) const
 
const cObjectoperator[] (const char *objname) const
 
virtual bool exist (int m) const
 
virtual bool exist (const char *objname) const
 
virtual cObjectremove (int m)
 
virtual cObjectremove (const char *objname)
 
virtual 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 setTakeOwnership (bool tk)
 
bool getTakeOwnership () const
 
- Public Member Functions inherited from cOwnedObject
 cOwnedObject ()
 
 cOwnedObject (const char *name, bool namepooling=true)
 
 cOwnedObject (const cOwnedObject &obj)
 
virtual ~cOwnedObject ()
 
cOwnedObjectoperator= (const cOwnedObject &o)
 
virtual cObjectgetOwner () const override
 
virtual bool isOwnedObject () const override
 
- Public Member Functions inherited from cNamedObject
 cNamedObject ()
 
 cNamedObject (const char *name, bool namepooling=true)
 
 cNamedObject (const cNamedObject &obj)
 
virtual ~cNamedObject ()
 
cNamedObjectoperator= (const cNamedObject &o)
 
virtual void setName (const char *s)
 
virtual const char * getName () const override
 
virtual void setNamePooling (bool b)
 
virtual bool getNamePooling ()
 
- Public Member Functions inherited from cObject
 cObject ()
 
 cObject (const cObject &other)=default
 
virtual ~cObject ()
 
virtual const char * getClassName () const
 
bool isName (const char *s) const
 
virtual const char * getFullName () const
 
virtual std::string getFullPath () const
 
virtual std::string getClassAndFullName () const
 
virtual std::string getClassAndFullPath () const
 
const cObjectgetThisPtr () const
 
virtual std::ostream & printOn (std::ostream &os) const
 
virtual bool isSoftOwner () const
 
cObjectfindObject (const char *name, bool deep=true)
 
virtual cClassDescriptorgetDescriptor () const
 
void copyNotSupported () const
 

Additional Inherited Members

- Static Public Member Functions inherited from cOwnedObject
static long getTotalObjectCount ()
 
static long getLiveObjectCount ()
 
static void resetObjectCounters ()
 
static cSoftOwnergetOwningContext ()
 
- Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
 
virtual void drop (cOwnedObject *obj)
 
void dropAndDelete (cOwnedObject *obj)
 

Constructor & Destructor Documentation

◆ cArray() [1/2]

cArray ( const cArray list)

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

◆ cArray() [2/2]

cArray ( const char *  name = nullptr,
int  capacity = 0,
int  delta = 10 
)
explicit

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

◆ ~cArray()

virtual ~cArray ( )
virtual

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

Member Function Documentation

◆ operator=()

cArray& operator= ( const cArray list)

Assignment operator. The name member is not copied; see cNamedObject::operator=() for details. Contained objects that are owned by cArray will be duplicated so that the new cArray will have its own copy of them.

◆ dup()

virtual cArray* dup ( ) const
inlineoverridevirtual

Creates and returns an exact copy of this object. 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.

◆ str()

virtual std::string str ( ) const
overridevirtual

Produces a one-line description of the object's contents. See cObject for more details.

Reimplemented from cObject.

◆ forEachChild()

virtual void forEachChild ( cVisitor v)
overridevirtual

Calls v->visit(this) for each contained object. See cObject for more details.

Reimplemented from cObject.

◆ parsimPack()

virtual void parsimPack ( cCommBuffer buffer) const
overridevirtual

Serializes the object into an MPI send buffer. Used by the simulation kernel for parallel execution. See cObject for more details.

Reimplemented from cOwnedObject.

◆ parsimUnpack()

virtual void parsimUnpack ( cCommBuffer buffer)
overridevirtual

Deserializes the object from an MPI receive buffer Used by the simulation kernel for parallel execution. See cObject for more details.

Reimplemented from cOwnedObject.

◆ size()

virtual int size ( ) const
inlinevirtual

Returns the index of last used position+1. This only equals the number of contained objects if there are no "holes" (nullptr elements) in the array.

Referenced by cArray::Iterator::end().

◆ clear()

virtual void clear ( )
virtual

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

◆ getCapacity()

virtual int getCapacity ( ) const
inlinevirtual

Returns the allocated size of the underlying array.

◆ setCapacity()

virtual void setCapacity ( int  capacity)
virtual

Resizes the the underlying array, without changing the contents of this array. The specified capacity cannot be less than size().

◆ add()

virtual int add ( cObject obj)
virtual

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.

◆ addAt()

virtual int addAt ( int  m,
cObject obj 
)
virtual

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.

◆ set()

virtual int set ( cObject obj)
virtual

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.

◆ find() [1/2]

virtual int find ( cObject obj) const
virtual

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.

Referenced by cMessage::hasObject().

◆ find() [2/2]

virtual int find ( const char *  objname) const
virtual

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.

◆ get() [1/4]

virtual cObject* get ( int  m)
virtual

Returns reference to the mth object in the array. Returns nullptr if the mth position is not used.

Referenced by cArray::Iterator::operator*().

◆ get() [2/4]

virtual cObject* get ( const char *  objname)
virtual

Returns reference to the first object in the array with name s. Returns nullptr if no object with the given name was found.

◆ get() [3/4]

virtual const cObject* get ( int  m) const
virtual

Returns reference to the mth object in the array. Returns nullptr if the mth position is not used.

◆ get() [4/4]

virtual const cObject* get ( const char *  objname) const
virtual

Returns reference to the first object in the array with name s. Returns nullptr if no object with the given name was found.

◆ operator[]() [1/4]

cObject* operator[] ( int  m)
inline

The same as get(int). With the indexing operator, cArray can be used as a vector.

◆ operator[]() [2/4]

cObject* operator[] ( const char *  objname)
inline

The same as get(const char *). With the indexing operator, cArray can be used as a vector.

◆ operator[]() [3/4]

const cObject* operator[] ( int  m) const
inline

The same as get(int). With the indexing operator, cArray can be used as a vector.

◆ operator[]() [4/4]

const cObject* operator[] ( const char *  objname) const
inline

The same as get(const char *). With the indexing operator, cArray can be used as a vector.

◆ exist() [1/2]

virtual bool exist ( int  m) const
inlinevirtual

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

◆ exist() [2/2]

virtual bool exist ( const char *  objname) const
inlinevirtual

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

◆ remove() [1/3]

virtual cObject* remove ( int  m)
virtual

Removes the object given with its index/name/pointer from the container. (If the object was owned by the container, drop() is called.)

◆ remove() [2/3]

virtual cObject* remove ( const char *  objname)
virtual

Removes the object given with its index/name/pointer from the container. (If the object was owned by the container, drop() is called.)

◆ remove() [3/3]

virtual cObject* remove ( cObject obj)
virtual

Removes the object given with its index/name/pointer from the container, and returns the same pointer. If the object was not found, nullptr is returned. (If the object was owned by the container, drop() is called.)

◆ setTakeOwnership()

void setTakeOwnership ( bool  tk)
inline

Sets the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it. It does not affect objects already in the queue. When an inserted object is owned by the container, that means it will be deleted when the container object is deleted or cleared, and will be duplicated when the container object is duplicated or copied.

Setting the flag to false does not affect the treatment of objects that are NOT cOwnedObject. Since they do not support the ownership protocol, they will always be treated by the container.

◆ getTakeOwnership()

bool getTakeOwnership ( ) const
inline

Returns the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it. See setTakeOwnedship() for more details.


The documentation for this class was generated from the following file: