1 #ifndef __ardour_configuration_variable_h__
2 #define __ardour_configuration_variable_h__
11 class ConfigVariableBase {
21 ConfigVariableBase (std::string str) : _name (str), _owner (Default) {}
22 virtual ~ConfigVariableBase() {}
24 std::string name() const { return _name; }
25 Owner owner() const { return _owner; }
27 virtual void add_to_node (XMLNode& node) = 0;
28 virtual bool set_from_node (const XMLNode& node, Owner owner) = 0;
30 void show_stored_value (const std::string&);
31 static void set_show_stored_values (bool yn);
36 static bool show_stores;
43 class ConfigVariable : public ConfigVariableBase
46 ConfigVariable (std::string str) : ConfigVariableBase (str) {}
47 ConfigVariable (std::string str, T val) : ConfigVariableBase (str), value (val) {}
49 virtual bool set (T val, Owner owner) {
55 _owner = (ConfigVariableBase::Owner)(_owner |owner);
64 void add_to_node (XMLNode& node) {
67 show_stored_value (ss.str());
68 XMLNode* child = new XMLNode ("Option");
69 child->add_property ("name", _name);
70 child->add_property ("value", ss.str());
71 node.add_child_nocopy (*child);
74 bool set_from_node (const XMLNode& node, Owner owner) {
76 if (node.name() == "Config") {
80 const XMLProperty* prop;
82 XMLNodeConstIterator niter;
85 nlist = node.children();
87 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
91 if (child->name() == "Option") {
92 if ((prop = child->property ("name")) != 0) {
93 if (prop->value() == _name) {
94 if ((prop = child->property ("value")) != 0) {
98 _owner = (ConfigVariableBase::Owner)(_owner |owner);
106 } else if (node.name() == "Options") {
111 XMLNodeConstIterator oiter;
113 const XMLProperty* opt_prop;
115 olist = node.children();
117 for (oiter = olist.begin(); oiter != olist.end(); ++oiter) {
121 if (option->name() == _name) {
122 if ((opt_prop = option->property ("val")) != 0) {
123 std::stringstream ss;
124 ss << opt_prop->value();
126 _owner = (ConfigVariableBase::Owner)(_owner |owner);
137 virtual T get_for_save() { return value; }
142 class ConfigVariableWithMutation : public ConfigVariable<T>
145 ConfigVariableWithMutation (std::string name, T val, T (*m)(T))
146 : ConfigVariable<T> (name, val), mutator (m) {}
148 bool set (T val, ConfigVariableBase::Owner owner) {
149 if (unmutated_value != val) {
150 unmutated_value = val;
151 return ConfigVariable<T>::set (mutator (val), owner);
157 virtual T get_for_save() { return unmutated_value; }
164 #endif /* __ardour_configuration_variable_h__ */