diff options
-rw-r--r-- | gr-soapy/python/soapy/bindings/soapy_common.cc | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/gr-soapy/python/soapy/bindings/soapy_common.cc b/gr-soapy/python/soapy/bindings/soapy_common.cc index 98d59be032..911ec7209e 100644 --- a/gr-soapy/python/soapy/bindings/soapy_common.cc +++ b/gr-soapy/python/soapy/bindings/soapy_common.cc @@ -11,6 +11,8 @@ #include <SoapySDR/Types.hpp> #include <SoapySDR/Version.h> +#include <stdexcept> +#include <string> // SoapySDR doesn't have an API define for SettingToString, so we need // to check the version. 0.8 is the first tagged version to have this @@ -49,22 +51,20 @@ static inline T string_to_setting(const std::string& str) } // Copied from SoapySDR 0.8 +//! convert empty and "false" strings to false, integers to their truthness template <> inline bool string_to_setting<bool>(const std::string& str) { - if (str == SOAPY_SDR_TRUE) - return true; - if (str == SOAPY_SDR_FALSE) - return false; - - // zeros and empty strings are false - if (str == "0") - return false; - if (str == "0.0") - return false; - if (str == "") + if (str.empty() || str == SOAPY_SDR_FALSE) { return false; - + } + if (str == SOAPY_SDR_TRUE) { + return true; + } + try { + return static_cast<bool>(std::stod(str)); + } catch (std::invalid_argument& e) { + } // other values are true return true; } |