OMNeT++ Simulation Library  5.5
cObject Class Reference

#include <cobject.h>


Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members.

cObject and its subclass cOwnedObject define an ownership mechanism. Any cObject may become owner of other objects, but owned objects must be subclassed from cOwnedObject. cObject also contains methods that allow the object to be displayed in graphical user interfaces (Tkenv, Qtenv).

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. Subclasses are expected to redefine member functions such as dup(), str(), forEachChild(), etc.

Note: The (cPolymorphic, cObject) classes in OMNeT++ versions 2.x and 3.x were renamed to (cObject, cOwnedObject) in version 4.0.

Inheritance diagram for cObject:
cChannel::MessageSentSignalValue cCommBuffer cConfiguration cDynamicExpression::Functor cExpression cExpression::Context cFingerprintCalculator cGate cIEventlogManager cIHistogramStrategy cIOutputScalarManager cIOutputVectorManager cISnapshotManager cModelChangeNotification cNamedObject cPar cParsimCommunications cProperties cResultListener cRNG cScheduler cTimestampedValue cXMLElement

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
const cObjectgetThisPtr () const
virtual std::string str () const
virtual _OPPDEPRECATED std::string info () const
virtual _OPPDEPRECATED 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) const
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)

Constructor & Destructor Documentation

◆ cObject() [1/2]

cObject ( )

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

◆ cObject() [2/2]

cObject ( const cObject other)

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.

◆ ~cObject()

virtual ~cObject ( )

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

◆ getClassName()

virtual const char* getClassName ( ) const

Returns the (fully qualified) class name. This method is implemented using typeid (C++ RTTI), and it does not need to be overridden in subclasses.

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

Referenced by cWatch_cObject::getClassName(), and cWatch_cObjectPtr::getClassName().

◆ getName()

virtual const char* getName ( ) const

Returns pointer to the object's name. It should never return nullptr. This default implementation just returns an empty string ("").

Reimplemented in cXMLElement, cGate, cPar, cNamedObject, cResultRecorder, and cProperties.

◆ isName()

bool isName ( const char *  s) const

Returns true if the object's name is identical to the string passed.

References omnetpp::opp_strcmp().

◆ getFullName()

virtual const char* getFullName ( ) const

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 cModule, cGate, cComponentType, Sizeof, LoopVar, cProperty, SiblingModuleParameterRef, and ParameterRef.

◆ getFullPath()

virtual std::string getFullPath ( ) const

Returns the full path of the object in the object hierarchy, like "[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, cSimulation, and cResultRecorder.

◆ getThisPtr()

const cObject* getThisPtr ( ) const

Returns the this pointer. Utility function for the logging macros.

◆ str()

virtual std::string str ( ) const

Produce a one-line description of the object. The string is displayed at various places e.g. in graphical user interfaces.

Reimplemented in cCanvas, cPixmapFigure, cImageFigure, cAbstractTextFigure, cPathFigure, cPolygonFigure, cPieSliceFigure, cRingFigure, cOvalFigure, cRectangleFigure, cAbstractShapeFigure, cPolylineFigure, cArcFigure, cLineFigure, cAbstractLineFigure, cPanelFigure, cGroupFigure, cPoisson, cNegBinomial, cGeometric, cBinomial, cBernoulli, cIntUniformExcl, cIntUniform, cParetoShifted, cWeibull, cTriang, cModule, cCauchy, cFigure, cStudentT, cTopology, cChiSquare, SumPerDurationFilter, cErlang, RemoveRepeatsFilter, cDynamicExpression, cBeta, TimeAverageFilter, AverageFilter, cMultiFingerprintCalculator, MaxFilter, cGamma, StatisticsRecorder, cRealTimeScheduler, MinFilter, cFSM, cWatch_cObjectPtr, TimeAverageRecorder, MeanFilter, cSingleFingerprintCalculator, cMessage, cWatch_cObject, cQueue, cTruncNormal, AverageRecorder, cWatch_stdstring, SumFilter, cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, cXMLParImpl, cGate, MaxRecorder, cXMLElement, CountNanFilter, cArray, cMsgPar, cSequentialScheduler, cWatch_uchar, cNormal, MinRecorder, cOsgCanvas, MeanRecorder, cPacket, cWatch_char, cSimpleModule, cChannel, cPar, cNedMathFunction, cProperty, cExponential, SumRecorder, cWatch_bool, cEvent, cEventHeap, cDefaultList, cEnum, ConstantFilter, cDatarateChannel, LastValueRecorder, cNedFunction, cOutVector, cGenericAssignableWatch< T >, cPacketQueue, cProperties, cConfigOption, cUniform, cStdDev, cExpression, cScheduler, cGenericReadonlyWatch< T >, TotalCountRecorder, TotalCountFilter, cFutureEventSet, cObjectFactory, cRegistrationList, and VectorRecorder.

Referenced by cWatch_cObject::str(), and cWatch_cObjectPtr::str().

◆ info()

virtual _OPPDEPRECATED std::string info ( ) const

Deprecated, use str() instead. This method also delegates to str().

◆ detailedInfo()

virtual _OPPDEPRECATED std::string detailedInfo ( ) const

Deprecated. This method returns an empty string.

◆ dup()

◆ take()

virtual void take ( cOwnedObject obj)

Makes this object the owner of obj. This method should be called by container classes when they take ownership of an object inserted into them.

The obj pointer should not be nullptr.

Reimplemented in cDefaultList.

◆ drop()

virtual void drop ( cOwnedObject obj)

Releases ownership of obj, giving it back to its default owner. This method should be called by container classes when an object is removed from the container.

The obj pointer should not be nullptr.

Reimplemented in cDefaultList.

◆ dropAndDelete()

void dropAndDelete ( cOwnedObject obj)

This is a shortcut for the sequence

  delete obj;

It is especially useful when writing destructors and assignment operators.

Passing nullptr is allowed.

See also

◆ parsimPack()

virtual void parsimPack ( cCommBuffer buffer) const

◆ parsimUnpack()

virtual void parsimUnpack ( cCommBuffer buffer)

◆ getOwner()

virtual cObject* getOwner ( ) const

Returns owner (or parent) object. This default implementation just returns nullptr.

Reimplemented in cOwnedObject, cGate, cXMLElement, and cPar.

◆ isOwnedObject()

virtual bool isOwnedObject ( ) const

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.

◆ forEachChild()

virtual void forEachChild ( cVisitor v)

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 cCanvas, cModule, cFigure, cComponent, StatisticsRecorder, cMessage, cQueue, cXMLElement, cArray, cMsgPar, cGate, cPacket, cPar, cSimpleModule, cSimulation, cEvent, cEventHeap, cDefaultList, cResultFilter, and cRegistrationList.

Referenced by cParImpl::forEachChild().

◆ findObject()

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 nullptr 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.

◆ copyNotSupported()

void 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.

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