diff options
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/types/dict.hpp | 18 | ||||
-rw-r--r-- | host/include/uhd/types/dict.ipp | 17 |
2 files changed, 31 insertions, 4 deletions
diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index a117efa6b..d0ca36512 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -73,10 +73,24 @@ namespace uhd{ /*! * Get a value in the dict or default. * \param key the key to look for - * \param def use if key not found + * \param other use if key not found * \return the value or default */ - const Val &get(const Key &key, const Val &def) const; + const Val &get(const Key &key, const Val &other) const; + + /*! + * Get a value in the dict or throw. + * \param key the key to look for + * \return the value or default + */ + const Val &get(const Key &key) const; + + /*! + * Set a value in the dict at the key. + * \param key the key to set at + * \param val the value to set + */ + void set(const Key &key, const Val &val); /*! * Get a value for the given key if it exists. diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index efff9e955..cd64594e1 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -85,11 +85,24 @@ namespace uhd{ } template <typename Key, typename Val> - const Val &dict<Key, Val>::get(const Key &key, const Val &def) const{ + const Val &dict<Key, Val>::get(const Key &key, const Val &other) const{ BOOST_FOREACH(const pair_t &p, _map){ if (p.first == key) return p.second; } - return def; + return other; + } + + template <typename Key, typename Val> + const Val &dict<Key, Val>::get(const Key &key) const{ + BOOST_FOREACH(const pair_t &p, _map){ + if (p.first == key) return p.second; + } + throw key_not_found<Key, Val>(key); + } + + template <typename Key, typename Val> + void dict<Key, Val>::set(const Key &key, const Val &val){ + (*this)[key] = val; } template <typename Key, typename Val> |