15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_UTILS_IFACTORY_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_UTILS_IFACTORY_H
28 template <
class Key,
class Value>
class IFactory {
30 using function_t = std::function<std::unique_ptr<Value>()>;
31 using map_t = std::map<Key, function_t>;
35 std::unique_ptr<Value>
create(
const Key& item_key)
const
37 auto it =
m_data.find(item_key);
39 std::ostringstream message;
40 message <<
"IFactory::createItem() -> Error. Unknown item key '" << item_key <<
"'";
41 throw std::runtime_error(message.str());
49 std::ostringstream message;
50 message <<
"IFactory::createItem() -> Already registered item key '" << key <<
"'";
51 throw std::runtime_error(message.str());
53 return m_data.insert(make_pair(key, func)).second;
59 typename map_t::iterator
end() {
return m_data.end(); }
std::function< std::unique_ptr< Value >()> function_t
bool contains(const Key &item_key) const
std::map< Key, function_t > map_t
bool add(const Key &key, function_t func)
std::unique_ptr< Value > create(const Key &item_key) const
materialitems.h Collection of materials to populate MaterialModel.