The class behind the createOne() function and the Register_Class() macro. More...
#include <cobjectfactory.h>
Public Member Functions | |
Constructors, destructor, assignment. | |
cObjectFactory (const char *name, cObject *(*creatorfunc)(), void *(*castfunc)(cObject *), const char *description=NULL) | |
Redefined cObject member functions. | |
virtual std::string | info () const |
New methods | |
virtual bool | isAbstract () const |
virtual cObject * | createOne () const |
virtual bool | isInstance (cObject *obj) const |
const char * | getDescription () const |
Static Public Member Functions | |
Static factory methods | |
static cObjectFactory * | find (const char *classname) |
static cObjectFactory * | get (const char *classname) |
static cObject * | createOne (const char *classname) |
static cObject * | createOneIfClassIsKnown (const char *classname) |
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.
static cObject* cObjectFactory::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 a NULL pointer 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.
virtual cObject* cObjectFactory::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 createOne().
static cObject* cObjectFactory::createOneIfClassIsKnown | ( | const char * | classname | ) | [static] |
A variant of the createOne() function; this function doesn't throw an exception if the class is not registered, but returns a NULL pointer instead.
Referenced by createOneIfClassIsKnown().
static cObjectFactory* cObjectFactory::find | ( | const char * | classname | ) | [static] |
Finds the factory object for the class given in the classname parameter, or NULL if not found.
The class name string should be given with any potential namespace, enclosing class etc. The class must have been registered previously with the Register_Class() macro.
virtual std::string cObjectFactory::info | ( | ) | const [virtual] |
virtual bool cObjectFactory::isAbstract | ( | ) | const [inline, virtual] |
Returns true if the class this object stands for is abstract.
createOne() cannot be called for abstract classes.