Use PBD string conversion functions in PBD::ConfigurationVariable
authorTim Mayberry <mojofunk@gmail.com>
Wed, 24 Aug 2016 12:32:51 +0000 (22:32 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Tue, 18 Apr 2017 23:36:47 +0000 (09:36 +1000)
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

gtk2_ardour/ui_config.cc
libs/ardour/rc_configuration.cc
libs/ardour/session.cc
libs/ardour/session_configuration.cc
libs/pbd/configuration_variable.cc
libs/pbd/pbd/configuration_variable.h

index 7758c6a0524a67be65d2f9fb97f2d2fbee9387dc..2a555970c4db321a4517a2c010375acc10c91c6a 100644 (file)
@@ -49,6 +49,7 @@
 #include "ardour/search_paths.h"
 #include "ardour/revision.h"
 #include "ardour/utils.h"
+#include "ardour/types_convert.h"
 
 #include "gtkmm2ext/rgb_macros.h"
 #include "gtkmm2ext/gtk_ui.h"
index 7fc2f5105b6755ed7906c0d1d7f9f781c1e417f1..e16bf40fb7b0ca274b8574a28b56629e8d8e4063 100644 (file)
@@ -35,6 +35,7 @@
 #include "ardour/port.h"
 #include "ardour/rc_configuration.h"
 #include "ardour/session_metadata.h"
+#include "ardour/types_convert.h"
 
 #include "pbd/i18n.h"
 
index 243a46b0ee091b55c5762543d1231b85be3058d3..ded851faae7e3858036523c2131ff0efff244635 100644 (file)
 #include "ardour/tempo.h"
 #include "ardour/ticker.h"
 #include "ardour/track.h"
+#include "ardour/types_convert.h"
 #include "ardour/user_bundle.h"
 #include "ardour/utils.h"
 #include "ardour/vca_manager.h"
index b8814711f376a856e6fea8df430cf9ceb8a89bbe..3b4f4c7f9aa6eed81f9416f35fac4ef9e84380d9 100644 (file)
@@ -27,6 +27,7 @@
 #include "pbd/pathexpand.h"
 
 #include "ardour/types.h"
+#include "ardour/types_convert.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/session_configuration.h"
 #include "ardour/utils.h"
index 0e2d6c739a9392a1ec5f8969fa779749c4f2d2cf..61c024a58a860754e4960180f14a30b89a3df8d6 100644 (file)
@@ -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);
-}
index 143f53f2181b567f1bed58d3bd04827a8a144efc..33d5b95d39883ad3ddd182223947b23f19945ae8 100644 (file)
 #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: