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. Notes:

  • desired classes must be previously registered via the CH_FACTORY_REGISTER macro, or using ClassRegister, otherwise the ChClassFactory::create() throws an exception.
  • there is no 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 class name. Name is the mnemonic tag given at registration.
 
static bool IsClassRegistered (const std::type_index &mtypeid)
 Tell if a class is registered, from std::type_index.
 
static ChClassRegistrationBaseGetClass (const std::string &keyName)
 Get class registration info from class name. More...
 
static std::string & GetClassTagName (const std::type_index &mtypeid)
 Tell the class name, from type_index. More...
 
template<class T >
static void create (const std::string &keyName, T **ptr)
 Create from class name, for registered classes. More...
 
template<class T >
static void create (const std::string &keyName, ChArchiveIn &archive_in, T **ptr)
 Create from class name, for registered classes. More...
 
template<class T >
static void archive_in (const std::string &keyName, ChArchiveIn &archive_in, T *ptr)
 Populate an already existing object with its ArchiveIn.
 
template<class T >
static void archive_out (const std::string &keyName, ChArchiveOut &archive_out, T *ptr)
 Archive out the most derived object pointed by ptr.
 
template<class T >
static void archive_out_constructor (const std::string &keyName, ChArchiveOut &archive_out, T *ptr)
 Populate an already existing object with its ArchiveIn.
 

Member Function Documentation

◆ ClassRegister()

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

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.

◆ ClassUnregister()

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

Unregister a class from the global class factory.

Provide an unique name.

◆ create() [1/2]

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

Create from class name, for registered classes.

Name is the mnemonic tag given at registration. If a static T* ArchiveInConstructor(ChArchiveIn&) function is available, call it instead. The created object is returned in "ptr"

◆ create() [2/2]

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

Create from class name, for registered classes.

Name is the mnemonic tag given at registration. The created object is returned in "ptr"

◆ GetClass()

static ChClassRegistrationBase* chrono::ChClassFactory::GetClass ( const std::string &  keyName)
inlinestatic

Get class registration info from class name.

Name is the mnemonic tag given at registration. Return nullptr if not registered.

◆ GetClassTagName()

static std::string& chrono::ChClassFactory::GetClassTagName ( const std::type_index &  mtypeid)
inlinestatic

Tell the class name, from type_index.

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


The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono/core/ChClassFactory.h
  • /builds/uwsbel/chrono/src/chrono/core/ChClassFactory.cpp