diff options
author | Robin Gareus <robin@gareus.org> | 2016-12-07 00:50:00 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-12-07 00:50:00 +0100 |
commit | 7b1f97bffa8c3a43618e35d5a50e6c7cf1558ff9 (patch) | |
tree | b3632a2d9b49482d0def25bf2a477c3ec10fe274 | |
parent | 6ce9efb11d01042c72044db98c6839db78bb4694 (diff) |
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++).
-rw-r--r-- | libs/pbd/configuration_variable.cc | 7 | ||||
-rw-r--r-- | libs/pbd/pbd/configuration_variable.h | 4 |
2 files changed, 11 insertions, 0 deletions
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<float>::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<float>::set_from_string (std::string const & s); + /** Specialisation of ConfigVariable for std::string to cope with whitespace properly */ template<> class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase |