OMNeT++ Simulation Library
5.6.1
|
#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.
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 cObject * | getThisPtr () const |
virtual std::string | str () const |
virtual _OPPDEPRECATED std::string | info () const |
virtual _OPPDEPRECATED std::string | detailedInfo () const |
virtual cObject * | dup () 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 cObject * | getOwner () const |
virtual bool | isOwnedObject () const |
virtual void | forEachChild (cVisitor *v) |
cObject * | findObject (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) |
|
inline |
Constructor. It has an empty body. (The class does not have data members and there is nothing special to do at construction time.)
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 |
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.
|
virtual |
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().
|
inlinevirtual |
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.
|
inline |
Returns true if the object's name is identical to the string passed.
References omnetpp::opp_strcmp().
|
inlinevirtual |
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.
|
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, cSimulation, and cResultRecorder.
|
inline |
Returns the this pointer. Utility function for the logging macros.
|
virtual |
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().
|
inlinevirtual |
|
inlinevirtual |
Deprecated. This method returns an empty string.
|
virtual |
Should be redefined in subclasses to create an exact copy of this object. The default implementation just throws an error, to indicate that the method was not redefined.
Reimplemented in cCanvas, cPixmapFigure, cIconFigure, cImageFigure, cAbstractImageFigure, cLabelFigure, cTextFigure, cAbstractTextFigure, cPathFigure, cPolygonFigure, cPieSliceFigure, cRingFigure, cOvalFigure, cRectangleFigure, cAbstractShapeFigure, cPolylineFigure, cArcFigure, cLineFigure, cAbstractLineFigure, cPanelFigure, cGroupFigure, cPoisson, cNegBinomial, cGeometric, cBinomial, cBernoulli, cIntUniformExcl, cIntUniform, cParetoShifted, cWeibull, cTriang, cDoubleHistogram, cCauchy, cFigure, cStudentT, cLongHistogram, cTopology, cChiSquare, cAutoRangeHistogramStrategy, cErlang, cDynamicExpression, cBeta, cMultiFingerprintCalculator, cWeightedStdDev, cNoncopyableOwnedObject, cDefaultHistogramStrategy, cGamma, cKSplit, cFSM, cSingleFingerprintCalculator, cMessage, cTruncNormal, cQueue, cArray, cMsgPar, cNormal, cHistogram, cOsgCanvas, Sizeof, cPacket, LoopVar, cExponential, cProperty, cFixedRangeHistogramStrategy, cVarHistogram, cEvent, cParImpl, SiblingModuleParameterRef, cEventHeap, cEnum, cPacketQueue, cUniform, ParameterRef, cProperties, cPSquare, cAbstractHistogram, cStdDev, cExpression, cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.
Referenced by cMultiFingerprintCalculator::dup().
|
protectedvirtual |
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.
|
protectedvirtual |
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.
|
protected |
This is a shortcut for the sequence
drop(obj); delete obj;
It is especially useful when writing destructors and assignment operators.
Passing nullptr is allowed.
|
virtual |
Serializes the object into a buffer. This default implementation throws an exception ("packing not implemented").
Reimplemented in cTopology, cNoncopyableOwnedObject, cLegacyHistogram, cFSM, cKSplit, cMessage, cQueue, cArray, cMsgPar, cOwnedObject, cHistogram, cPacket, cChannel, cProperty, cPrecollectionBasedDensityEst, cEvent, cDefaultList, cVarHistogram, cParImpl, cOutVector, cPacketQueue, cProperties, cNamedObject, cStdDev, cPSquare, cExpression, cLegacyHistogramBase, cStatistic, cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.
|
virtual |
Deserializes the object from a buffer. This default implementation just throws an exception ("packing not implemented").
Reimplemented in cTopology, cNoncopyableOwnedObject, cLegacyHistogram, cFSM, cKSplit, cMessage, cQueue, cArray, cMsgPar, cOwnedObject, cHistogram, cPacket, cChannel, cPrecollectionBasedDensityEst, cProperty, cEvent, cDefaultList, cVarHistogram, cParImpl, cPacketQueue, cOutVector, cProperties, cNamedObject, cStdDev, cPSquare, cLegacyHistogramBase, cExpression, cStatistic, cBoolParImpl, cDoubleParImpl, cStringParImpl, cIntParImpl, and cXMLParImpl.
|
inlinevirtual |
Returns owner (or parent) object. This default implementation just returns nullptr.
Reimplemented in cOwnedObject, cGate, cXMLElement, and cPar.
|
inlinevirtual |
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 |
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().
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.
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.