BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
mumufit::test::IFactory< Key, AbstractProduct > Class Template Reference

Base class for all factories. More...

Public Types

typedef std::map< Key, CreateItemCallbackCallbackMap_t
 map for correspondence between object identifier and object creation function More...
 
typedef std::function< AbstractProduct *()> CreateItemCallback
 function which will be used to create object of AbstractProduct base type More...
 

Public Member Functions

bool contains (const Key &item_key) const
 
AbstractProduct * createItem (const Key &item_key) const
 Creates object by calling creation function corresponded to given identifier. More...
 
std::unique_ptr< AbstractProduct > createItemPtr (const Key &item_key) const
 
bool registerItem (const Key &item_key, CreateItemCallback CreateFn)
 Registers object's creation function. More...
 
size_t size () const
 Returns number of registered objects. More...
 

Protected Attributes

CallbackMap_t m_callbacks
 map of correspondence of objectsId and creation functions More...
 

Detailed Description

template<class Key, class AbstractProduct>
class mumufit::test::IFactory< Key, AbstractProduct >

Base class for all factories.

Definition at line 35 of file IFactory.h.

Member Typedef Documentation

◆ CallbackMap_t

template<class Key , class AbstractProduct >
typedef std::map<Key, CreateItemCallback> mumufit::test::IFactory< Key, AbstractProduct >::CallbackMap_t

map for correspondence between object identifier and object creation function

Definition at line 41 of file IFactory.h.

◆ CreateItemCallback

template<class Key , class AbstractProduct >
typedef std::function<AbstractProduct*()> mumufit::test::IFactory< Key, AbstractProduct >::CreateItemCallback

function which will be used to create object of AbstractProduct base type

Definition at line 38 of file IFactory.h.

Member Function Documentation

◆ contains()

template<class Key , class AbstractProduct >
bool mumufit::test::IFactory< Key, AbstractProduct >::contains ( const Key &  item_key) const
inline

Definition at line 65 of file IFactory.h.

66  {
67  return m_callbacks.find(item_key) != m_callbacks.end();
68  }
CallbackMap_t m_callbacks
map of correspondence of objectsId and creation functions
Definition: IFactory.h:74

References mumufit::test::IFactory< Key, AbstractProduct >::m_callbacks.

◆ createItem()

template<class Key , class AbstractProduct >
AbstractProduct* mumufit::test::IFactory< Key, AbstractProduct >::createItem ( const Key &  item_key) const
inline

Creates object by calling creation function corresponded to given identifier.

Definition at line 44 of file IFactory.h.

45  {
46  auto it = m_callbacks.find(item_key);
47  assert(it != m_callbacks.end());
48  return (it->second)();
49  }

References mumufit::test::IFactory< Key, AbstractProduct >::m_callbacks.

Referenced by mumufit::test::IFactory< Key, AbstractProduct >::createItemPtr().

◆ createItemPtr()

template<class Key , class AbstractProduct >
std::unique_ptr<AbstractProduct> mumufit::test::IFactory< Key, AbstractProduct >::createItemPtr ( const Key &  item_key) const
inline

Definition at line 52 of file IFactory.h.

53  {
54  return std::unique_ptr<AbstractProduct>{createItem(item_key)};
55  }
AbstractProduct * createItem(const Key &item_key) const
Creates object by calling creation function corresponded to given identifier.
Definition: IFactory.h:44

References mumufit::test::IFactory< Key, AbstractProduct >::createItem().

Here is the call graph for this function:

◆ registerItem()

template<class Key , class AbstractProduct >
bool mumufit::test::IFactory< Key, AbstractProduct >::registerItem ( const Key &  item_key,
CreateItemCallback  CreateFn 
)
inline

Registers object's creation function.

Definition at line 59 of file IFactory.h.

60  {
61  assert(m_callbacks.find(item_key) == m_callbacks.end());
62  return m_callbacks.insert(make_pair(item_key, CreateFn)).second;
63  }

References mumufit::test::IFactory< Key, AbstractProduct >::m_callbacks.

◆ size()

template<class Key , class AbstractProduct >
size_t mumufit::test::IFactory< Key, AbstractProduct >::size ( ) const
inline

Returns number of registered objects.

Definition at line 71 of file IFactory.h.

71 { return m_callbacks.size(); }

References mumufit::test::IFactory< Key, AbstractProduct >::m_callbacks.

Member Data Documentation

◆ m_callbacks

template<class Key , class AbstractProduct >
CallbackMap_t mumufit::test::IFactory< Key, AbstractProduct >::m_callbacks
protected

The documentation for this class was generated from the following file: