OMNeT++ Simulation Library
6.0.3
|
#include <cobjectfactory.h>
The class behind the createOne() function and the Register_Class() macro.
Each instance is a factory for a particular class: it knows how to create an object of that class.
Public Member Functions | |
Constructors, destructor, assignment. | |
cObjectFactory (const char *name, cObject *(*creatorfunc)(), void *(*castfunc)(cObject *), const char *description=nullptr) | |
Redefined cObject member functions. | |
virtual std::string | str () const override |
New methods | |
virtual bool | isAbstract () const |
virtual cObject * | createOne () const |
virtual bool | isInstance (cObject *obj) const |
const char * | getDescription () const |
Public Member Functions inherited from cNoncopyableOwnedObject | |
cNoncopyableOwnedObject (const char *name=nullptr, bool namepooling=true) | |
virtual cNoncopyableOwnedObject * | dup () const override |
Public Member Functions inherited from cOwnedObject | |
cOwnedObject () | |
cOwnedObject (const char *name, bool namepooling=true) | |
cOwnedObject (const cOwnedObject &obj) | |
virtual | ~cOwnedObject () |
cOwnedObject & | operator= (const cOwnedObject &o) |
virtual cObject * | getOwner () 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 () |
cNamedObject & | operator= (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 cObject * | getThisPtr () const |
virtual std::ostream & | printOn (std::ostream &os) const |
virtual bool | isSoftOwner () const |
virtual void | forEachChild (cVisitor *v) |
cObject * | findObject (const char *name, bool deep=true) |
virtual cClassDescriptor * | getDescriptor () const |
void | copyNotSupported () const |
Static Public Member Functions | |
Static factory methods | |
static cObjectFactory * | find (const char *className, const char *contextNamespace=nullptr, bool fallbackToOmnetpp=true) |
static cObjectFactory * | get (const char *className, const char *contextNamespace=nullptr, bool fallbackToOmnetpp=true) |
static cObject * | createOne (const char *classname) |
static cObject * | createOneIfClassIsKnown (const char *classname) |
Static Public Member Functions inherited from cOwnedObject | |
static long | getTotalObjectCount () |
static long | getLiveObjectCount () |
static void | resetObjectCounters () |
static cSoftOwner * | getOwningContext () |
Additional Inherited Members | |
Protected Member Functions inherited from cObject | |
virtual void | take (cOwnedObject *obj) |
virtual void | drop (cOwnedObject *obj) |
void | dropAndDelete (cOwnedObject *obj) |
cObjectFactory | ( | const char * | name, |
cObject *(*)() | creatorfunc, | ||
void *(*)(cObject *) | castfunc, | ||
const char * | description = nullptr |
||
) |
Constructor.
|
overridevirtual |
|
inlinevirtual |
Returns true if the class this object stands for is abstract. createOne() cannot be called for abstract classes.
|
virtual |
Creates an instance of a particular class by calling the creator function. The result has to be cast to the appropriate type (preferably by dynamic_cast or check_and_cast). The method will throw an error if the class is abstract (see isAbstract()).
Referenced by omnetpp::createOne().
|
inlinevirtual |
Returns true if the given object can be cast (via dynamic_cast) to the class represented by this factory object, and false otherwise.
|
inline |
Returns a description string.
|
static |
Finds the factory object for the class given in the className parameter, or nullptr if not found. The class must have been registered previously with the Register_Class() macro.
|
static |
Like find(), but throws an error if the object was not found.
|
static |
Creates an instance of a particular class; the result has to be cast to the appropriate type by hand. The class must have been registered previously with the Register_Class() macro. The class name string should be given with any potential namespace, enclosing class etc.
If the class is not registered, this function throws an exception. If you'd prefer having nullptr returned instead, use the createOneIfClassIsKnown() function.
Example:
cMessage *msg = cObjectFactory::createOne("INET::EthernetFrame");
createOne() is used e.g. in parallel simulation, when an object is received from another partition in serialized form and has to be demarshalled.
|
static |
A variant of the createOne() function; this function doesn't throw an exception if the class is not registered, but returns nullptr instead.
Referenced by omnetpp::createOneIfClassIsKnown().