ug4
ug::Factory< TBase, TPairSeq > Class Template Reference

A factory class which creates instances given a class-name. More...

#include <factory.h>

Classes

struct  ClassInfo
 

Public Member Functions

const std::string & class_name (const size_t i) const
 
const std::string & class_name (const TBase &cls) const
 
SmartPtr< TBase > create (const char *className)
 
SmartPtr< TBase > create (const std::string &className)
 
TBase * create_raw (const char *className)
 
TBase * create_raw (const std::string &className)
 
 Factory ()
 
size_t num_classes () const
 
template<class TDerived >
void register_class (const char *name)
 

Private Types

typedef std::map< std::string, ClassInfoclass_map_t
 
typedef std::map< std::string, std::string > class_name_map_t
 
typedef TBase *(* factory_sig) ()
 

Private Attributes

class_map_t m_classMap
 contains ClassInfo objects accessible by class-name. More...
 
class_name_map_t m_classNameMap
 key: type-name, value: class-names More...
 
std::vector< std::string > m_classNames
 

Detailed Description

template<class TBase, class TPairSeq = boost::mpl::vector<>>
class ug::Factory< TBase, TPairSeq >

A factory class which creates instances given a class-name.

Given a base-class 'TBase' and an optional boost::mpl sequence of pairs of derived classes and strings 'TPairSeq', the ug::Factory class allows for the creation of instances ofderived classes given a name. Additionally to the classes contained in 'TPairSeq', one may register derived classes at runtime through the 'register_class' method.

Besides creation of registered classes through the 'create' method, one can iterate over all registered classes or obtain a registered class-name given a pointer to the base class.

Note
This factory class is somewhat limited compared to e.g. to boost::factory and is not meant as a replacement. It's main purpose is to allow iteration over registered classes and to perform automatic registration through a type list.

Member Typedef Documentation

◆ class_map_t

template<class TBase , class TPairSeq = boost::mpl::vector<>>
typedef std::map<std::string, ClassInfo> ug::Factory< TBase, TPairSeq >::class_map_t
private

◆ class_name_map_t

template<class TBase , class TPairSeq = boost::mpl::vector<>>
typedef std::map<std::string, std::string> ug::Factory< TBase, TPairSeq >::class_name_map_t
private

◆ factory_sig

template<class TBase , class TPairSeq = boost::mpl::vector<>>
typedef TBase*(* ug::Factory< TBase, TPairSeq >::factory_sig) ()
private

Constructor & Destructor Documentation

◆ Factory()

template<class TBase , class TPairSeq = boost::mpl::vector<>>
ug::Factory< TBase, TPairSeq >::Factory ( )
inline

References func().

Member Function Documentation

◆ class_name() [1/2]

template<class TBase , class TPairSeq = boost::mpl::vector<>>
const std::string& ug::Factory< TBase, TPairSeq >::class_name ( const size_t  i) const
inline

◆ class_name() [2/2]

template<class TBase , class TPairSeq = boost::mpl::vector<>>
const std::string& ug::Factory< TBase, TPairSeq >::class_name ( const TBase &  cls) const
inline

◆ create() [1/2]

template<class TBase , class TPairSeq = boost::mpl::vector<>>
SmartPtr<TBase> ug::Factory< TBase, TPairSeq >::create ( const char *  className)
inline

◆ create() [2/2]

template<class TBase , class TPairSeq = boost::mpl::vector<>>
SmartPtr<TBase> ug::Factory< TBase, TPairSeq >::create ( const std::string &  className)
inline

◆ create_raw() [1/2]

template<class TBase , class TPairSeq = boost::mpl::vector<>>
TBase* ug::Factory< TBase, TPairSeq >::create_raw ( const char *  className)
inline

◆ create_raw() [2/2]

template<class TBase , class TPairSeq = boost::mpl::vector<>>
TBase* ug::Factory< TBase, TPairSeq >::create_raw ( const std::string &  className)
inline

◆ num_classes()

template<class TBase , class TPairSeq = boost::mpl::vector<>>
size_t ug::Factory< TBase, TPairSeq >::num_classes ( ) const
inline

◆ register_class()

template<class TBase , class TPairSeq = boost::mpl::vector<>>
template<class TDerived >
void ug::Factory< TBase, TPairSeq >::register_class ( const char *  name)
inline

Member Data Documentation

◆ m_classMap

template<class TBase , class TPairSeq = boost::mpl::vector<>>
class_map_t ug::Factory< TBase, TPairSeq >::m_classMap
private

◆ m_classNameMap

template<class TBase , class TPairSeq = boost::mpl::vector<>>
class_name_map_t ug::Factory< TBase, TPairSeq >::m_classNameMap
private

◆ m_classNames

template<class TBase , class TPairSeq = boost::mpl::vector<>>
std::vector<std::string> ug::Factory< TBase, TPairSeq >::m_classNames
private

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