#include <sstream>
#include "pbd/xml++.h"
+#include "pbd/convert.h"
#include "ardour/types.h"
+#include "ardour/utils.h"
namespace ARDOUR {
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;
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
+{
+ 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 ConfigVariableWithMutation : public ConfigVariable<T>
{
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<std::string> : public ConfigVariable<std::string>
+{
+ public:
+ ConfigVariableWithMutation (std::string name, std::string val, std::string (*m)(std::string))
+ : ConfigVariable<std::string> (name, val), mutator (m) {}
+
+ bool set (std::string val) {
+ if (unmutated_value != val) {
+ unmutated_value = val;
+ return ConfigVariable<std::string>::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__ */