cObject Class Reference
[Simulation core classes]

Root of the OMNeT++ class hierarchy. More...

#include <cobject.h>

Inheritance diagram for cObject:
cChannel::MessageSentSignalValue cCommBuffer cConfiguration cDynamicExpression::Functor cExpression cGate cModelChangeNotification cNamedObject cOutputScalarManager cOutputVectorManager cPar cParsimCommunications cProperties cRNG cScheduler cSnapshotManager cTimestampedValue

List of all members.

Public Member Functions

 cObject ()
 cObject (const cObject &other)
virtual ~cObject ()
virtual const char * getClassName () const
Empty virtual functions which can be redefined in subclasses

virtual const char * getName () const
bool isName (const char *s) const
virtual const char * getFullName () const
virtual std::string getFullPath () const
virtual std::string info () const
virtual std::string detailedInfo () const
virtual cObjectdup () const
Support for parallel execution.

These functions pack/unpack the object from/to a communication buffer, and should be redefined in classes whose instances are expected to travel across partitions.

virtual void parsimPack (cCommBuffer *buffer)
virtual void parsimUnpack (cCommBuffer *buffer)
Miscellaneous functions.

virtual cObjectgetOwner () const
virtual bool isOwnedObject () const
virtual void forEachChild (cVisitor *v)
cObjectfindObject (const char *name, bool deep=true)
Helper functions.

void copyNotSupported () const

Protected Member Functions

Ownership control.

The following functions are intended to be used by derived container classes to manage ownership of their contained objects.

See object description for more info on ownership management.

virtual void take (cOwnedObject *obj)
virtual void drop (cOwnedObject *obj)
void dropAndDelete (cOwnedObject *obj)

Friends

class cOwnedObject
class cDefaultList

Detailed Description

Root of the OMNeT++ class hierarchy.

cObject is a lightweight class, it does not contain any data members.

Note: In OMNeT++ 2.x and 3.x, cObject was called cPolymorphic. Class cObject in 2.x and 3.x has been renamed to cOwnedObject.

It is recommended to use cObject as a base class for any class that has at least one virtual member function. This makes the class more interoperable with OMNeT++, and causes no extra overhead at all. sizeof(cObject) should yield 4 on a 32-bit architecture (4-byte vptr), and using cObject as a base class does not add anything to the size of an object, because a class with a virtual function already has a vptr.

cObject allows the object to be displayed in graphical user interface (Tkenv) via the getClassName(), info() and detailedInfo() methods which you may choose to redefine in your own subclasses.

Using cObject also strengthens type safety. cObject * pointers should replace void * in most places where you need pointers to "any data structure". Using cObject will allow safe downcasts using dynamic_cast and also OMNeT++'s check_and_cast.

Any cObject may become owner of other objects, but owned objects must be subclassed from cOwnedObject.

Subclasses are expected to redefine member functions such as dup(), info(), etc.


Constructor & Destructor Documentation

cObject::cObject (  )  [inline]

Constructor.

It has an empty body. (The class does not have data members and there is nothing special to do at construction time.)

cObject::cObject ( const cObject other  )  [inline]

Copy constructor.

It has an empty body. (The class does not have data members and there is nothing special to do at construction time.) Subclasses should call the copy constructor of their base classes from their own copy constructors.

virtual cObject::~cObject (  )  [virtual]

Destructor.

It has an empty body (the class does not have data members.) It is declared here only to make the class polymorphic and make its destructor virtual.


Member Function Documentation

void cObject::copyNotSupported (  )  const

Convenience function: throws a cRuntimeError ("copying not supported") stating that assignment, copy constructor and dup() will not work for this object.

You can call this from operator=() if you do not want to implement object copying.

Referenced by cExpression::dup(), cAccuracyDetection::dup(), and cTransientDetection::dup().

virtual std::string cObject::detailedInfo (  )  const [virtual]

Can be redefined to produce a detailed, multi-line, arbitrarily long description of the object.

The string appears in the graphical user interface (Tkenv) together with other object data (e.g. class name) wherever it is feasible to display a multi-line string.

Reimplemented in cDensityEstBase, cKSplit, cMessage, cPacket, cMsgPar, cPar, cParImpl, cPSquare, cStdDev, and cXMLParImpl.

virtual void cObject::drop ( cOwnedObject obj  )  [protected, virtual]

Releases ownership of `object', giving it back to its default owner.

The function called by the container object when obj is removed from the container -- releases the ownership of the object and hands it over to its default owner.

The obj pointer should not be NULL.

Reimplemented in cDefaultList.

void cObject::dropAndDelete ( cOwnedObject obj  )  [protected]

This is a shortcut for the sequence.

   drop(obj);
   delete obj;
 

It is especially useful when writing destructors and assignment operators.

Passing NULL is allowed.

See also:
drop()
virtual cObject* cObject::dup (  )  const [virtual]
cObject* cObject::findObject ( const char *  name,
bool  deep = true 
)

Finds the object with the given name.

This function is useful when called on subclasses that are containers. This method finds the object with the given name in a container object and returns a pointer to it or NULL if the object has not been found. If deep is false, only objects directly contained will be searched, otherwise the function searches the whole subtree for the object. It uses the forEachChild() mechanism.

Do not use it for finding submodules! Use cModule::getModuleByRelativePath() instead.

virtual void cObject::forEachChild ( cVisitor v  )  [virtual]

Enables traversing the object tree, performing some operation on each object.

The operation is encapsulated in the particular subclass of cVisitor.

This method should be redefined in every subclass to call v->visit(obj) for every obj object contained.

Reimplemented in cArray, cFigure, cCanvas, cChannel, cComponent, cDefaultList, cGate, cMessage, cPacket, cMessageHeap, cModule, cMsgPar, cQueue, cRegistrationList, cSimpleModule, and cSimulation.

virtual const char* cObject::getClassName (  )  const [virtual]

Returns a pointer to the class name string.

This method is implemented using typeid (C++ RTTI), and it does not need to be overridden in subclasses.

Reimplemented in cGenericReadonlyWatch< T >, cGenericAssignableWatch< T >, cWatch_bool, cWatch_char, cWatch_uchar, cWatch_stdstring, cWatch_cObject, and cWatch_cObjectPtr.

Referenced by check_and_cast().

virtual const char* cObject::getFullName (  )  const [inline, virtual]

When this object is part of a vector (like a submodule can be part of a module vector, or a gate can be part of a gate vector), this method returns the object's name with the index in brackets; for example: "out[5]".

This default implementation just returns getName().

Reimplemented in cComponentType, cGate, cModule, cProperty, NEDSupport::ParameterRef, NEDSupport::SiblingModuleParameterRef, NEDSupport::LoopVar, and NEDSupport::Sizeof.

References cNamedObject::getName().

virtual std::string cObject::getFullPath (  )  const [virtual]

Returns the full path of the object in the object hierarchy, like "net.host[2].tcp.winsize".

This method relies on getOwner(): if there is an owner object, this method returns the owner's fullPath plus this object's fullName, separated by a dot; otherwise it simply returns fullName.

Reimplemented in cModule, and cSimulation.

Referenced by check_and_cast().

virtual const char* cObject::getName (  )  const [inline, virtual]

Returns pointer to the object's name.

It should never return NULL. This default implementation just returns an empty string ("").

Reimplemented in cGate, cNamedObject, cPar, and cProperties.

virtual cObject* cObject::getOwner (  )  const [inline, virtual]

May be redefined to return an owner or parent object.

This default implementation just returns NULL.

Reimplemented in cGate, cOwnedObject, and cPar.

virtual std::string cObject::info (  )  const [virtual]
virtual bool cObject::isOwnedObject (  )  const [inline, virtual]

Returns true if this class is a subclass of cOwnedObject.

This is a performance optimization, to avoid frequent calls to dynamic_cast<>. In cObject this method returns false, in cOwnedObject it returns true, and it MUST NOT be defined on any other class.

Reimplemented in cOwnedObject.

virtual void cObject::take ( cOwnedObject obj  )  [protected, virtual]

Makes this object the owner of 'object'.

The function called by the container object when it takes ownership of the obj object that is inserted into it.

The obj pointer should not be NULL.

Reimplemented in cDefaultList.


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:29 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3