diff options
author | Josh Blum <josh@joshknows.com> | 2011-09-15 13:10:02 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-09-16 10:36:29 -0400 |
commit | 5e40f9ef156f0c5a0ebd7a71ba4b9afd3b08bd20 (patch) | |
tree | 89f4ef578b8abc0f6dedaab3fc14c1e2c2e69722 | |
parent | 0b1b37d01ca8526d982a7c145583116428cc7634 (diff) | |
download | uhd-5e40f9ef156f0c5a0ebd7a71ba4b9afd3b08bd20.tar.gz uhd-5e40f9ef156f0c5a0ebd7a71ba4b9afd3b08bd20.tar.bz2 uhd-5e40f9ef156f0c5a0ebd7a71ba4b9afd3b08bd20.zip |
uhd: separate_device_addr, copy globals across entire address
-rw-r--r-- | host/lib/types/device_addr.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp index 45d885adc..e329bd390 100644 --- a/host/lib/types/device_addr.cpp +++ b/host/lib/types/device_addr.cpp @@ -96,7 +96,8 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){ } } //------------------------------------------------------------------ - device_addrs_t dev_addrs; + device_addrs_t dev_addrs(1); //must be at least one (obviously) + std::vector<std::string> global_keys; //keys that apply to all (no numerical suffix) BOOST_FOREACH(const std::string &key, dev_addr.keys()){ boost::cmatch matches; if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){ @@ -104,10 +105,21 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){ } std::string key_part(matches[1].first, matches[1].second); std::string num_part(matches[2].first, matches[2].second); - size_t num = (num_part.empty())? 0 : boost::lexical_cast<size_t>(num_part); + if (num_part.empty()){ //no number? save it for later + global_keys.push_back(key); + continue; + } + const size_t num = boost::lexical_cast<size_t>(num_part); dev_addrs.resize(std::max(num+1, dev_addrs.size())); dev_addrs[num][key_part] = dev_addr[key]; } + + //copy the global settings across all device addresses + BOOST_FOREACH(device_addr_t &my_dev_addr, dev_addrs){ + BOOST_FOREACH(const std::string &global_key, global_keys){ + my_dev_addr[global_key] = dev_addr[global_key]; + } + } return dev_addrs; } |