fix parsing "-inf" in config variables
authorRobin Gareus <robin@gareus.org>
Tue, 6 Dec 2016 23:50:00 +0000 (00:50 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 6 Dec 2016 23:50:00 +0000 (00:50 +0100)
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
libs/pbd/pbd/configuration_variable.h

index 578114e92a55b32e1fcf5e53fedfb3797dab3e9d..cde1d15bf186bd348ef9fbb965197bc916ceea33 100644 (file)
@@ -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);
+}
index 6bdf0f7868589c59045f3fee367831cf04760f84..7af7974229d6d8144c84f74b9999aee96c7ab4dc 100644 (file)
@@ -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