BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
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 IFactory< Key, AbstractProduct >

Base class for all factories.

Definition at line 29 of file IFactory.h.

Member Typedef Documentation

◆ CallbackMap_t

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

map for correspondence between object identifier and object creation function

Definition at line 35 of file IFactory.h.

◆ 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.

Member Function Documentation

◆ 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  }
CallbackMap_t m_callbacks
map of correspondence of objectsId and creation functions
Definition: IFactory.h:68

References IFactory< Key, AbstractProduct >::m_callbacks.

Referenced by ItemCatalog::createItemPtr().

◆ 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  }

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().

Referenced by ItemCatalog::createItemPtr(), and ItemComboWidget::setPresentation().

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.

Referenced by ItemCatalog::add(), and ItemComboWidget::registerWidget().

◆ 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: