DART
6.7.3
|
Implementation of the Abstract Factory Pattern. More...
#include <Factory.hpp>
Classes | |
struct | EnumClassHash |
Public Types | |
using | This = Factory< KeyT, BaseT, HeldT > |
using | Creator = std::function< HeldT(Args...)> |
template<typename Key > | |
using | HashType = typename std::conditional< std::is_enum< Key >::value, EnumClassHash, std::hash< Key > >::type |
using | CreatorMap = std::unordered_map< KeyT, Creator, HashType< KeyT > > |
Public Member Functions | |
Factory ()=default | |
Default constructor. More... | |
virtual | ~Factory ()=default |
Destructor. More... | |
void | registerCreator (const KeyT &key, Creator creator) |
Registers a object creator function with a key. More... | |
template<typename Derived > | |
void | registerCreator (const KeyT &key) |
Registers the default object creator function with a key. More... | |
void | unregisterCreator (const KeyT &key) |
Unregisters the object creator function that is registered with a key. More... | |
void | unregisterAllCreators () |
Unregisters all the object creator functions. More... | |
bool | canCreate (const KeyT &key) |
Returns true if an object creator function is registered with the key. More... | |
HeldT | create (const KeyT &key, Args &&... args) |
Creates an object of the class that is registered with a key. More... | |
std::unordered_set< KeyT > | getKeys () const |
Get a set of the keys that are available for this Creator. More... | |
Static Private Member Functions | |
template<typename Derived > | |
static HeldT | defaultCreator (Args &&... args) |
Private Attributes | |
CreatorMap | mCreatorMap |
Object creator function map. More... | |
Implementation of the Abstract Factory Pattern.
Example:
using dart::common::Factory< KeyT, BaseT, HeldT, Args >::Creator = std::function<HeldT(Args...)> |
using dart::common::Factory< KeyT, BaseT, HeldT, Args >::CreatorMap = std::unordered_map<KeyT, Creator, HashType<KeyT> > |
using dart::common::Factory< KeyT, BaseT, HeldT, Args >::HashType = typename std::conditional< std::is_enum<Key>::value, EnumClassHash, std::hash<Key> >::type |
using dart::common::Factory< KeyT, BaseT, HeldT, Args >::This = Factory<KeyT, BaseT, HeldT> |
|
default |
Default constructor.
|
virtualdefault |
Destructor.
bool dart::common::Factory< KeyT, BaseT, HeldT, Args >::canCreate | ( | const KeyT & | key | ) |
Returns true if an object creator function is registered with the key.
Otherwise, returns false.
HeldT dart::common::Factory< KeyT, BaseT, HeldT, Args >::create | ( | const KeyT & | key, |
Args &&... | args | ||
) |
Creates an object of the class that is registered with a key.
Returns nullptr if there is no object creator function associated with the key.
|
staticprivate |
std::unordered_set< KeyT > dart::common::Factory< KeyT, BaseT, HeldT, Args >::getKeys |
Get a set of the keys that are available for this Creator.
void dart::common::Factory< KeyT, BaseT, HeldT, Args >::registerCreator | ( | const KeyT & | key | ) |
Registers the default object creator function with a key.
void dart::common::Factory< KeyT, BaseT, HeldT, Args >::registerCreator | ( | const KeyT & | key, |
Creator | creator | ||
) |
Registers a object creator function with a key.
void dart::common::Factory< KeyT, BaseT, HeldT, Args >::unregisterAllCreators |
Unregisters all the object creator functions.
void dart::common::Factory< KeyT, BaseT, HeldT, Args >::unregisterCreator | ( | const KeyT & | key | ) |
Unregisters the object creator function that is registered with a key.
Do nothing if there is no creator function associated with the key.
|
private |
Object creator function map.