chrono::ChClassFactory Class Reference

Description

A class factory.

It can create C++ objects from their string name. Just use the ChClassFactory::create() function, given a string. NOTE: desired classes must be previously registered via the CH_FACTORY_REGISTER macro, or using ClassRegister, otherwise the ChClassFactory::create() throws an exception. NOTE: You do not need to explicitly create it: a static ChClassFactory class factory is automatically instanced once, at the first time that someone registers a class. It is consistent also across different DLLs.

#include <ChClassFactory.h>

Static Public Member Functions

static void ClassRegister (const std::string &keyName, ChClassRegistrationBase *mregistration)
 Register a class into the global class factory. More...
 
static void ClassUnregister (const std::string &keyName)
 Unregister a class from the global class factory. More...
 
static bool IsClassRegistered (const std::string &keyName)
 Tell if a class is registered, from its name.
 
static std::string & GetClassTagName (const std::type_info &mtype)
 Tell the tag name of a class. More...
 
template<class T >
static void create (const std::string &keyName, T **ptr)
 Create from tag name, for registered classes. More...
 
template<class T >
static void create (const std::string &keyName, ChArchiveIn &marchive, T **ptr)
 Create from tag name, for registered classes. More...
 

Member Function Documentation

static void chrono::ChClassFactory::ClassRegister ( const std::string &  keyName,
ChClassRegistrationBase mregistration 
)
static

Register a class into the global class factory.

Provide an unique name and a ChClassRegistration object. If multiple registrations with the same name are attempted, only one is done.

static void chrono::ChClassFactory::ClassUnregister ( const std::string &  keyName)
static

Unregister a class from the global class factory.

Provide an unique name.

template<class T >
static void chrono::ChClassFactory::create ( const std::string &  keyName,
T **  ptr 
)
static

Create from tag name, for registered classes.

The created object is returned in "ptr"

template<class T >
static void chrono::ChClassFactory::create ( const std::string &  keyName,
ChArchiveIn marchive,
T **  ptr 
)
static

Create from tag name, for registered classes.

If a static T* ArchiveINconstructor(ChArchiveIn&) function is available, call it instead. The created object is returned in "ptr"

static std::string& chrono::ChClassFactory::GetClassTagName ( const std::type_info &  mtype)
static

Tell the tag name of a class.

This is the mnemonic name, given at registration, not the typeid.name().