Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | Static Private Member Functions
boostx::factory< INTERFACE, TYPEINFO, ARGS > Struct Template Reference

The central factory class. More...

#include <factory.hpp>

Public Types

typedef INTERFACE interface_type
 Typedef for our abstract interface. More...
 
typedef factory
< interface_type, TYPEINFO,
ARGS...> 
type
 Typedef for this factory type. More...
 
template<typename T >
using typeinfo_type = TYPEINFO< T >
 Template alias for typeinfo type. More...
 
typedef typeinfo_type
< interface_type >
::typeid_type 
key_type
 Get key type from typeinfo struct. More...
 
typedef std::function
< interface_type *(ARGS...)> 
constructor_type
 Constructor function type. More...
 
typedef std::unordered_map
< key_type, constructor_type
class_map_type
 Internal type of map for storing ids. More...
 
template<typename T >
using registrar_type = registrar< T, type, ARGS...>
 Alias template for registar. More...
 

Static Public Member Functions

static bool exists (const key_type &_key)
 Checks if class with element id is registered. More...
 
template<typename T >
static void reg (const key_type &_key)
 Registers class with custom key. More...
 
template<typename T >
static void reg ()
 Registers class by getting key from registrar's type id. More...
 
static void unreg (const key_type &_key)
 Unregisters class with custom key. More...
 
template<typename T >
static void unreg ()
 Unregisters class by getting key from registrar. More...
 
static interface_typecreate (const key_type &_key, const ARGS &..._args)
 Instantiates an object of the class by id and constructor arguments. More...
 
static class_map_type const & classes ()
 Gives readonly access to registered classes. More...
 

Static Private Member Functions

template<typename T >
static void key_type_check ()
 Checks if key types are the same. More...
 
static class_map_typeprivate_classes ()
 

Detailed Description

template<typename INTERFACE, template< class > class TYPEINFO, typename... ARGS>
struct boostx::factory< INTERFACE, TYPEINFO, ARGS >

The central factory class.

Template Parameters
INTERFACETypename of the abstract interface
TYPEINFOTemplate template parameter for the typeinfo
...ARGSTemplate parameter which comply to the constructor signature of the interface

Member Typedef Documentation

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
typedef std::unordered_map<key_type,constructor_type> boostx::factory< INTERFACE, TYPEINFO, ARGS >::class_map_type

Internal type of map for storing ids.

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
typedef std::function<interface_type*(ARGS...)> boostx::factory< INTERFACE, TYPEINFO, ARGS >::constructor_type

Constructor function type.

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
typedef INTERFACE boostx::factory< INTERFACE, TYPEINFO, ARGS >::interface_type

Typedef for our abstract interface.

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
typedef typeinfo_type<interface_type>::typeid_type boostx::factory< INTERFACE, TYPEINFO, ARGS >::key_type

Get key type from typeinfo struct.

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
template<typename T >
using boostx::factory< INTERFACE, TYPEINFO, ARGS >::registrar_type = registrar<T,type,ARGS...>

Alias template for registar.

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
typedef factory<interface_type,TYPEINFO,ARGS...> boostx::factory< INTERFACE, TYPEINFO, ARGS >::type

Typedef for this factory type.

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
template<typename T >
using boostx::factory< INTERFACE, TYPEINFO, ARGS >::typeinfo_type = TYPEINFO<T>

Template alias for typeinfo type.

Member Function Documentation

template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
static class_map_type const& boostx::factory< INTERFACE, TYPEINFO, ARGS >::classes ( )
inlinestatic

Gives readonly access to registered classes.

109  {
110  return private_classes();
111  }
static class_map_type & private_classes()
Definition: factory.hpp:128
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
static interface_type* boostx::factory< INTERFACE, TYPEINFO, ARGS >::create ( const key_type _key,
const ARGS &...  _args 
)
inlinestatic

Instantiates an object of the class by id and constructor arguments.

102  {
103  if (!exists(_key)) return nullptr;
104  return private_classes()[_key](_args...);
105  }
static class_map_type & private_classes()
Definition: factory.hpp:128
static bool exists(const key_type &_key)
Checks if class with element id is registered.
Definition: factory.hpp:64
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
static bool boostx::factory< INTERFACE, TYPEINFO, ARGS >::exists ( const key_type _key)
inlinestatic

Checks if class with element id is registered.

65  {
66  return private_classes().count(_key) > 0;
67  }
static class_map_type & private_classes()
Definition: factory.hpp:128
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
template<typename T >
static void boostx::factory< INTERFACE, TYPEINFO, ARGS >::key_type_check ( )
inlinestaticprivate

Checks if key types are the same.

117  {
118  // Check if T is a base class of interface
119  static_assert(std::is_base_of<interface_type,T>::value,
120  "Given type T must be a base class of the interface class");
121 
122  // Check if registrar's type id and key type are the same
123  typedef std::is_same<decltype(registrar_type<T>::type_id()),key_type> is_same_type;
124  static_assert(is_same_type::value,
125  "Type of type id to be registered and registrys type id must be equal!");
126  }
typeinfo_type< interface_type >::typeid_type key_type
Get key type from typeinfo struct.
Definition: factory.hpp:51
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
static class_map_type& boostx::factory< INTERFACE, TYPEINFO, ARGS >::private_classes ( )
inlinestaticprivate
129  {
130  static class_map_type _classes;
131  return _classes;
132  }
std::unordered_map< key_type, constructor_type > class_map_type
Internal type of map for storing ids.
Definition: factory.hpp:57
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
template<typename T >
static void boostx::factory< INTERFACE, TYPEINFO, ARGS >::reg ( const key_type _key)
inlinestatic

Registers class with custom key.

72  {
73  if (exists(_key)) return;
74  private_classes()[_key] = registrar_type<T>::create;
75  }
static class_map_type & private_classes()
Definition: factory.hpp:128
static bool exists(const key_type &_key)
Checks if class with element id is registered.
Definition: factory.hpp:64
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
template<typename T >
static void boostx::factory< INTERFACE, TYPEINFO, ARGS >::reg ( )
inlinestatic

Registers class by getting key from registrar's type id.

80  {
81  key_type_check<T>();
83  }
static decltype(typeinfo_type()()) type_id()
Return type id by calling the call operator of type info template.
Definition: factory.hpp:187
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
static void boostx::factory< INTERFACE, TYPEINFO, ARGS >::unreg ( const key_type _key)
inlinestatic

Unregisters class with custom key.

87  {
88  if (!exists(_key)) return;
89  private_classes().erase(_key);
90  }
static class_map_type & private_classes()
Definition: factory.hpp:128
static bool exists(const key_type &_key)
Checks if class with element id is registered.
Definition: factory.hpp:64
template<typename INTERFACE , template< class > class TYPEINFO, typename... ARGS>
template<typename T >
static void boostx::factory< INTERFACE, TYPEINFO, ARGS >::unreg ( )
inlinestatic

Unregisters class by getting key from registrar.

95  {
96  key_type_check<T>();
97  unreg(registrar_type<T>::type_id());
98  }
static void unreg()
Unregisters class by getting key from registrar.
Definition: factory.hpp:94

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