From cb4e30ec501aa201c0ca5d2676f2d568ae24356b Mon Sep 17 00:00:00 2001 From: Josh Blum <josh@joshknows.com> Date: Sun, 31 Oct 2010 11:04:42 -0700 Subject: uhd: added dict get method, used in usrp1 image loading --- host/include/uhd/types/dict.hpp | 8 ++++++++ host/include/uhd/types/dict.ipp | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index b14fc5425..6166140a0 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -70,6 +70,14 @@ namespace uhd{ */ bool has_key(const Key &key) const; + /*! + * Get a value in the dict or default. + * \param key the key to look for + * \param def use if key not found + * \return the value or default + */ + const Val &get(const Key &key, const Val &def) const; + /*! * Get a value for the given key if it exists. * If the key is not found throw an error. diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index 85071e6fd..4aab5de45 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -85,6 +85,14 @@ namespace uhd{ return false; } + template <typename Key, typename Val> + const Val &dict<Key, Val>::get(const Key &key, const Val &def) const{ + BOOST_FOREACH(const pair_t &p, _map){ + if (p.first == key) return p.second; + } + return def; + } + template <typename Key, typename Val> const Val &dict<Key, Val>::operator[](const Key &key) const{ BOOST_FOREACH(const pair_t &p, _map){ -- cgit v1.2.3