33 #ifndef DART_COMMON_FACTORY_HPP_
34 #define DART_COMMON_FACTORY_HPP_
37 #include <unordered_map>
39 #include <unordered_set>
57 template <
typename KeyT,
59 typename HeldT = std::shared_ptr<BaseT>,
67 using Creator = std::function<HeldT(Args...)>;
68 template <
typename Key>
71 using CreatorMap = std::unordered_map<KeyT, Creator, HashType<KeyT>>;
83 template <
typename Derived>
99 HeldT
create(
const KeyT& key, Args&&... args);
104 std::unordered_set<KeyT>
getKeys()
const;
107 template <
typename Derived>
115 template <
typename KeyT,
118 typename HeldT = std::shared_ptr<BaseT>,
std::string type
Definition: SdfParser.cpp:82
Helper class to register a object creator function to the Singleton.
Definition: Factory.hpp:121
FactoryRegistrar(const KeyT &key, Creator creator)
Constructor.
Definition: Factory-impl.hpp:212
typename FactoryType::Creator Creator
Definition: Factory.hpp:126
Implementation of the Abstract Factory Pattern.
Definition: Factory.hpp:62
std::unordered_set< KeyT > getKeys() const
Get a set of the keys that are available for this Creator.
Definition: Factory-impl.hpp:184
std::unordered_map< KeyT, Creator, HashType< KeyT > > CreatorMap
Definition: Factory.hpp:71
bool canCreate(const KeyT &key)
Returns true if an object creator function is registered with the key.
Definition: Factory-impl.hpp:148
std::function< HeldT(Args...)> Creator
Definition: Factory.hpp:67
Factory()=default
Default constructor.
HeldT create(const KeyT &key, Args &&... args)
Creates an object of the class that is registered with a key.
Definition: Factory-impl.hpp:160
void registerCreator(const KeyT &key, Creator creator)
Registers a object creator function with a key.
Definition: Factory-impl.hpp:101
void unregisterCreator(const KeyT &key)
Unregisters the object creator function that is registered with a key.
Definition: Factory-impl.hpp:127
static HeldT defaultCreator(Args &&... args)
Definition: Factory-impl.hpp:199
virtual ~Factory()=default
Destructor.
typename std::conditional< std::is_enum< Key >::value, EnumClassHash, std::hash< Key > >::type HashType
Definition: Factory.hpp:70
void unregisterAllCreators()
Unregisters all the object creator functions.
Definition: Factory-impl.hpp:138
CreatorMap mCreatorMap
Object creator function map.
Definition: Factory.hpp:111
Singleton template class.
Definition: Singleton.hpp:51
Definition: BulletCollisionDetector.cpp:63
Definition: Factory-impl.hpp:88