X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fardour%2Fardour%2Fconfiguration_variable.h;h=a7fe8def48169c17c508ca714ffc135a1ea9bfb9;hb=976fc86811bbef6e8b79ed6157155593e5122740;hp=ec954e8d9c4f0206a93b4e11371a60c73a2bdff5;hpb=2575a3907b665e0ff3f151221e5c753c84d512ee;p=ardour.git diff --git a/libs/ardour/ardour/configuration_variable.h b/libs/ardour/ardour/configuration_variable.h index ec954e8d9c..a7fe8def48 100644 --- a/libs/ardour/ardour/configuration_variable.h +++ b/libs/ardour/ardour/configuration_variable.h @@ -24,6 +24,7 @@ #include #include "pbd/xml++.h" +#include "pbd/convert.h" #include "ardour/types.h" #include "ardour/utils.h" @@ -88,6 +89,42 @@ class ConfigVariable : public ConfigVariableBase T value; }; +/** Specialisation of ConfigVariable for std::string to cope with whitespace properly */ +template<> +class ConfigVariable : 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 : public ConfigVariableBase { @@ -117,7 +154,7 @@ class ConfigVariable : public ConfigVariableBase } void set_from_string (std::string const & s) { - value = string_is_affirmative (s); + value = PBD::string_is_affirmative (s); } protected: @@ -141,11 +178,11 @@ class ConfigVariableWithMutation : public ConfigVariable } void set_from_string (std::string const & s) { - T v; - std::stringstream ss; - ss << s; + T v; + std::stringstream ss; + ss << s; ss >> v; - set (v); + set (v); } protected: @@ -154,6 +191,31 @@ class ConfigVariableWithMutation : public ConfigVariable T (*mutator)(T); }; +template<> +class ConfigVariableWithMutation : public ConfigVariable +{ + public: + ConfigVariableWithMutation (std::string name, std::string val, std::string (*m)(std::string)) + : ConfigVariable (name, val), mutator (m) {} + + bool set (std::string val) { + if (unmutated_value != val) { + unmutated_value = val; + return ConfigVariable::set (mutator (val)); + } + return false; + } + + void set_from_string (std::string const & s) { + set (s); + } + + protected: + virtual std::string get_for_save() { return unmutated_value; } + std::string unmutated_value; + std::string (*mutator)(std::string); +}; + } #endif /* __ardour_configuration_variable_h__ */