8#ifndef INCLUDED_UHD_TYPES_DICT_IPP
9#define INCLUDED_UHD_TYPES_DICT_IPP
12#include <boost/foreach.hpp>
13#include <boost/format.hpp>
14#include <boost/lexical_cast.hpp>
20 template<
typename Key,
typename Val>
24 "key \"%s\" not found in dict(%s, %s)"
25 ) % boost::lexical_cast<std::string>(key)
26 %
typeid(Key).name() %
typeid(Val).name()
34 template <
typename Key,
typename Val>
39 template <
typename Key,
typename Val>
template <
typename InputIterator>
46 template <
typename Key,
typename Val>
51 template <
typename Key,
typename Val>
53 std::vector<Key> keys;
54 BOOST_FOREACH(
const pair_t &p, _map){
55 keys.push_back(p.first);
60 template <
typename Key,
typename Val>
62 std::vector<Val> vals;
63 BOOST_FOREACH(
const pair_t &p, _map){
64 vals.push_back(p.second);
69 template <
typename Key,
typename Val>
71 BOOST_FOREACH(
const pair_t &p, _map){
72 if (p.first == key)
return true;
77 template <
typename Key,
typename Val>
79 BOOST_FOREACH(
const pair_t &p, _map){
80 if (p.first == key)
return p.second;
85 template <
typename Key,
typename Val>
87 BOOST_FOREACH(
const pair_t &p, _map){
88 if (p.first == key)
return p.second;
90 throw key_not_found<Key, Val>(key);
93 template <
typename Key,
typename Val>
98 template <
typename Key,
typename Val>
100 BOOST_FOREACH(
const pair_t &p, _map){
101 if (p.first == key)
return p.second;
103 throw key_not_found<Key, Val>(key);
106 template <
typename Key,
typename Val>
108 BOOST_FOREACH(pair_t &p, _map){
109 if (p.first == key)
return p.second;
111 _map.push_back(std::make_pair(key, Val()));
112 return _map.back().second;
115 template <
typename Key,
typename Val>
117 if (this->size() != other.
size()){
120 BOOST_FOREACH(
const pair_t& p, _map) {
121 if (not (other.
has_key(p.first) and other.
get(p.first) == p.second)){
128 template <
typename Key,
typename Val>
130 return not (*
this == other);
133 template <
typename Key,
typename Val>
135 typename std::list<pair_t>::iterator it;
136 for (it = _map.begin(); it != _map.end(); it++){
137 if (it->first == key){
138 Val val = it->second;
143 throw key_not_found<Key, Val>(key);
146 template <
typename Key,
typename Val>
149 BOOST_FOREACH(
const Key &key, new_dict.
keys()) {
150 if (fail_on_conflict and has_key(key) and get(key) != new_dict[key]) {
152 boost::format(
"Option merge conflict: %s:%s != %s:%s")
153 % key % get(key) % key % new_dict[key]
156 set(key, new_dict[key]);
160 template <
typename Key,
typename Val>
163 std::map<Key, Val> new_map;
164 BOOST_FOREACH (
const pair_t& p, _map) {
165 new_map[p.first] = p.second;
std::vector< Key > keys(void) const
Definition dict.ipp:52
std::vector< Val > vals(void) const
Definition dict.ipp:61
bool operator==(const dict< Key, Val > &other) const
Definition dict.ipp:116
void update(const dict< Key, Val > &new_dict, bool fail_on_conflict=true)
Definition dict.ipp:147
const Val & operator[](const Key &key) const
Definition dict.ipp:99
std::size_t size(void) const
Definition dict.ipp:47
bool operator!=(const dict< Key, Val > &other) const
Definition dict.ipp:129
bool has_key(const Key &key) const
Definition dict.ipp:70
dict(void)
Definition dict.ipp:35
const Val & get(const Key &key, const Val &other) const
Definition dict.ipp:78
Val pop(const Key &key)
Definition dict.ipp:134
void set(const Key &key, const Val &val)
Definition dict.ipp:94
Definition build_info.hpp:13
Definition exception.hpp:84
Definition exception.hpp:110