13#include <boost/format.hpp>
20template <
typename Key,
typename Val>
21struct key_not_found : uhd::key_error
23 key_not_found(
const Key& key)
24 : uhd::key_error(boost::str(boost::format(
"key \"%s\" not found in dict(%s, %s)")
25 % uhd::cast::
to_str(key) % typeid(Key).name()
26 % typeid(Val).name()))
33template <
typename Key,
typename Val>
39template <
typename Key,
typename Val>
40template <
typename InputIterator>
46template <
typename Key,
typename Val>
52template <
typename Key,
typename Val>
58template <
typename Key,
typename Val>
61 std::vector<Key>
keys;
62 for (
const pair_t& p : _map) {
63 keys.push_back(p.first);
68template <
typename Key,
typename Val>
71 std::vector<Val>
vals;
72 for (
const pair_t& p : _map) {
73 vals.push_back(p.second);
78template <
typename Key,
typename Val>
81 for (
const pair_t& p : _map) {
88template <
typename Key,
typename Val>
91 for (
const pair_t& p : _map) {
98template <
typename Key,
typename Val>
101 for (
const pair_t& p : _map) {
105 throw key_not_found<Key, Val>(key);
108template <
typename Key,
typename Val>
114template <
typename Key,
typename Val>
117 for (
const pair_t& p : _map) {
121 throw key_not_found<Key, Val>(key);
124template <
typename Key,
typename Val>
127 for (pair_t& p : _map) {
131 _map.push_back(std::make_pair(key, Val()));
132 return _map.back().second;
135template <
typename Key,
typename Val>
141 for (
const pair_t& p : _map) {
142 if (not(other.
has_key(p.first) and other.
get(p.first) == p.second)) {
149template <
typename Key,
typename Val>
152 return not(*
this == other);
155template <
typename Key,
typename Val>
158 typename std::list<pair_t>::iterator it;
159 for (it = _map.begin(); it != _map.end(); it++) {
160 if (it->first == key) {
161 Val val = it->second;
166 throw key_not_found<Key, Val>(key);
169template <
typename Key,
typename Val>
172 for (
const Key& key : new_dict.
keys()) {
173 if (fail_on_conflict and
has_key(key) and
get(key) != new_dict[key]) {
175 str(boost::format(
"Option merge conflict: %s:%s != %s:%s") % key
176 %
get(key) % key % new_dict[key]));
178 set(key, new_dict[key]);
182template <
typename Key,
typename Val>
185 std::map<Key, Val> new_map;
186 for (
const pair_t& p : _map) {
187 new_map[p.first] = p.second;
std::vector< Key > keys(void) const
Definition dict.ipp:59
std::vector< Val > vals(void) const
Definition dict.ipp:69
bool operator==(const dict< Key, Val > &other) const
Definition dict.ipp:136
void update(const dict< Key, Val > &new_dict, bool fail_on_conflict=true)
Definition dict.ipp:170
const Val & operator[](const Key &key) const
Definition dict.ipp:115
std::size_t size(void) const
Definition dict.ipp:53
bool operator!=(const dict< Key, Val > &other) const
Definition dict.ipp:150
bool has_key(const Key &key) const
Definition dict.ipp:79
dict(void)
Definition dict.ipp:34
const Val & get(const Key &key, const Val &other) const
Definition dict.ipp:89
Val pop(const Key &key)
Definition dict.ipp:156
void set(const Key &key, const Val &val)
Definition dict.ipp:109
auto to_str(const T &val) -> std::enable_if_t< std::is_arithmetic_v< T > &&!std::is_floating_point_v< T > &&!std::is_same_v< T, int8_t > &&!std::is_same_v< T, uint8_t > &&!std::is_enum_v< T > &&!detail::has_to_string_method< T >::value, decltype(std::to_string(val))>
SFINAE-based template for integer types that std::to_string can handle.
Definition cast.hpp:167
Definition build_info.hpp:12
Definition exception.hpp:108