diff options
author | Andrej Rode <andrej.rode@ettus.com> | 2017-02-09 23:19:55 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-02-10 16:44:33 -0800 |
commit | 26cc20847cde543e759aa5cee9a27eaa69c5dd9e (patch) | |
tree | eee102333381e2313af59e725d6b7a06b665161f /host/lib/types | |
parent | f3a004faf7d50cbb5564f5e2f67f54ee07e051dd (diff) | |
download | uhd-26cc20847cde543e759aa5cee9a27eaa69c5dd9e.tar.gz uhd-26cc20847cde543e759aa5cee9a27eaa69c5dd9e.tar.bz2 uhd-26cc20847cde543e759aa5cee9a27eaa69c5dd9e.zip |
uhd: replace BOOST_FOREACH with C++11 range-based for loop
Note: This is the first commit that uses for-range, and range-based
for-loops are now usable for UHD development.
Diffstat (limited to 'host/lib/types')
-rw-r--r-- | host/lib/types/byte_vector.cpp | 3 | ||||
-rw-r--r-- | host/lib/types/device_addr.cpp | 17 | ||||
-rw-r--r-- | host/lib/types/mac_addr.cpp | 5 | ||||
-rw-r--r-- | host/lib/types/ranges.cpp | 11 |
4 files changed, 16 insertions, 20 deletions
diff --git a/host/lib/types/byte_vector.cpp b/host/lib/types/byte_vector.cpp index 15ae93858..f08b6e088 100644 --- a/host/lib/types/byte_vector.cpp +++ b/host/lib/types/byte_vector.cpp @@ -15,7 +15,6 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <boost/foreach.hpp> #include <uhd/types/byte_vector.hpp> @@ -23,7 +22,7 @@ namespace uhd{ std::string bytes_to_string(const byte_vector_t &bytes){ std::string out; - BOOST_FOREACH(uint8_t byte, bytes){ + for(uint8_t byte: bytes){ if (byte < 32 or byte > 127) return out; out += byte; } diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp index 747f61b8d..71acd7f1f 100644 --- a/host/lib/types/device_addr.cpp +++ b/host/lib/types/device_addr.cpp @@ -18,7 +18,6 @@ #include <uhd/types/device_addr.hpp> #include <boost/algorithm/string.hpp> #include <boost/tokenizer.hpp> -#include <boost/foreach.hpp> #include <boost/format.hpp> #include <boost/regex.hpp> #include <stdexcept> @@ -38,10 +37,10 @@ static std::string trim(const std::string &in){ (inp, boost::char_separator<char>(sep)) device_addr_t::device_addr_t(const std::string &args){ - BOOST_FOREACH(const std::string &pair, tokenizer(args, arg_delim)){ + for(const std::string &pair: tokenizer(args, arg_delim)){ if (trim(pair) == "") continue; std::vector<std::string> toks; - BOOST_FOREACH(const std::string &tok, tokenizer(pair, pair_delim)){ + for(const std::string &tok: tokenizer(pair, pair_delim)){ toks.push_back(tok); } if (toks.size() == 1) toks.push_back(""); //pad empty value @@ -57,7 +56,7 @@ std::string device_addr_t::to_pp_string(void) const{ std::stringstream ss; ss << "Device Address:" << std::endl; - BOOST_FOREACH(std::string key, this->keys()){ + for(std::string key: this->keys()){ ss << boost::format(" %s: %s") % key % this->get(key) << std::endl; } return ss.str(); @@ -66,7 +65,7 @@ std::string device_addr_t::to_pp_string(void) const{ std::string device_addr_t::to_string(void) const{ std::string args_str; size_t count = 0; - BOOST_FOREACH(const std::string &key, this->keys()){ + for(const std::string &key: this->keys()){ args_str += ((count++)? arg_delim : "") + key + pair_delim + this->get(key); } return args_str; @@ -97,7 +96,7 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){ //------------------------------------------------------------------ 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()){ + for(const std::string &key: dev_addr.keys()){ boost::cmatch matches; if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){ throw std::runtime_error("unknown key format: " + key); @@ -114,8 +113,8 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){ } //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){ + for(device_addr_t &my_dev_addr: dev_addrs){ + for(const std::string &global_key: global_keys){ my_dev_addr[global_key] = dev_addr[global_key]; } } @@ -125,7 +124,7 @@ device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){ device_addr_t uhd::combine_device_addrs(const device_addrs_t &dev_addrs){ device_addr_t dev_addr; for (size_t i = 0; i < dev_addrs.size(); i++){ - BOOST_FOREACH(const std::string &key, dev_addrs[i].keys()){ + for(const std::string &key: dev_addrs[i].keys()){ dev_addr[str(boost::format("%s%d") % key % i)] = dev_addrs[i][key]; } } diff --git a/host/lib/types/mac_addr.cpp b/host/lib/types/mac_addr.cpp index ab71bc0c3..2e5651558 100644 --- a/host/lib/types/mac_addr.cpp +++ b/host/lib/types/mac_addr.cpp @@ -18,7 +18,6 @@ #include <uhd/types/mac_addr.hpp> #include <uhd/exception.hpp> #include <boost/tokenizer.hpp> -#include <boost/foreach.hpp> #include <boost/format.hpp> #include <stdint.h> #include <sstream> @@ -45,7 +44,7 @@ mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){ //split the mac addr hex string at the colons boost::tokenizer<boost::char_separator<char> > hex_num_toks( mac_addr_str, boost::char_separator<char>(":")); - BOOST_FOREACH(const std::string &hex_str, hex_num_toks){ + for(const std::string &hex_str: hex_num_toks){ int hex_num; std::istringstream iss(hex_str); iss >> std::hex >> hex_num; @@ -68,7 +67,7 @@ byte_vector_t mac_addr_t::to_bytes(void) const{ std::string mac_addr_t::to_string(void) const{ std::string addr = ""; - BOOST_FOREACH(uint8_t byte, this->to_bytes()){ + for(uint8_t byte: this->to_bytes()){ addr += str(boost::format("%s%02x") % ((addr == "")?"":":") % int(byte)); } return addr; diff --git a/host/lib/types/ranges.cpp b/host/lib/types/ranges.cpp index 82a9a84e1..ee4546cb8 100644 --- a/host/lib/types/ranges.cpp +++ b/host/lib/types/ranges.cpp @@ -18,7 +18,6 @@ #include <uhd/types/ranges.hpp> #include <uhd/exception.hpp> #include <boost/math/special_functions/round.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <sstream> @@ -93,7 +92,7 @@ meta_range_t::meta_range_t( double meta_range_t::start(void) const{ check_meta_range_monotonic(*this); double min_start = this->front().start(); - BOOST_FOREACH(const range_t &r, (*this)){ + for(const range_t &r: (*this)){ min_start = std::min(min_start, r.start()); } return min_start; @@ -102,7 +101,7 @@ double meta_range_t::start(void) const{ double meta_range_t::stop(void) const{ check_meta_range_monotonic(*this); double max_stop = this->front().stop(); - BOOST_FOREACH(const range_t &r, (*this)){ + for(const range_t &r: (*this)){ max_stop = std::max(max_stop, r.stop()); } return max_stop; @@ -112,7 +111,7 @@ double meta_range_t::step(void) const{ check_meta_range_monotonic(*this); std::vector<double> non_zero_steps; range_t last = this->front(); - BOOST_FOREACH(const range_t &r, (*this)){ + for(const range_t &r: (*this)){ //steps at each range if (r.step() > 0) non_zero_steps.push_back(r.step()); //and steps in-between ranges @@ -128,7 +127,7 @@ double meta_range_t::step(void) const{ double meta_range_t::clip(double value, bool clip_step) const{ check_meta_range_monotonic(*this); double last_stop = this->front().stop(); - BOOST_FOREACH(const range_t &r, (*this)){ + for(const range_t &r: (*this)){ //in-between ranges, clip to nearest if (value < r.start()){ return (std::abs(value - r.start()) < std::abs(value - last_stop))? @@ -147,7 +146,7 @@ double meta_range_t::clip(double value, bool clip_step) const{ const std::string meta_range_t::to_pp_string(void) const{ std::stringstream ss; - BOOST_FOREACH(const range_t &r, (*this)){ + for(const range_t &r: (*this)){ ss << r.to_pp_string() << std::endl; } return ss.str(); |