16 #error no need to expose this header to Swig
20 #ifndef BORNAGAIN_FIT_TESTENGINE_IFACTORY_H
21 #define BORNAGAIN_FIT_TESTENGINE_IFACTORY_H
35 template <
class Key,
class AbstractProduct>
class IFactory {
48 return (it->second)();
52 std::unique_ptr<AbstractProduct>
createItemPtr(
const Key& item_key)
const
54 return std::unique_ptr<AbstractProduct>{
createItem(item_key)};
62 return m_callbacks.insert(make_pair(item_key, CreateFn)).second;
Base class for all factories.
std::map< Key, CreateItemCallback > CallbackMap_t
map for correspondence between object identifier and object creation function
size_t size() const
Returns number of registered objects.
std::function< AbstractProduct *()> CreateItemCallback
function which will be used to create object of AbstractProduct base type
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.
AbstractProduct * createItem(const Key &item_key) const
Creates object by calling creation function corresponded to given identifier.
std::unique_ptr< AbstractProduct > createItemPtr(const Key &item_key) const
bool contains(const Key &item_key) const
T * create_new()
Returns new instance of class T.