From 7b1f97bffa8c3a43618e35d5a50e6c7cf1558ff9 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 7 Dec 2016 00:50:00 +0100 Subject: fix parsing "-inf" in config variables The default for export-silence-threshold is -INFINITY, written as "-inf" (by cfgtool) into system_config. Yet parsing the config using a std::stringstream results in "0" (due to bugs in various libc++). --- libs/pbd/configuration_variable.cc | 7 +++++++ libs/pbd/pbd/configuration_variable.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/libs/pbd/configuration_variable.cc b/libs/pbd/configuration_variable.cc index 578114e92a..cde1d15bf1 100644 --- a/libs/pbd/configuration_variable.cc +++ b/libs/pbd/configuration_variable.cc @@ -107,3 +107,10 @@ ConfigVariableBase::miss () // is set but to the same value as it already has } +/* Specialisation of ConfigVariable to deal with float (-inf etc) + * http://stackoverflow.com/questions/23374095/should-a-stringstream-parse-infinity-as-an-infinite-value + */ +template<> void +ConfigVariable::set_from_string (std::string const & s) { + value = std::strtof (s.c_str(), NULL); +} diff --git a/libs/pbd/pbd/configuration_variable.h b/libs/pbd/pbd/configuration_variable.h index 6bdf0f7868..7af7974229 100644 --- a/libs/pbd/pbd/configuration_variable.h +++ b/libs/pbd/pbd/configuration_variable.h @@ -89,6 +89,10 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase T value; }; +/** Specialisation of ConfigVariable to deal with float (-inf etc) */ +template<> void +ConfigVariable::set_from_string (std::string const & s); + /** Specialisation of ConfigVariable for std::string to cope with whitespace properly */ template<> class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase -- cgit v1.2.3