Specialise ConfigVariable for string so that values with
authorCarl Hetherington <carl@carlh.net>
Sun, 18 Sep 2011 19:49:36 +0000 (19:49 +0000)
committerCarl Hetherington <carl@carlh.net>
Sun, 18 Sep 2011 19:49:36 +0000 (19:49 +0000)
spaces in get handled properly (part of #4321).

git-svn-id: svn://localhost/ardour2/branches/3.0@10092 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/configuration_variable.h

index e05952417d4ccbbd15962f997e0f08d9c20aa3bb..da8fc1b9a119c26d60372168d0de01fe39be0101 100644 (file)
@@ -88,6 +88,42 @@ class ConfigVariable : public ConfigVariableBase
        T value;
 };
 
+/** Specialisation of ConfigVariable for std::string to cope with whitespace properly */
+template<>
+class ConfigVariable<std::string> : public ConfigVariableBase
+{
+  public:
+
+       ConfigVariable (std::string str) : ConfigVariableBase (str) {}
+       ConfigVariable (std::string str, std::string val) : ConfigVariableBase (str), value (val) {}
+
+       std::string get() const {
+               return value;
+       }
+
+       std::string get_as_string () const {
+               return value;
+       }
+
+       virtual bool set (std::string val) {
+               if (val == value) {
+                       miss ();
+                       return false;
+               }
+               value = val;
+               notify ();
+               return true;
+       }
+
+       virtual void set_from_string (std::string const & s) {
+               value = s;
+       }
+
+  protected:
+       virtual std::string get_for_save() { return value; }
+       std::string value;
+};
+
 template<>
 class ConfigVariable<bool> : public ConfigVariableBase
 {