From 3012d86672876734f7e25bd3411ba323c221ead6 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 2 Jun 2010 11:40:01 +0000 Subject: specialize ConfigVariable to use string_is_affirmative() and thus get consistency about how XML state is interpreted when setting *all* Configuration variables git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@7204 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/configuration_variable.h | 98 +++++++++++++++++++++++++++++ libs/ardour/ardour/utils.h | 6 +- 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/configuration_variable.h b/libs/ardour/ardour/configuration_variable.h index fa149672be..c9b9890c81 100644 --- a/libs/ardour/ardour/configuration_variable.h +++ b/libs/ardour/ardour/configuration_variable.h @@ -25,6 +25,8 @@ #include +#include "ardour/utils.h" + namespace ARDOUR { class ConfigVariableBase { @@ -157,6 +159,102 @@ class ConfigVariable : public ConfigVariableBase T value; }; +/* full specialization for bool, required because ::set_from_node() needs + special handling. +*/ + +template<> +class ConfigVariable : public ConfigVariableBase +{ + public: + ConfigVariable (std::string str) : ConfigVariableBase (str), value (false) {} + ConfigVariable (std::string str, bool val) : ConfigVariableBase (str), value (val) {} + + virtual bool set (bool val, Owner owner) { + if (val == value) { + miss (); + return false; + } + value = val; + _owner = (ConfigVariableBase::Owner)(_owner |owner); + notify (); + return true; + } + + bool get() const { + return value; + } + + void add_to_node (XMLNode& node) { + XMLNode* child = new XMLNode ("Option"); + child->add_property ("name", _name); + child->add_property ("value", (value ? "yes" : "no")); + node.add_child_nocopy (*child); + } + + bool set_from_node (const XMLNode& node, Owner owner) { + + if (node.name() == "Config") { + + /* ardour.rc */ + + const XMLProperty* prop; + XMLNodeList nlist; + XMLNodeConstIterator niter; + XMLNode* child; + + nlist = node.children(); + + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + + child = *niter; + + if (child->name() == "Option") { + if ((prop = child->property ("name")) != 0) { + if (prop->value() == _name) { + if ((prop = child->property ("value")) != 0) { + value = ::string_is_affirmative (prop->value()); + _owner = (ConfigVariableBase::Owner)(_owner |owner); + return true; + } + } + } + } + } + + } else if (node.name() == "Options") { + + /* session file */ + + XMLNodeList olist; + XMLNodeConstIterator oiter; + XMLNode* option; + const XMLProperty* opt_prop; + + olist = node.children(); + + for (oiter = olist.begin(); oiter != olist.end(); ++oiter) { + + option = *oiter; + + if (option->name() == _name) { + if ((opt_prop = option->property ("val")) != 0) { + value = ::string_is_affirmative (opt_prop->value()); + _owner = (ConfigVariableBase::Owner)(_owner |owner); + return true; + } + } + } + } + + return false; + } + + protected: + virtual bool get_for_save() { return value; } + bool value; +}; + template class ConfigVariableWithMutation : public ConfigVariable { diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index eccfc33d25..17ca139fb1 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -28,6 +28,11 @@ #include #endif +/* this needs to come before ardour.h, since it may include + headers that use this function. +*/ +bool string_is_affirmative (const std::string& str); + #include "ardour.h" class XMLNode; @@ -37,7 +42,6 @@ Glib::ustring legalize_for_path (Glib::ustring); void elapsed_time_to_str (char *buf, uint32_t seconds); std::ostream& operator<< (std::ostream& o, const ARDOUR::BBT_Time& bbt); XMLNode* find_named_node (const XMLNode& node, std::string name); -bool string_is_affirmative (const std::string& str); static inline float f_max(float x, float a) { x -= a; -- cgit v1.2.3