7#include "xtensor-python/pyarray.hpp"
8#include "xtensor/io/xio.hpp"
25 template <
class K,
class T>
36 using pointer =
typename base_type::pointer;
43 using base_type::empty;
44 using base_type::find;
45 using base_type::emplace;
47 using base_type::begin;
49 using base_type::cbegin;
50 using base_type::cend;
63 template <
class K,
class T>
66 template <
class K,
class T>
77 xt::pyarray<T>&
array(
const std::string& key);
84 template <
class D1,
class D2>
85 typename D1::mapped_type& find_element(
const std::string& key,
88 const std::string& expected_type,
89 const std::string& other_type);
92 std::string get_additional_error_msg(
const std::string& key,
94 const std::string& asked_type,
95 const std::string& tried_type)
const;
112 return std::string(
"key ") + key + std::string(
" not found");
116 template <
class K,
class T>
119 auto it = this->find(k);
127 template <
class K,
class T>
130 return base_type::insert(std::move(
v));
133 template <
class K,
class T>
136 auto it = base_type::find(k);
137 if(it == base_type::end())
139 return base_type::emplace(k, std::move(
v));
143 it->second = std::move(
v);
144 return std::make_pair(it,
false);
155 return find_element(key,
m_darray,
m_iarray,
"pyarray<double>",
"pyarray<int>");
161 return find_element(key,
m_iarray,
m_darray,
"pyarray<int>",
"pyarray<double>");
176 template <
class D1,
class D2>
177 typename D1::mapped_type& arguments_dict::find_element(
const std::string& key,
179 const D2& other_dict,
180 const std::string& expected_type,
181 const std::string& other_type)
185 return expected_dict[key];
187 catch(std::runtime_error& e)
189 throw std::runtime_error(e.what()
190 + get_additional_error_msg(key, other_dict, expected_type, other_type));
195 std::string arguments_dict::get_additional_error_msg(
const std::string& key,
197 const std::string& asked_type,
198 const std::string& tried_type)
const
200 auto it = d.find(key);
203 return " in any of the internal dicts";
207 return " in dict of " + asked_type +
" but found in dict of " + tried_type;
std::pair< iterator, bool > insert_or_assign(key_type &&k, mapped_type &&v)
typename base_type::value_type value_type
std::map< K, T > base_type
typename base_type::iterator iterator
typename base_type::mapped_type mapped_type
typename base_type::pointer pointer
mapped_type & operator[](const key_type &k)
typename base_type::const_pointer const_pointer
typename base_type::const_iterator const_iterator
typename base_type::key_type key_type
typename base_type::difference_type difference_type
typename base_type::reference reference
typename base_type::size_type size_type
typename base_type::const_reference const_reference
std::pair< iterator, bool > insert(value_type &&)
std::string key_error_messagei(const T &key)
std::string key_error_message(const std::string &key)
throwing_map< K, T > scalar_dict
throwing_map< K, xt::pyarray< T > > pyarray_dict
T & scalar(const std::string &key)
pyarray_dict< std::string, double > m_darray
scalar_dict< std::string, int > m_iscalar
xt::pyarray< T > & array(const std::string &key)
pyarray_dict< std::string, int > m_iarray
scalar_dict< std::string, double > m_dscalar