BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IFactory< Key, AbstractProduct > Class Template Reference
Collaboration diagram for IFactory< Key, AbstractProduct >:

Public Types

typedef std::function< AbstractProduct *()> CreateItemCallback
 
typedef std::map< Key, CreateItemCallbackCallbackMap_t
 

Public Member Functions

AbstractProduct * createItem (const Key &item_key) const
 
std::unique_ptr< AbstractProduct > createItemPtr (const Key &item_key) const
 
bool registerItem (const Key &item_key, CreateItemCallback CreateFn)
 
bool contains (const Key &item_key) const
 
size_t size () const
 

Protected Attributes

CallbackMap_t m_callbacks
 

Detailed Description

template<class Key, class AbstractProduct>
class IFactory< Key, AbstractProduct >

Base class for all factories.

Definition at line 28 of file IFactory.h.

Member Typedef Documentation

◆ CreateItemCallback

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

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

Definition at line 32 of file IFactory.h.

◆ CallbackMap_t

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

map for correspondance between object identifier and object creation function

Definition at line 35 of file IFactory.h.

Member Function Documentation

◆ createItem()

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

Creates object by calling creation function corresponded to given identifier.

Definition at line 38 of file IFactory.h.

39  {
40  auto it = m_callbacks.find(item_key);
41  assert(it != m_callbacks.end());
42  return (it->second)();
43  }
CallbackMap_t m_callbacks
map of correspondence of objectsId and creation functions
Definition: IFactory.h:68

References IFactory< Key, AbstractProduct >::m_callbacks.

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

◆ createItemPtr()

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

Definition at line 46 of file IFactory.h.

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

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

Here is the call graph for this function:

◆ registerItem()

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

Registers object's creation function.

Definition at line 53 of file IFactory.h.

54  {
55  assert(m_callbacks.find(item_key) == m_callbacks.end());
56  return m_callbacks.insert(make_pair(item_key, CreateFn)).second;
57  }

References IFactory< Key, AbstractProduct >::m_callbacks.

◆ contains()

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

Definition at line 59 of file IFactory.h.

60  {
61  return m_callbacks.find(item_key) != m_callbacks.end();
62  }

References IFactory< Key, AbstractProduct >::m_callbacks.

◆ size()

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

Returns number of registered objects.

Definition at line 65 of file IFactory.h.

65 { return m_callbacks.size(); }

References IFactory< Key, AbstractProduct >::m_callbacks.

Member Data Documentation

◆ m_callbacks

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

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