33 #ifndef DART_COMMON_FACTORY_HPP_ 34 #define DART_COMMON_FACTORY_HPP_ 38 #include <unordered_map> 39 #include <unordered_set> 41 #include "dart/common/Singleton.hpp" 42 #include "dart/common/StlHelpers.hpp" 60 typename HeldT = std::shared_ptr<BaseT>,
68 using Creator = std::function<HeldT(Args...)>;
69 template <
typename Key>
70 using HashType =
typename std::conditional<
71 std::is_enum<Key>::value,
73 std::hash<Key>>::type;
74 using CreatorMap = std::unordered_map<KeyT, Creator, HashType<KeyT>>;
86 template <
typename Derived>
102 HeldT
create(
const KeyT& key, Args&&... args);
107 std::unordered_set<KeyT>
getKeys()
const;
110 template <
typename Derived>
111 static HeldT defaultCreator(Args&&... args);
114 CreatorMap mCreatorMap;
122 typename HeldT = std::shared_ptr<BaseT>,
130 using Creator =
typename FactoryType::Creator;
144 #include "dart/common/detail/Factory-impl.hpp" 146 #endif // DART_COMMON_FACTORY_HPP_ Helper class to register a object creator function to the Singleton.
Definition: Factory.hpp:124
bool canCreate(const KeyT &key)
Returns true if an object creator function is registered with the key.
Definition: Factory-impl.hpp:125
Factory()=default
Default constructor.
Definition: Aspect.cpp:40
void unregisterAllCreators()
Unregisters all the object creator functions.
Definition: Factory-impl.hpp:118
std::unordered_set< KeyT > getKeys() const
Get a set of the keys that are available for this Creator.
Definition: Factory-impl.hpp:155
Definition: Factory-impl.hpp:84
Singleton template class.
Definition: Singleton.hpp:50
virtual ~Factory()=default
Destructor.
Implementation of the Abstract Factory Pattern.
Definition: Factory.hpp:62
void registerCreator(const KeyT &key, Creator creator)
Registers a object creator function with a key.
Definition: Factory-impl.hpp:95
HeldT create(const KeyT &key, Args &&... args)
Creates an object of the class that is registered with a key.
Definition: Factory-impl.hpp:134
void unregisterCreator(const KeyT &key)
Unregisters the object creator function that is registered with a key.
Definition: Factory-impl.hpp:111