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;
36 class ConfigVariable : public ConfigVariableBase
39 ConfigVariable (std::string str) : ConfigVariableBase (str) {}
40 ConfigVariable (std::string str, T val) : ConfigVariableBase (str), value (val) {}
42 virtual bool set (T val, Owner owner) {
47 _owner = (ConfigVariableBase::Owner)(_owner |owner);
55 void add_to_node (XMLNode& node) {
58 XMLNode* child = new XMLNode ("Option");
59 child->add_property ("name", _name);
60 child->add_property ("value", ss.str());
61 node.add_child_nocopy (*child);
64 bool set_from_node (const XMLNode& node, Owner owner) {
66 if (node.name() == "Config") {
70 const XMLProperty* prop;
72 XMLNodeConstIterator niter;
75 nlist = node.children();
77 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
81 if (child->name() == "Option") {
82 if ((prop = child->property ("name")) != 0) {
83 if (prop->value() == _name) {
84 if ((prop = child->property ("value")) != 0) {
88 _owner = (ConfigVariableBase::Owner)(_owner |owner);
96 } else if (node.name() == "Options") {
101 XMLNodeConstIterator oiter;
103 const XMLProperty* opt_prop;
105 olist = node.children();
107 for (oiter = olist.begin(); oiter != olist.end(); ++oiter) {
111 if (option->name() == _name) {
112 if ((opt_prop = option->property ("val")) != 0) {
113 std::stringstream ss;
114 ss << opt_prop->value();
116 _owner = (ConfigVariableBase::Owner)(_owner |owner);
127 virtual T get_for_save() { return value; }
132 class ConfigVariableWithMutation : public ConfigVariable<T>
135 ConfigVariableWithMutation (std::string name, T val, T (*m)(T))
136 : ConfigVariable<T> (name, val), mutator (m) {}
138 bool set (T val, ConfigVariableBase::Owner owner) {
139 if (unmutated_value != val) {
140 unmutated_value = val;
141 return ConfigVariable<T>::set (mutator (val), owner);
147 virtual T get_for_save() { return unmutated_value; }
154 #endif /* __ardour_configuration_variable_h__ */