cObjectFactory Class Reference
[Internal classes]

The class behind the createOne() function and the Register_Class() macro. More...

#include <cobjectfactory.h>

Inheritance diagram for cObjectFactory:
cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject

List of all members.

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 cObjectcreateOne () const
virtual bool isInstance (cObject *obj) const
const char * getDescription () const

Static Public Member Functions

Static factory methods

static cObjectFactoryfind (const char *classname)
static cObjectFactoryget (const char *classname)
static cObjectcreateOne (const char *classname)
static cObjectcreateOneIfClassIsKnown (const char *classname)

Detailed Description

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

Member Function Documentation

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.

See also:
createOneIfClassIsKnown()
Register_Class() macro
cObjectFactory class
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.

See also:
createOne()

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]

Produces a one-line description of the object's contents.

See cObject for more details.

Reimplemented from cObject.

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.


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:29 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3