From 26cc20847cde543e759aa5cee9a27eaa69c5dd9e Mon Sep 17 00:00:00 2001 From: Andrej Rode Date: Thu, 9 Feb 2017 23:19:55 -0800 Subject: 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. --- host/include/uhd/image_loader.hpp | 1 + host/include/uhd/property_tree.ipp | 5 ++--- host/include/uhd/rfnoc/node_ctrl_base.ipp | 4 ++-- host/include/uhd/types/dict.ipp | 17 ++++++++--------- host/include/uhd/utils/assert_has.ipp | 3 +-- host/include/uhd/utils/soft_register.hpp | 23 +++++++++++------------ 6 files changed, 25 insertions(+), 28 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/image_loader.hpp b/host/include/uhd/image_loader.hpp index fd4a96781..4ebac288e 100644 --- a/host/include/uhd/image_loader.hpp +++ b/host/include/uhd/image_loader.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include diff --git a/host/include/uhd/property_tree.ipp b/host/include/uhd/property_tree.ipp index 6ed1056e6..ef63ced24 100644 --- a/host/include/uhd/property_tree.ipp +++ b/host/include/uhd/property_tree.ipp @@ -19,7 +19,6 @@ #define INCLUDED_UHD_PROPERTY_TREE_IPP #include -#include #include #include @@ -72,14 +71,14 @@ public: void _set_coerced(const T &value){ init_or_set_value(_coerced_value, value); - BOOST_FOREACH(typename property::subscriber_type &csub, _coerced_subscribers){ + for(typename property::subscriber_type &csub: _coerced_subscribers){ csub(get_value_ref(_coerced_value)); //let errors propagate } } property &set(const T &value){ init_or_set_value(_value, value); - BOOST_FOREACH(typename property::subscriber_type &dsub, _desired_subscribers){ + for(typename property::subscriber_type &dsub: _desired_subscribers){ dsub(get_value_ref(_value)); //let errors propagate } if (not _coercer.empty()) { diff --git a/host/include/uhd/rfnoc/node_ctrl_base.ipp b/host/include/uhd/rfnoc/node_ctrl_base.ipp index d300f72a7..2492031be 100644 --- a/host/include/uhd/rfnoc/node_ctrl_base.ipp +++ b/host/include/uhd/rfnoc/node_ctrl_base.ipp @@ -45,7 +45,7 @@ namespace uhd { while (iters++ < MAX_ITER) { next_q.clear(); - BOOST_FOREACH(const sptr &this_node, search_q) { + for(const sptr &this_node: search_q) { // Add this node to the list of explored nodes explored.insert(this_node); // Create set of all child nodes of this_node that are not in explored: @@ -98,7 +98,7 @@ namespace uhd { std::vector< boost::shared_ptr > descendant_rate_nodes = _find_child_node(); value_type ret_val = NULL_VALUE; std::string first_node_id; - BOOST_FOREACH(const boost::shared_ptr &node, descendant_rate_nodes) { + for(const boost::shared_ptr &node: descendant_rate_nodes) { if (exclude_nodes.count(node)) { continue; } diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index 5fd4b536e..b9d367a3c 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -19,7 +19,6 @@ #define INCLUDED_UHD_TYPES_DICT_IPP #include -#include #include #include #include @@ -61,7 +60,7 @@ namespace uhd{ template std::vector dict::keys(void) const{ std::vector keys; - BOOST_FOREACH(const pair_t &p, _map){ + for(const pair_t &p: _map){ keys.push_back(p.first); } return keys; @@ -70,7 +69,7 @@ namespace uhd{ template std::vector dict::vals(void) const{ std::vector vals; - BOOST_FOREACH(const pair_t &p, _map){ + for(const pair_t &p: _map){ vals.push_back(p.second); } return vals; @@ -78,7 +77,7 @@ namespace uhd{ template bool dict::has_key(const Key &key) const{ - BOOST_FOREACH(const pair_t &p, _map){ + for(const pair_t &p: _map){ if (p.first == key) return true; } return false; @@ -86,7 +85,7 @@ namespace uhd{ template const Val &dict::get(const Key &key, const Val &other) const{ - BOOST_FOREACH(const pair_t &p, _map){ + for(const pair_t &p: _map){ if (p.first == key) return p.second; } return other; @@ -94,7 +93,7 @@ namespace uhd{ template const Val &dict::get(const Key &key) const{ - BOOST_FOREACH(const pair_t &p, _map){ + for(const pair_t &p: _map){ if (p.first == key) return p.second; } throw key_not_found(key); @@ -107,7 +106,7 @@ namespace uhd{ template const Val &dict::operator[](const Key &key) const{ - BOOST_FOREACH(const pair_t &p, _map){ + for(const pair_t &p: _map){ if (p.first == key) return p.second; } throw key_not_found(key); @@ -115,7 +114,7 @@ namespace uhd{ template Val &dict::operator[](const Key &key){ - BOOST_FOREACH(pair_t &p, _map){ + for(pair_t &p: _map){ if (p.first == key) return p.second; } _map.push_back(std::make_pair(key, Val())); @@ -138,7 +137,7 @@ namespace uhd{ template void dict::update(const dict &new_dict, bool fail_on_conflict) { - BOOST_FOREACH(const Key &key, new_dict.keys()) { + for(const Key &key: new_dict.keys()) { if (fail_on_conflict and has_key(key) and get(key) != new_dict[key]) { throw uhd::value_error(str( boost::format("Option merge conflict: %s:%s != %s:%s") diff --git a/host/include/uhd/utils/assert_has.ipp b/host/include/uhd/utils/assert_has.ipp index 7b3c88cb7..6457cf2ee 100644 --- a/host/include/uhd/utils/assert_has.ipp +++ b/host/include/uhd/utils/assert_has.ipp @@ -21,7 +21,6 @@ #include #include #include -#include #include namespace uhd{ @@ -34,7 +33,7 @@ namespace uhd{ if (uhd::has(range, value)) return; std::string possible_values = ""; size_t i = 0; - BOOST_FOREACH(const T &v, range){ + for(const T &v: range){ if (i++ > 0) possible_values += ", "; possible_values += boost::lexical_cast(v); } diff --git a/host/include/uhd/utils/soft_register.hpp b/host/include/uhd/utils/soft_register.hpp index 2870ad595..d3a1e0943 100644 --- a/host/include/uhd/utils/soft_register.hpp +++ b/host/include/uhd/utils/soft_register.hpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -479,7 +478,7 @@ public: */ void initialize(wb_iface& iface, bool sync = false) { boost::lock_guard lock(_mutex); - BOOST_FOREACH(soft_register_base* reg, _reglist) { + for(soft_register_base* reg: _reglist) { reg->initialize(iface, sync); } } @@ -491,7 +490,7 @@ public: */ void flush() { boost::lock_guard lock(_mutex); - BOOST_FOREACH(soft_register_base* reg, _reglist) { + for(soft_register_base* reg: _reglist) { reg->flush(); } } @@ -503,7 +502,7 @@ public: */ void refresh() { boost::lock_guard lock(_mutex); - BOOST_FOREACH(soft_register_base* reg, _reglist) { + for(soft_register_base* reg: _reglist) { reg->refresh(); } } @@ -527,7 +526,7 @@ public: */ virtual std::vector enumerate() const { std::vector temp; - BOOST_FOREACH(const regmap_t::value_type& reg, _regmap) { + for(const regmap_t::value_type& reg: _regmap) { temp.push_back(_name + "/" + reg.first); } return temp; @@ -623,8 +622,8 @@ public: { //Turn the slash separated path string into tokens std::list tokens; - BOOST_FOREACH( - const std::string& node, + for( + const std::string& node: boost::tokenizer< boost::char_separator >(path, boost::char_separator("/"))) { tokens.push_back(node); @@ -633,7 +632,7 @@ public: (tokens.size() > 1 && _name == "")) { //If this is a top-level DB if (_name != "") tokens.pop_front(); if (tokens.size() == 2) { //2 tokens => regmap/register path - BOOST_FOREACH(const soft_regmap_accessor_t* regmap, _regmaps) { + for(const soft_regmap_accessor_t* regmap: _regmaps) { if (regmap->get_name() == tokens.front()) { return regmap->lookup(tokens.back()); } @@ -642,11 +641,11 @@ public: } else if (not _regmap_dbs.empty()) { //>2 tokens => <1 or more dbs>/regmap/register //Reconstruct path from tokens std::string newpath; - BOOST_FOREACH(const std::string& node, tokens) { + for(const std::string& node: tokens) { newpath += ("/" + node); } //Dispatch path to hierarchical DB - BOOST_FOREACH(const soft_regmap_accessor_t* db, _regmap_dbs) { + for(const soft_regmap_accessor_t* db: _regmap_dbs) { try { return db->lookup(newpath.substr(1)); } catch (std::exception&) { @@ -663,11 +662,11 @@ public: */ virtual std::vector enumerate() const { std::vector paths; - BOOST_FOREACH(const soft_regmap_accessor_t* regmap, _regmaps) { + for(const soft_regmap_accessor_t* regmap: _regmaps) { const std::vector& regs = regmap->enumerate(); paths.insert(paths.end(), regs.begin(), regs.end()); } - BOOST_FOREACH(const soft_regmap_accessor_t* db, _regmap_dbs) { + for(const soft_regmap_accessor_t* db: _regmap_dbs) { const std::vector& regs = db->enumerate(); paths.insert(paths.end(), regs.begin(), regs.end()); } -- cgit v1.2.3