smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy > Class Template Reference

Abstract Factory class. More...

Inheritance diagram for smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >:
[legend]
Collaboration diagram for smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >:
[legend]

Public Types

using IDType = IdentifierType
 

Public Member Functions

void Reserve (std::size_t count)
 
void ReserveAdditional (std::size_t count)
 
bool Register (const IDType &id, ProductCreator creator, const std::type_info &info)
 
bool Deregister (const IDType &id)
 
bool IsRegistered (const IDType &id)
 
bool IsRegistered (const std::type_info &info)
 
AbstractProduct CreateObject (const IDType &id)
 
IDType GetTypeIdentifier (const std::type_info &info)
 
std::vector< IDTypeGetRegisteredIdentifiers () const
 

Private Types

using NameMap = std::unordered_map< size_t, IdentifierType >
 
using TypeMap = std::unordered_map< IdentifierType, ProductCreator >
 

Private Attributes

NameMap typeToIDMap_
 
TypeMap idToCreatorMap_
 

Detailed Description

template<class BaseClass, typename IdentifierType, class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
class smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >

Abstract Factory class.

This factory uses RTTI to allow looking up an existing object's registered type identifier.

Template Parameters
BaseClassBase type of object managed by factory
IdentifierTypeIdentifier type (e.g. std::string)
AbstractProductProduct generated by factory creation method
ProductCreatorType of functor which produces AbstractProduct
FactoryErrorPolicyPolicy for handling errors

Definition at line 73 of file Factory.hpp.

Member Typedef Documentation

◆ IDType

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
using smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >::IDType = IdentifierType

Convenience alias for identifiers

Definition at line 77 of file Factory.hpp.

◆ NameMap

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
using smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >::NameMap = std::unordered_map<size_t, IdentifierType>
private

Alias for std::type_info::hash() -> IdentifierType structure

Definition at line 109 of file Factory.hpp.

◆ TypeMap

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
using smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >::TypeMap = std::unordered_map<IdentifierType, ProductCreator>
private

Alias for IdentifierType -> ProduceCreator structure

Definition at line 111 of file Factory.hpp.

Member Function Documentation

◆ CreateObject()

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
A smgl::detail::Factory< B, I, A, P, E >::CreateObject ( const IDType id)

Create AbstractProduct from registered identifier

Definition at line 111 of file FactoryImpl.hpp.

◆ Deregister()

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
bool smgl::detail::Factory< B, I, A, P, E >::Deregister ( const IDType id)

Deregister type using identifier

Definition at line 88 of file FactoryImpl.hpp.

◆ GetRegisteredIdentifiers()

template<class B , typename I , class A , typename P , template< typename, class > class E>
std::vector< I > smgl::detail::Factory< B, I, A, P, E >::GetRegisteredIdentifiers ( ) const

Get a list of registered identifiers

Definition at line 142 of file FactoryImpl.hpp.

◆ GetTypeIdentifier()

template<class B , typename I , class A , typename P , template< typename, class > class E>
I smgl::detail::Factory< B, I, A, P, E >::GetTypeIdentifier ( const std::type_info info)

Get a registered type's identifier

Definition at line 126 of file FactoryImpl.hpp.

◆ IsRegistered() [1/2]

template<class B , typename I , class A , typename P , template< typename, class > class E>
bool smgl::detail::Factory< B, I, A, P, E >::IsRegistered ( const IDType id)

Check whether given ID is registered to a type

Definition at line 158 of file FactoryImpl.hpp.

◆ IsRegistered() [2/2]

template<class B , typename I , class A , typename P , template< typename, class > class E>
bool smgl::detail::Factory< B, I, A, P, E >::IsRegistered ( const std::type_info info)

Check whether a given type has been registered

Definition at line 170 of file FactoryImpl.hpp.

◆ Register()

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
bool smgl::detail::Factory< B, I, A, P, E >::Register ( const IDType id,
ProductCreator  creator,
const std::type_info info 
)

Register identifier, type, and creation functor

Definition at line 68 of file FactoryImpl.hpp.

◆ Reserve()

template<class B , typename I , class A , typename P , template< typename, class > class E>
void smgl::detail::Factory< B, I, A, P, E >::Reserve ( std::size_t  count)

Reserve space for exactly N registrations

Definition at line 42 of file FactoryImpl.hpp.

◆ ReserveAdditional()

template<class B , typename I , class A , typename P , template< typename, class > class E>
void smgl::detail::Factory< B, I, A, P, E >::ReserveAdditional ( std::size_t  count)

Reserve space for an additional N registrations

Definition at line 55 of file FactoryImpl.hpp.

Member Data Documentation

◆ idToCreatorMap_

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
TypeMap smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >::idToCreatorMap_
private

Holds mappings from IdentifierType -> ProduceCreator

Definition at line 115 of file Factory.hpp.

◆ typeToIDMap_

template<class BaseClass , typename IdentifierType , class AbstractProduct = BaseClass*, typename ProductCreator = std::function<AbstractProduct()>, template< typename, class > class FactoryErrorPolicy = policy::DefaultFactoryError>
NameMap smgl::detail::Factory< BaseClass, IdentifierType, AbstractProduct, ProductCreator, FactoryErrorPolicy >::typeToIDMap_
private

Holds mappings from std::type_info::hash() -> IdentifierType

Definition at line 113 of file Factory.hpp.


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