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.
- See also
- Register_Class(), Define_Module() macros
◆ cObjectFactory()
◆ 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.
◆ isAbstract()
virtual bool isAbstract |
( |
| ) |
const |
|
inlinevirtual |
Returns true if the class this object stands for is abstract. createOne() cannot be called for abstract classes.
◆ createOne() [1/2]
virtual cObject* createOne |
( |
| ) |
const |
|
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().
◆ isInstance()
virtual bool isInstance |
( |
cObject * |
obj | ) |
const |
|
inlinevirtual |
Returns true if the given object can be cast (via dynamic_cast) to the class represented by this factory object, and false otherwise.
◆ getDescription()
const char* getDescription |
( |
| ) |
const |
|
inline |
Returns a description string.
◆ find()
static cObjectFactory* find |
( |
const char * |
className, |
|
|
const char * |
contextNamespace = nullptr , |
|
|
bool |
fallbackToOmnetpp = true |
|
) |
| |
|
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.
◆ get()
static cObjectFactory* get |
( |
const char * |
className, |
|
|
const char * |
contextNamespace = nullptr , |
|
|
bool |
fallbackToOmnetpp = true |
|
) |
| |
|
static |
Like find(), but throws an error if the object was not found.
◆ createOne() [2/2]
static cObject* createOne |
( |
const char * |
classname | ) |
|
|
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.
- See also
- createOneIfClassIsKnown()
-
Register_Class() macro
-
cObjectFactory class
◆ createOneIfClassIsKnown()
static cObject* createOneIfClassIsKnown |
( |
const char * |
classname | ) |
|
|
static |
The documentation for this class was generated from the following file: