AndroMeta  2.0.0
Public Member Functions | Static Public Member Functions
Meta::MFactory Class Reference

Interface used to dynamically instantiate a class from M, recreate a stored object, or create a remote object. More...

#include <MFactory.h>

List of all members.

Public Member Functions

 MFactory (const mstr &className)
virtual ~MFactory ()
virtual MObjectBasecreate (mnode f)
virtual MObjectcreate (MBrokerBase *broker)
virtual MObjectBaserecreate (const mvar &v)

Static Public Member Functions

static MObjectBase::ClassIdType allocateClassId ()
static MObjectBaseconstruct (mnode f)
static MObjectBaserestore (const mvar &v)

Detailed Description

Interface used to dynamically instantiate a class from M, recreate a stored object, or create a remote object.

Factories enable dynamic instantiation of a class from M, the re-creation of stored objects from an mvar, and the creation of remote objects (client-side distributed objects). To allow a class to be instantiated from the M intepreter, the user creates an MFactory subclass, re-implementing the relevant methods: create() and recreate(). The factory should then be instantiated statically/globally such that enabling the factory is a simple matter of linking the appropriate library/object.


Constructor & Destructor Documentation

Meta::MFactory::MFactory ( const mstr className)

Constructor.

Parameters:
classNameThe name of the class that this factory refers to.
virtual Meta::MFactory::~MFactory ( ) [virtual]

Destructor.


Member Function Documentation

static MObjectBase::ClassIdType Meta::MFactory::allocateClassId ( ) [static]
Returns:
A unique run-time id for this factory's class.
static MObjectBase* Meta::MFactory::construct ( mnode  f) [static]

Construct an object from a function. This searches for the appropriate factory and creates the object using the available factories and their create() methods.

Parameters:
fFunction to create a class, e.g: MRandom(10)
Returns:
The constructed object or null in the case of failure.
virtual MObjectBase* Meta::MFactory::create ( mnode  f) [virtual]

Reimplement to allow this factory's class to be instantiated from the M interpreter. Default behavior is to return null (disabled).

Parameters:
fThe function node passed to the create the object, e.g: MRandom(10) so that the args may be passed to the appropriate C++ constructor. Should return null in the case of args mismatch.
virtual MObject* Meta::MFactory::create ( MBrokerBase broker) [virtual]

Reimplement to allow this factory's class to be obtained via a distributed broker. This method provides the client-side object of the distributed object. It calls a class-specific constructor which in turn calls MObject(MBrokerBase* broker). The default behavior is to return null (disabled).

virtual MObjectBase* Meta::MFactory::recreate ( const mvar v) [virtual]

Reimplement to allow an object of this factory's class to be reconstructed/restored from an mvar. This method calls the class-specific restore constructor. The default behavior is to return null (disabled).

Parameters:
vThe stored mvar, e.g: [type:MTime, MTime:[sec:12312,usec:3342]].
static MObjectBase* Meta::MFactory::restore ( const mvar v) [static]

Restore an object from a stored mvar. This searches for the appropriate factory and re-creates the object using that factory's recreate() method.

Parameters:
vThe store mvar, e.g: [type:MTime, MTime:[sec:12312,usec:3342]]
Returns:
The resurrected object or null in the case of failure.

The documentation for this class was generated from the following file: