From 2129e9d20e5009f0c97b5935740d5db906956387 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 24 Jul 2018 09:26:40 -0700 Subject: lib: Improve constrained_device_args_t - Add default parser helper - Allow _enforce_discrete() for str_arg --- host/lib/include/uhdlib/usrp/constrained_device_args.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'host/lib/include') 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 #include #include +#include #include namespace uhd { @@ -237,6 +238,16 @@ namespace usrp { inline virtual std::string to_string() const = 0; + template + 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() )); } } -- cgit v1.2.3