diff options
author | Josh Blum <josh@joshknows.com> | 2010-10-31 11:04:42 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-10-31 11:04:42 -0700 |
commit | cb4e30ec501aa201c0ca5d2676f2d568ae24356b (patch) | |
tree | 88e0fc7878338a96e83f2d5ff5fc23dcb05f04eb /host | |
parent | a8d2c2944b329218af1c0b171b92f775b679b409 (diff) | |
download | uhd-cb4e30ec501aa201c0ca5d2676f2d568ae24356b.tar.gz uhd-cb4e30ec501aa201c0ca5d2676f2d568ae24356b.tar.bz2 uhd-cb4e30ec501aa201c0ca5d2676f2d568ae24356b.zip |
uhd: added dict get method, used in usrp1 image loading
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/types/dict.hpp | 8 | ||||
-rw-r--r-- | host/include/uhd/types/dict.ipp | 8 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/usrp1_impl.cpp | 6 |
3 files changed, 18 insertions, 4 deletions
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 @@ -71,6 +71,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. * \param key the key to look for 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 @@ -86,6 +86,14 @@ namespace uhd{ } 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){ if (p.first == key) return p.second; diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 314384e72..bc478c7fb 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -59,9 +59,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) //extract the firmware path for the USRP1 std::string usrp1_fw_image; try{ - usrp1_fw_image = find_image_path( - hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx" - ); + usrp1_fw_image = find_image_path(hint.get("fw", "usrp1_fw.ihx")); } catch(...){ uhd::warning::post( @@ -110,7 +108,7 @@ static device::sptr usrp1_make(const device_addr_t &device_addr){ //extract the FPGA path for the USRP1 std::string usrp1_fpga_image = find_image_path( - device_addr.has_key("fpga")? device_addr["fpga"] : "usrp1_fpga.rbf" + device_addr.get("fpga", "usrp1_fpga.rbf") ); //std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl; |