15 #ifndef BORNAGAIN_FIT_TESTENGINE_IFACTORY_H
16 #define BORNAGAIN_FIT_TESTENGINE_IFACTORY_H
28 template <
class Key,
class AbstractProduct>
class IFactory
42 return (it->second)();
46 std::unique_ptr<AbstractProduct> createItemPtr(
const Key& item_key)
const
48 return std::unique_ptr<AbstractProduct>{
createItem(item_key)};
56 return m_callbacks.insert(make_pair(item_key, CreateFn)).second;
59 bool contains(
const Key& item_key)
const
T * create_new()
Returns new instance of class T.
Base class for all factories.
AbstractProduct * createItem(const Key &item_key) const
Creates object by calling creation function corresponded to given identifier.
std::function< AbstractProduct *()> CreateItemCallback
function which will be used to create object of AbstractProduct base type
std::map< Key, CreateItemCallback > CallbackMap_t
map for correspondance between object identifier and object creation function
size_t size() const
Returns number of registered objects.
CallbackMap_t m_callbacks
map of correspondence of objectsId and creation functions
bool registerItem(const Key &item_key, CreateItemCallback CreateFn)
Registers object's creation function.