28#include <unordered_map>
61 template <
class RegisteredType,
class KeyType = std::
string,
class =
void>
84 static const RegisteredType&
85 get(
const KeyType& key)
87 std::lock_guard<std::recursive_mutex> guard{registeredElementsMutex()};
90 throw std::invalid_argument{
"No factory for this key! "};
92 return registeredElements().at(key);
96 has(
const KeyType& key)
98 std::lock_guard<std::recursive_mutex> guard{registeredElementsMutex()};
99 return registeredElements().end() != registeredElements().find(key);
110 std::lock_guard<std::recursive_mutex> guard{registeredElementsMutex()};
111 registeredElements()[key] = std::move(element);
118 static std::vector<KeyType>
121 std::lock_guard<std::recursive_mutex> guard{registeredElementsMutex()};
122 std::vector<KeyType> result;
123 result.reserve(registeredElements().size());
124 for (
const auto& elem : registeredElements())
126 result.emplace_back(elem.first);
136 static ContainerType&
139 static ContainerType elementContainer;
140 return elementContainer;
143 static std::recursive_mutex&
144 registeredElementsMutex()
146 static std::recursive_mutex elementContainerMutex;
147 return elementContainerMutex;
static bool has(const KeyType &key)
static const RegisteredType & get(const KeyType &key)
Returns the registered object for the given key.
static std::vector< KeyType > getKeys()
Retrieves the list of all registered elements.
std::unordered_map< std::string, ComponentCreatorObject > ContainerType
static void registerElement(const KeyType &key, RegisteredType element)
Registers an element.
This file offers overloads of toIce() and fromIce() functions for STL container types.
RegisterElement(const KeyType &key, RegisteredType element)