aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2018-03-29 18:42:39 -0700
committerMartin Braun <martin.braun@ettus.com>2018-04-02 13:38:45 -0700
commit3f0e7d405f128e9faeea03cb6f97f25423983e63 (patch)
treeb2edb1fe8ad3e6161e300174faa873baa935689a
parent6038a7af68451639f48dc75e1f3939bf975118ed (diff)
downloaduhd-3f0e7d405f128e9faeea03cb6f97f25423983e63.tar.gz
uhd-3f0e7d405f128e9faeea03cb6f97f25423983e63.tar.bz2
uhd-3f0e7d405f128e9faeea03cb6f97f25423983e63.zip
lib: adding device_addr_t constructor from map
Adding constructor for device_addr_t that takes a map<string, string> as an argument.
-rw-r--r--host/include/uhd/types/device_addr.hpp7
-rw-r--r--host/lib/types/device_addr.cpp6
-rw-r--r--host/tests/addr_test.cpp9
3 files changed, 22 insertions, 0 deletions
diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp
index dd60df2e7..b9d3659c0 100644
--- a/host/include/uhd/types/device_addr.hpp
+++ b/host/include/uhd/types/device_addr.hpp
@@ -14,6 +14,7 @@
#include <stdexcept>
#include <vector>
#include <string>
+#include <map>
namespace uhd{
@@ -43,6 +44,12 @@ namespace uhd{
device_addr_t(const std::string &args = "");
/*!
+ * Create a device address from a std::map
+ * \param info the device info map
+ */
+ device_addr_t(const std::map<std::string, std::string> &info);
+
+ /*!
* Convert a device address into a pretty print string.
* \return a printable string representing the device address
*/
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
index 18376a8b8..65d265857 100644
--- a/host/lib/types/device_addr.cpp
+++ b/host/lib/types/device_addr.cpp
@@ -41,6 +41,12 @@ device_addr_t::device_addr_t(const std::string &args){
}
}
+device_addr_t::device_addr_t(const std::map<std::string, std::string> &info) {
+ for (auto& t : info) {
+ this->set(t.first, t.second);
+ }
+}
+
std::string device_addr_t::to_pp_string(void) const{
if (this->size() == 0) return "Empty Device Address";
diff --git a/host/tests/addr_test.cpp b/host/tests/addr_test.cpp
index 671715153..9819df1a5 100644
--- a/host/tests/addr_test.cpp
+++ b/host/tests/addr_test.cpp
@@ -75,3 +75,12 @@ BOOST_AUTO_TEST_CASE(test_dboard_id){
BOOST_CHECK_EQUAL(dboard_id_t::from_string("1234").to_uint16(), 1234);
std::cout << "Pretty Print: " << std::endl << dboard_id_t::none().to_pp_string();
}
+
+BOOST_AUTO_TEST_CASE(test_map_device_addr){
+ std::map<std::string, std::string> dev_addr_map;
+ dev_addr_map["key1"] = "val1";
+ dev_addr_map["key2"] = "val2";
+ uhd::device_addr_t dev_addr(dev_addr_map);
+ BOOST_CHECK_EQUAL(dev_addr["key1"], "val1");
+ BOOST_CHECK_EQUAL(dev_addr["key2"], "val2");
+}