diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-07-24 09:26:40 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-08-10 10:16:36 -0700 |
commit | 2129e9d20e5009f0c97b5935740d5db906956387 (patch) | |
tree | cd8a1b38052befbc8fcefda10a44321456f16ae9 /host | |
parent | 8d25a3acc123fd5ba971846aac7a4f23547925ba (diff) | |
download | uhd-2129e9d20e5009f0c97b5935740d5db906956387.tar.gz uhd-2129e9d20e5009f0c97b5935740d5db906956387.tar.bz2 uhd-2129e9d20e5009f0c97b5935740d5db906956387.zip |
lib: Improve constrained_device_args_t
- Add default parser helper
- Allow _enforce_discrete() for str_arg
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/include/uhdlib/usrp/constrained_device_args.hpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/host/lib/include/uhdlib/usrp/constrained_device_args.hpp b/host/lib/include/uhdlib/usrp/constrained_device_args.hpp index 487337bae..b75fae75a 100644 --- a/host/lib/include/uhdlib/usrp/constrained_device_args.hpp +++ b/host/lib/include/uhdlib/usrp/constrained_device_args.hpp @@ -15,6 +15,7 @@ #include <boost/assign/list_of.hpp> #include <vector> #include <string> +#include <sstream> #include <unordered_map> namespace uhd { @@ -237,6 +238,16 @@ namespace usrp { inline virtual std::string to_string() const = 0; + template <typename arg_type> + void parse_arg_default( + const device_addr_t& dev_args, + arg_type& constrained_arg + ) { + if (dev_args.has_key(constrained_arg.key())) { + constrained_arg.parse(dev_args[constrained_arg.key()]); + } + } + protected: //Methods //Override _parse to provide an implementation to parse all //client specific device args @@ -270,10 +281,11 @@ namespace usrp { if (!match) { std::string valid_values_str; for (size_t i = 0; i < valid_values.size(); i++) { - valid_values_str += ((i==0)?"":", ") + std::to_string(valid_values[i]); + std::stringstream valid_values_ss; + valid_values_ss << ((i==0)?"":", ") << valid_values[i]; throw uhd::value_error(str(boost::format( "Invalid device arg value: %s (Valid: {%s})") % - arg.to_string() % valid_values_str + arg.to_string() % valid_values_ss.str() )); } } |