Do not require the invocation of ::get() in Factory
Factory
is a singleton.
Currently, we access the unique instance with a static method get()
.
After that, we call other methods:
FactorySensor::get().registerCreator(...);
FactorySensor::get().create(...);
[...]
This issue proposes a cleaner API, as follows:
FactorySensor::registerCreator(...);
FactorySensor::create(...);
[...]
The idea is to make get()
private, and registerCreator()
, unregisterCreator()
, create()
static, which would internally invoke get()
to get access to the factory:
For example, the method create()
would be:
template<class TypeBase, typename... TypeInput>
class Factory
{
static TypeBasePtr create(const std::string& _type, TypeInput... _input);
{
typename CallbackMap::const_iterator creator_callback_it = get().callbacks_.find(_type); // <-- use get() here
if (creator_callback_it == get().callbacks_.end()) // <-- use get() here
// not found
throw std::runtime_error(get().getClass() // <-- use get() here
+ " : Unknown type \""
+ _type
+ "\". Possibly you tried to use an unregistered creator.");
// Invoke the creation function
return (creator_callback_it->second)(std::forward<TypeInput>(_input)...);
}
}