From 3f1554f1a5a71190e2105354b8f6a8faa3347124 Mon Sep 17 00:00:00 2001 From: Aaron Rossetto Date: Wed, 18 Mar 2020 07:36:29 -0500 Subject: lib: Use from_str in constrained_device_args_t This modifies `constrained_device_args_t::bool_arg::parse()` to use `uhd::cast::from_str` to interpret strings as Boolean values, deduplicating the string parsing code and single-sourcing it from `uhd::cast`. --- .../uhdlib/usrp/constrained_device_args.hpp | 24 +++++++--------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/host/lib/include/uhdlib/usrp/constrained_device_args.hpp b/host/lib/include/uhdlib/usrp/constrained_device_args.hpp index 7c516f80c..6d836c84d 100644 --- a/host/lib/include/uhdlib/usrp/constrained_device_args.hpp +++ b/host/lib/include/uhdlib/usrp/constrained_device_args.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -220,27 +221,16 @@ public: // Types inline void parse(const std::string& str_rep) { try { - _value = (std::stoi(str_rep) != 0); - } catch (std::exception& ex) { if (str_rep.empty()) { - // If str_rep is empty then the device_addr was set - // without a value which means that the user "set" the flag - _value = true; - } else if (boost::algorithm::to_lower_copy(str_rep) == "true" - || boost::algorithm::to_lower_copy(str_rep) == "yes" - || boost::algorithm::to_lower_copy(str_rep) == "y" - || str_rep == "1") { + // If str_rep is empty, the flag is interpreted as set _value = true; - } else if (boost::algorithm::to_lower_copy(str_rep) == "false" - || boost::algorithm::to_lower_copy(str_rep) == "no" - || boost::algorithm::to_lower_copy(str_rep) == "n" - || str_rep == "0") { - _value = false; } else { - throw uhd::value_error( - str(boost::format("Error parsing boolean parameter %s: %s.") - % key() % ex.what())); + _value = uhd::cast::from_str(str_rep); } + } catch (std::exception& ex) { + throw uhd::value_error( + str(boost::format("Error parsing boolean parameter %s: %s.") + % key() % ex.what())); } } inline virtual std::string to_string() const -- cgit v1.2.3