summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-05 17:16:11 -0800
committerJosh Blum <josh@joshknows.com>2011-01-05 17:16:11 -0800
commit3db629e5a579bd50f317eadb7895fa2ce088812e (patch)
tree59d9fc2f160aa8f2236016b4acaf37a792c653db /host
parentbe19cfe964ace757aebb19d242807e647e12c0fa (diff)
downloaduhd-3db629e5a579bd50f317eadb7895fa2ce088812e.tar.gz
uhd-3db629e5a579bd50f317eadb7895fa2ce088812e.tar.bz2
uhd-3db629e5a579bd50f317eadb7895fa2ce088812e.zip
uhd: added get and set methods to dictionary to make swigging it easier
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/types/dict.hpp18
-rw-r--r--host/include/uhd/types/dict.ipp17
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>