ContRap-Core
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes

crp::ObjectFactory Class Reference

Object factory provides an interface for instantiating objects from a string holding the type. More...

#include <objectfactory.h>

Public Member Functions

void register_type (MetaInfo *meta_info)
 Registers a new type.
bool unregister_type (MetaInfo *meta_info)
 Unregisters a type.
void destroy (void *object, const std::string &type_name)
 Destroys an instance of an object.
bool is_registered (const std::string &type_name)
 Checks if the mangled type is registered.
bool is_type_name (const std::string &type_name)
 Checks if a type is a registered type name.
bool is_object (const std::string &type_name)
 Checks if the type is a native ContRap object.
DPtr cast (const DPtr &object, const std::string &type_name)
 Casts an object to the given type if possible.
const std::string & get_type_id (const std::string &type_name) const
 Returns the type identifier of a type.
const std::string & get_type_name (const std::string &type_name) const
 Returns the real name of a mangled type.
MetaInfoget_meta_info (const std::string &type_name)
 Returns the types meta information.
std::string to_string () const
 Returns the contents as a string.

Static Public Member Functions

static ObjectFactoryget_instance ()
 Returns the instance of the factory.

Protected Attributes

std::map< std::string, MetaInfometa_infos
 Holds the type meta information.
std::map< std::string,
std::string > 
real_to_mangled
 Association between mangled and real type names.

Static Protected Attributes

static ObjectFactoryobject_factory
 Static variable holding the singleton instance.

Detailed Description

Object factory provides an interface for instantiating objects from a string holding the type.


Member Function Documentation

DPtr crp::ObjectFactory::cast ( const DPtr object,
const std::string &  type_name 
)

Casts an object to the given type if possible.

Parameters:
objectObject to cast to
type_nameType to cast to
Pointerto the castet object
void crp::ObjectFactory::destroy ( void *  object,
const std::string &  type_name 
)

Destroys an instance of an object.

Parameters:
objectVoid pointer to the object
type_nameName of the type
static ObjectFactory* crp::ObjectFactory::get_instance ( ) [static]

Returns the instance of the factory.

Returns:
Singleton instance of the factory
MetaInfo* crp::ObjectFactory::get_meta_info ( const std::string &  type_name)

Returns the types meta information.

Notice: The type name must be given in exactly the same form as it was registered by the meta implementation macro.

Parameters:
type_nameReal type name
Returns:
Types meta info
const std::string& crp::ObjectFactory::get_type_id ( const std::string &  type_name) const

Returns the type identifier of a type.

The returned value is system dependend.

Notice: The type name must be given in exactly the same form as it was registered by the meta implementation macro.

Parameters:
type_nameName of a type
Returns:
Mangled type
const std::string& crp::ObjectFactory::get_type_name ( const std::string &  type_name) const

Returns the real name of a mangled type.

This name is system dependent.

Notice: The type name must be given in exactly the same form as it was registered by the meta implementation macro.

Parameters:
type_nameName of a mangled type
Returns:
Registred type name
bool crp::ObjectFactory::is_object ( const std::string &  type_name)

Checks if the type is a native ContRap object.

Parameters:
type_nameName of the type
Returns:
True if the object is object
bool crp::ObjectFactory::is_registered ( const std::string &  type_name)

Checks if the mangled type is registered.

The mangled type is system dependent and should not hard-coded as a string. Use the TYPE_NAME macro to get a type name on your system.

Parameters:
type_nameName of the type
Returns:
True if the object is registered
bool crp::ObjectFactory::is_type_name ( const std::string &  type_name)

Checks if a type is a registered type name.

The type name must exactly match the type name which was used in the CONTRAP_OBJECT macro at the registration time point.

Parameters:
type_nameName of the type
Returns:
True if the object is registered
void crp::ObjectFactory::register_type ( MetaInfo meta_info)

Registers a new type.

Parameters:
meta_infoMeta info of the type
std::string crp::ObjectFactory::to_string ( ) const

Returns the contents as a string.

Returns:
String with factory contents
bool crp::ObjectFactory::unregister_type ( MetaInfo meta_info)

Unregisters a type.

Parameters:
meta_infoMeta info of the type
Returns:
True if the type was registered.

Field Documentation

std::map<std::string, MetaInfo> crp::ObjectFactory::meta_infos [protected]

Holds the type meta information.

Static variable holding the singleton instance.

std::map<std::string, std::string> crp::ObjectFactory::real_to_mangled [protected]

Association between mangled and real type names.


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