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

Base for factories. More...

Public Types

using function_t = std::function< std::unique_ptr< Value >()>
 
using map_t = std::map< Key, function_t >
 

Public Member Functions

bool add (const Key &key, function_t func)
 
map_t::iterator begin ()
 
bool contains (const Key &item_key) const
 
std::unique_ptr< Value > create (const Key &item_key) const
 
map_t::iterator end ()
 
size_t size () const
 

Private Attributes

map_t m_data
 

Detailed Description

template<class Key, class Value>
class ModelView::IFactory< Key, Value >

Base for factories.

Definition at line 28 of file ifactory.h.

Member Typedef Documentation

◆ function_t

template<class Key , class Value >
using ModelView::IFactory< Key, Value >::function_t = std::function<std::unique_ptr<Value>()>

Definition at line 30 of file ifactory.h.

◆ map_t

template<class Key , class Value >
using ModelView::IFactory< Key, Value >::map_t = std::map<Key, function_t>

Definition at line 31 of file ifactory.h.

Member Function Documentation

◆ add()

template<class Key , class Value >
bool ModelView::IFactory< Key, Value >::add ( const Key &  key,
function_t  func 
)
inline

Definition at line 46 of file ifactory.h.

47  {
48  if (m_data.find(key) != m_data.end()) {
49  std::ostringstream message;
50  message << "IFactory::createItem() -> Already registered item key '" << key << "'";
51  throw std::runtime_error(message.str());
52  }
53  return m_data.insert(make_pair(key, func)).second;
54  }

References ModelView::IFactory< Key, Value >::m_data.

◆ begin()

template<class Key , class Value >
map_t::iterator ModelView::IFactory< Key, Value >::begin ( )
inline

Definition at line 58 of file ifactory.h.

58 { return m_data.begin(); }

References ModelView::IFactory< Key, Value >::m_data.

◆ contains()

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

Definition at line 33 of file ifactory.h.

33 { return m_data.find(item_key) != m_data.end(); }

References ModelView::IFactory< Key, Value >::m_data.

◆ create()

template<class Key , class Value >
std::unique_ptr<Value> ModelView::IFactory< Key, Value >::create ( const Key &  item_key) const
inline

Definition at line 35 of file ifactory.h.

36  {
37  auto it = m_data.find(item_key);
38  if (it == m_data.end()) {
39  std::ostringstream message;
40  message << "IFactory::createItem() -> Error. Unknown item key '" << item_key << "'";
41  throw std::runtime_error(message.str());
42  }
43  return it->second();
44  }

References ModelView::IFactory< Key, Value >::m_data.

◆ end()

template<class Key , class Value >
map_t::iterator ModelView::IFactory< Key, Value >::end ( )
inline

Definition at line 59 of file ifactory.h.

59 { return m_data.end(); }

References ModelView::IFactory< Key, Value >::m_data.

◆ size()

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

Definition at line 56 of file ifactory.h.

56 { return m_data.size(); }

References ModelView::IFactory< Key, Value >::m_data.

Member Data Documentation

◆ m_data


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