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;
40 class ConfigVariable : public ConfigVariableBase
43 ConfigVariable (std::string str) : ConfigVariableBase (str) {}
44 ConfigVariable (std::string str, T val) : ConfigVariableBase (str), value (val) {}
46 virtual bool set (T val, Owner owner) {
52 _owner = (ConfigVariableBase::Owner)(_owner |owner);
61 void add_to_node (XMLNode& node) {
64 cerr << "Config variable " << _name << " stored as " << ss.str() << endl;
65 XMLNode* child = new XMLNode ("Option");
66 child->add_property ("name", _name);
67 child->add_property ("value", ss.str());
68 node.add_child_nocopy (*child);
71 bool set_from_node (const XMLNode& node, Owner owner) {
73 if (node.name() == "Config") {
77 const XMLProperty* prop;
79 XMLNodeConstIterator niter;
82 nlist = node.children();
84 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
88 if (child->name() == "Option") {
89 if ((prop = child->property ("name")) != 0) {
90 if (prop->value() == _name) {
91 if ((prop = child->property ("value")) != 0) {
95 _owner = (ConfigVariableBase::Owner)(_owner |owner);
103 } else if (node.name() == "Options") {
108 XMLNodeConstIterator oiter;
110 const XMLProperty* opt_prop;
112 olist = node.children();
114 for (oiter = olist.begin(); oiter != olist.end(); ++oiter) {
118 if (option->name() == _name) {
119 if ((opt_prop = option->property ("val")) != 0) {
120 std::stringstream ss;
121 ss << opt_prop->value();
123 _owner = (ConfigVariableBase::Owner)(_owner |owner);
134 virtual T get_for_save() { return value; }
139 class ConfigVariableWithMutation : public ConfigVariable<T>
142 ConfigVariableWithMutation (std::string name, T val, T (*m)(T))
143 : ConfigVariable<T> (name, val), mutator (m) {}
145 bool set (T val, ConfigVariableBase::Owner owner) {
146 if (unmutated_value != val) {
147 unmutated_value = val;
148 return ConfigVariable<T>::set (mutator (val), owner);
154 virtual T get_for_save() { return unmutated_value; }
161 #endif /* __ardour_configuration_variable_h__ */