diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-01-16 15:16:05 -0800 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-17 18:03:42 -0800 |
commit | 6bd47c969222ee9e5e89cd00ebea9141c215e55c (patch) | |
tree | 3cbddae51f99bef056446ae936fd409aee0add66 /host/lib/rfnoc/blockdef_xml_impl.cpp | |
parent | 18cfd25129d06c456eade78d4e74dc4dceae6501 (diff) | |
download | uhd-6bd47c969222ee9e5e89cd00ebea9141c215e55c.tar.gz uhd-6bd47c969222ee9e5e89cd00ebea9141c215e55c.tar.bz2 uhd-6bd47c969222ee9e5e89cd00ebea9141c215e55c.zip |
lib: rfnoc: apply clang-format
This is a continuation of 967be2a4.
$ clang-format -i -style=file host/lib/rfnoc/*.cpp
Diffstat (limited to 'host/lib/rfnoc/blockdef_xml_impl.cpp')
-rw-r--r-- | host/lib/rfnoc/blockdef_xml_impl.cpp | 171 |
1 files changed, 78 insertions, 93 deletions
diff --git a/host/lib/rfnoc/blockdef_xml_impl.cpp b/host/lib/rfnoc/blockdef_xml_impl.cpp index 26622d649..db491922c 100644 --- a/host/lib/rfnoc/blockdef_xml_impl.cpp +++ b/host/lib/rfnoc/blockdef_xml_impl.cpp @@ -6,14 +6,14 @@ // #include <uhd/exception.hpp> -#include <uhd/rfnoc/constants.hpp> #include <uhd/rfnoc/blockdef.hpp> +#include <uhd/rfnoc/constants.hpp> #include <uhd/utils/log.hpp> #include <uhd/utils/paths.hpp> -#include <boost/format.hpp> -#include <boost/lexical_cast.hpp> #include <boost/algorithm/string.hpp> #include <boost/filesystem/operations.hpp> +#include <boost/format.hpp> +#include <boost/lexical_cast.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <cstdlib> @@ -31,41 +31,39 @@ static const fs::path XML_EXTENSION(".xml"); /**************************************************************************** * port_t stuff ****************************************************************************/ -const device_addr_t blockdef::port_t::PORT_ARGS( - "name," - "type," - "vlen=0," - "pkt_size=0," - "optional=0," - "bursty=0," - "port," -); +const device_addr_t blockdef::port_t::PORT_ARGS("name," + "type," + "vlen=0," + "pkt_size=0," + "optional=0," + "bursty=0," + "port,"); blockdef::port_t::port_t() { // This guarantees that we can access these keys // even if they were never initialized: - for(const std::string &key: PORT_ARGS.keys()) { + for (const std::string& key : PORT_ARGS.keys()) { set(key, PORT_ARGS[key]); } } -bool blockdef::port_t::is_variable(const std::string &key) const +bool blockdef::port_t::is_variable(const std::string& key) const { - const std::string &val = get(key); + const std::string& val = get(key); return (val[0] == '$'); } -bool blockdef::port_t::is_keyword(const std::string &key) const +bool blockdef::port_t::is_keyword(const std::string& key) const { - const std::string &val = get(key); + const std::string& val = get(key); return (val[0] == '%'); } bool blockdef::port_t::is_valid() const { // Check we have all the keys: - for(const std::string &key: PORT_ARGS.keys()) { + for (const std::string& key : PORT_ARGS.keys()) { if (not has_key(key)) { return false; } @@ -78,7 +76,7 @@ bool blockdef::port_t::is_valid() const std::string blockdef::port_t::to_string() const { std::string result; - for(const std::string &key: PORT_ARGS.keys()) { + for (const std::string& key : PORT_ARGS.keys()) { if (has_key(key)) { result += str(boost::format("%s=%s,") % key % get(key)); } @@ -92,28 +90,26 @@ std::string blockdef::port_t::to_string() const ****************************************************************************/ const device_addr_t blockdef::arg_t::ARG_ARGS( // List all tags/args an <arg> can have here: - "name," - "type," - "value," - "check," - "check_message," - "action," - "port=0," -); + "name," + "type," + "value," + "check," + "check_message," + "action," + "port=0,"); const std::set<std::string> blockdef::arg_t::VALID_TYPES = { // List all tags/args a <type> can have here: "string", "int", "int_vector", - "double" -}; + "double"}; blockdef::arg_t::arg_t() { // This guarantees that we can access these keys // even if they were never initialized: - for(const std::string &key: ARG_ARGS.keys()) { + for (const std::string& key : ARG_ARGS.keys()) { set(key, ARG_ARGS[key]); } } @@ -121,7 +117,7 @@ blockdef::arg_t::arg_t() bool blockdef::arg_t::is_valid() const { // 1. Check we have all the keys: - for(const std::string &key: ARG_ARGS.keys()) { + for (const std::string& key : ARG_ARGS.keys()) { if (not has_key(key)) { return false; } @@ -139,7 +135,7 @@ bool blockdef::arg_t::is_valid() const std::string blockdef::arg_t::to_string() const { std::string result; - for(const std::string &key: ARG_ARGS.keys()) { + for (const std::string& key : ARG_ARGS.keys()) { if (has_key(key)) { result += str(boost::format("%s=%s,") % key % get(key)); } @@ -154,10 +150,7 @@ std::string blockdef::arg_t::to_string() const class blockdef_xml_impl : public blockdef { public: - enum xml_repr_t { - DESCRIBES_BLOCK, - DESCRIBES_COMPONENT - }; + enum xml_repr_t { DESCRIBES_BLOCK, DESCRIBES_COMPONENT }; //! Returns a list of base paths for the XML files. // It is assumed that block definitions are in a subdir with name @@ -180,7 +173,7 @@ public: } //! Matches a NoC ID through substring matching - static bool match_noc_id(const std::string &lhs_, uint64_t rhs_) + static bool match_noc_id(const std::string& lhs_, uint64_t rhs_) { // Sanitize input: Make both values strings with all uppercase // characters and no leading 0x. Check inputs are valid. @@ -191,9 +184,10 @@ public: } UHD_ASSERT_THROW(rhs.size() == 16); if (lhs.size() < 4 or lhs.size() > 16) { - throw uhd::value_error(str(boost::format( - "%s is not a valid NoC ID (must be hexadecimal, min 4 and max 16 characters)" - ) % lhs_)); + throw uhd::value_error( + str(boost::format("%s is not a valid NoC ID (must be hexadecimal, min 4 " + "and max 16 characters)") + % lhs_)); } // OK, all good now. Next, we try and match the substring lhs in rhs: @@ -201,34 +195,31 @@ public: } //! Open the file at filename and see if it's a block definition for the given NoC ID - static bool has_noc_id(uint64_t noc_id, const fs::path &filename) + static bool has_noc_id(uint64_t noc_id, const fs::path& filename) { pt::ptree propt; try { read_xml(filename.string(), propt); - for(pt::ptree::value_type &v: propt.get_child("nocblock.ids")) { + for (pt::ptree::value_type& v : propt.get_child("nocblock.ids")) { if (v.first == "id" and match_noc_id(v.second.data(), noc_id)) { return true; } } - } catch (std::exception &e) { - UHD_LOGGER_WARNING("RFNOC") - << "has_noc_id(): caught exception " << e.what() - << " while parsing file: " << filename.string(); + } catch (std::exception& e) { + UHD_LOGGER_WARNING("RFNOC") << "has_noc_id(): caught exception " << e.what() + << " while parsing file: " << filename.string(); return false; } return false; } - blockdef_xml_impl(const fs::path &filename, uint64_t noc_id, xml_repr_t type=DESCRIBES_BLOCK) : - _type(type), - _noc_id(noc_id) + blockdef_xml_impl( + const fs::path& filename, uint64_t noc_id, xml_repr_t type = DESCRIBES_BLOCK) + : _type(type), _noc_id(noc_id) { - UHD_LOGGER_DEBUG("RFNOC") << - boost::format("Reading XML file %s for NOC ID 0x%08X") - % filename.string().c_str() - % noc_id - ; + UHD_LOGGER_DEBUG("RFNOC") + << boost::format("Reading XML file %s for NOC ID 0x%08X") + % filename.string().c_str() % noc_id; read_xml(filename.string(), _pt); try { // Check key is valid @@ -236,7 +227,7 @@ public: // Check name is valid get_name(); // Check there's at least one port - ports_t in = get_input_ports(); + ports_t in = get_input_ports(); ports_t out = get_output_ports(); if (in.empty() and out.empty()) { throw uhd::runtime_error("Block does not define inputs or outputs."); @@ -244,11 +235,10 @@ public: // Check args are valid get_args(); // TODO any more checks? - } catch (const std::exception &e) { - throw uhd::runtime_error(str( - boost::format("Invalid block definition in %s: %s") - % filename.string() % e.what() - )); + } catch (const std::exception& e) { + throw uhd::runtime_error( + str(boost::format("Invalid block definition in %s: %s") + % filename.string() % e.what())); } } @@ -266,7 +256,7 @@ public: { try { return _pt.get<std::string>("nocblock.key"); - } catch (const pt::ptree_bad_path &) { + } catch (const pt::ptree_bad_path&) { return _pt.get<std::string>("nocblock.blockname"); } } @@ -291,16 +281,17 @@ public: return _get_ports("source"); } - ports_t _get_ports(const std::string &port_type) + ports_t _get_ports(const std::string& port_type) { std::set<size_t> port_numbers; size_t n_ports = 0; ports_t ports; - for(pt::ptree::value_type &v: _pt.get_child("nocblock.ports")) { - if (v.first != port_type) continue; + for (pt::ptree::value_type& v : _pt.get_child("nocblock.ports")) { + if (v.first != port_type) + continue; // Now we have the correct sink or source node: port_t port; - for(const std::string &key: port_t::PORT_ARGS.keys()) { + for (const std::string& key : port_t::PORT_ARGS.keys()) { port[key] = v.second.get(key, port_t::PORT_ARGS[key]); } // We have to be extra-careful with the port numbers: @@ -310,17 +301,15 @@ public: size_t new_port_number; try { new_port_number = boost::lexical_cast<size_t>(port["port"]); - } catch (const boost::bad_lexical_cast &e) { - throw uhd::value_error(str( - boost::format("Invalid port number '%s' on port '%s'") - % port["port"] % port["name"] - )); + } catch (const boost::bad_lexical_cast& e) { + throw uhd::value_error( + str(boost::format("Invalid port number '%s' on port '%s'") + % port["port"] % port["name"])); } if (port_numbers.count(new_port_number) or new_port_number > MAX_NUM_PORTS) { - throw uhd::value_error(str( - boost::format("Port '%s' has invalid port number %d!") - % port["name"] % new_port_number - )); + throw uhd::value_error( + str(boost::format("Port '%s' has invalid port number %d!") + % port["name"] % new_port_number)); } port_numbers.insert(new_port_number); n_ports++; @@ -332,10 +321,10 @@ public: std::vector<size_t> get_all_port_numbers() { std::set<size_t> set_ports; - for(const port_t &port: get_input_ports()) { + for (const port_t& port : get_input_ports()) { set_ports.insert(boost::lexical_cast<size_t>(port["port"])); } - for(const port_t &port: get_output_ports()) { + for (const port_t& port : get_output_ports()) { set_ports.insert(boost::lexical_cast<size_t>(port["port"])); } return std::vector<size_t>(set_ports.begin(), set_ports.end()); @@ -347,10 +336,11 @@ public: args_t args; bool is_valid = true; pt::ptree def; - for(pt::ptree::value_type &v: _pt.get_child("nocblock.args", def)) { + for (pt::ptree::value_type& v : _pt.get_child("nocblock.args", def)) { arg_t arg; - if (v.first != "arg") continue; - for(const std::string &key: arg_t::ARG_ARGS.keys()) { + if (v.first != "arg") + continue; + for (const std::string& key : arg_t::ARG_ARGS.keys()) { arg[key] = v.second.get(key, arg_t::ARG_ARGS[key]); } if (arg["type"].empty()) { @@ -364,10 +354,8 @@ public: args.push_back(arg); } if (not is_valid) { - throw uhd::runtime_error(str( - boost::format("Found invalid arguments for block %s.") - % get_name() - )); + throw uhd::runtime_error( + str(boost::format("Found invalid arguments for block %s.") % get_name())); } return args; } @@ -382,12 +370,13 @@ public: return _get_regs("readback"); } - registers_t _get_regs(const std::string ®_type) + registers_t _get_regs(const std::string& reg_type) { registers_t registers; pt::ptree def; - for(pt::ptree::value_type &v: _pt.get_child("nocblock.registers", def)) { - if (v.first != reg_type) continue; + for (pt::ptree::value_type& v : _pt.get_child("nocblock.registers", def)) { + if (v.first != reg_type) + continue; registers[v.second.get<std::string>("name")] = boost::lexical_cast<size_t>(v.second.get<size_t>("address")); } @@ -396,7 +385,6 @@ public: private: - //! Tells us if is this for a NoC block, or a component. const xml_repr_t _type; //! The NoC-ID as reported (there may be several valid NoC IDs, this is the one used) @@ -405,7 +393,6 @@ private: //! This is a boost property tree, not the same as // our property tree. pt::ptree _pt; - }; blockdef::sptr blockdef::make_from_noc_id(uint64_t noc_id) @@ -422,11 +409,9 @@ blockdef::sptr blockdef::make_from_noc_id(uint64_t noc_id) } if (valid.empty()) { - throw uhd::assertion_error( - "Failed to find a valid XML path for RFNoC blocks.\n" - "Try setting the enviroment variable UHD_RFNOC_DIR " - "to the correct location" - ); + throw uhd::assertion_error("Failed to find a valid XML path for RFNoC blocks.\n" + "Try setting the enviroment variable UHD_RFNOC_DIR " + "to the correct location"); } // Iterate over all paths |