diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2016-08-24 22:32:51 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2017-04-19 09:36:47 +1000 |
commit | 2b58bbd50aa6a4af4c8f3019820396e5081b041a (patch) | |
tree | 03019304c96dcda1fca6e00513f5224acb876987 /libs/pbd | |
parent | cb3c564822e091325ff8799551640878faa3c597 (diff) |
Use PBD string conversion functions in PBD::ConfigurationVariable
No longer need a specialization for bool as PBD::to_string/string_to already
has specializations for bool
Remove template specialization for float as string_to/to_string handles string
representations of infinity
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/configuration_variable.cc | 8 | ||||
-rw-r--r-- | libs/pbd/pbd/configuration_variable.h | 59 |
2 files changed, 4 insertions, 63 deletions
diff --git a/libs/pbd/configuration_variable.cc b/libs/pbd/configuration_variable.cc index 0e2d6c739a..61c024a58a 100644 --- a/libs/pbd/configuration_variable.cc +++ b/libs/pbd/configuration_variable.cc @@ -111,11 +111,3 @@ ConfigVariableBase::miss () // placeholder for any debugging desired when a config variable // 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 143f53f218..33d5b95d39 100644 --- a/libs/pbd/pbd/configuration_variable.h +++ b/libs/pbd/pbd/configuration_variable.h @@ -20,12 +20,10 @@ #ifndef __libpbd_configuration_variable_h__ #define __libpbd_configuration_variable_h__ -#include <iostream> -#include <sstream> #include <string> #include "pbd/xml++.h" -#include "pbd/convert.h" +#include "pbd/string_convert.h" #include "pbd/libpbd_visibility.h" namespace PBD { @@ -63,9 +61,7 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase } std::string get_as_string () const { - std::ostringstream ss; - ss << value; - return ss.str (); + return to_string<T>(value); } virtual bool set (T val) { @@ -79,9 +75,7 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase } virtual void set_from_string (std::string const & s) { - std::stringstream ss; - ss << s; - ss >> value; + value = string_to<T>(s); } protected: @@ -89,10 +83,6 @@ class /*LIBPBD_API*/ ConfigVariable : public ConfigVariableBase T value; }; -/** Specialisation of ConfigVariable to deal with float (-inf etc) */ -template<> LIBPBD_API 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 @@ -129,43 +119,6 @@ class /*LIBPBD_API*/ ConfigVariable<std::string> : public ConfigVariableBase std::string value; }; -template<> -class /*LIBPBD_API*/ ConfigVariable<bool> : public ConfigVariableBase -{ - public: - - ConfigVariable (std::string str) : ConfigVariableBase (str), value (false) {} - ConfigVariable (std::string str, bool val) : ConfigVariableBase (str), value (val) {} - - bool get() const { - return value; - } - - std::string get_as_string () const { - std::ostringstream ss; - ss << value; - return ss.str (); - } - - virtual bool set (bool val) { - if (val == value) { - miss (); - return false; - } - value = val; - notify (); - return true; - } - - void set_from_string (std::string const & s) { - value = PBD::string_is_affirmative (s); - } - - protected: - virtual bool get_for_save() { return value; } - bool value; -}; - template<class T> class /*LIBPBD_API*/ ConfigVariableWithMutation : public ConfigVariable<T> { @@ -182,11 +135,7 @@ class /*LIBPBD_API*/ ConfigVariableWithMutation : public ConfigVariable<T> } void set_from_string (std::string const & s) { - T v; - std::stringstream ss; - ss << s; - ss >> v; - set (v); + set (string_to<T>(s)); } protected: |