X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fardour%2Fconfiguration_variable.h;h=da8fc1b9a119c26d60372168d0de01fe39be0101;hb=cd2047cbffc5e0270acab555364bb9d958fe7927;hp=90859b72b15989de83e7bcae9b50cafcaf536b83;hpb=bb9cc45cd22af67ac275a5e73accbe14fee664d8;p=ardour.git diff --git a/libs/ardour/ardour/configuration_variable.h b/libs/ardour/ardour/configuration_variable.h index 90859b72b1..da8fc1b9a1 100644 --- a/libs/ardour/ardour/configuration_variable.h +++ b/libs/ardour/ardour/configuration_variable.h @@ -20,11 +20,12 @@ #ifndef __ardour_configuration_variable_h__ #define __ardour_configuration_variable_h__ -#include -#include #include +#include #include "pbd/xml++.h" +#include "ardour/types.h" +#include "ardour/utils.h" namespace ARDOUR { @@ -41,13 +42,8 @@ class ConfigVariableBase { virtual std::string get_as_string () const = 0; virtual void set_from_string (std::string const &) = 0; - void show_stored_value (const std::string&); - - static void set_show_stored_values (bool); - protected: std::string _name; - static bool show_stores; void notify (); void miss (); @@ -66,7 +62,7 @@ class ConfigVariable : public ConfigVariableBase } std::string get_as_string () const { - std::stringstream ss; + std::ostringstream ss; ss << value; return ss.str (); } @@ -81,7 +77,7 @@ class ConfigVariable : public ConfigVariableBase return true; } - void set_from_string (std::string const & s) { + virtual void set_from_string (std::string const & s) { std::stringstream ss; ss << s; ss >> value; @@ -92,6 +88,79 @@ 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 +{ + 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 = string_is_affirmative (s); + } + + protected: + virtual bool get_for_save() { return value; } + bool value; +}; + template class ConfigVariableWithMutation : public ConfigVariable { @@ -107,12 +176,45 @@ class ConfigVariableWithMutation : public ConfigVariable return false; } + void set_from_string (std::string const & s) { + T v; + std::stringstream ss; + ss << s; + ss >> v; + set (v); + } + protected: virtual T get_for_save() { return unmutated_value; } T unmutated_value; 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__ */