From 3db629e5a579bd50f317eadb7895fa2ce088812e Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Wed, 5 Jan 2011 17:16:11 -0800
Subject: uhd: added get and set methods to dictionary to make swigging it
 easier

---
 host/include/uhd/types/dict.hpp | 18 ++++++++++++++++--
 host/include/uhd/types/dict.ipp | 17 +++++++++++++++--
 2 files changed, 31 insertions(+), 4 deletions(-)

(limited to 'host/include')

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>
-- 
cgit v1.2.3