1 #ifndef __ardour_configuration_variable_h__
2 #define __ardour_configuration_variable_h__
11 class ConfigVariableBase {
13 ConfigVariableBase (std::string str) : _name (str), _is_user (false) {}
14 virtual ~ConfigVariableBase() {}
16 std::string name() const { return _name; }
17 bool is_user() const { return _is_user; }
18 void set_is_user (bool yn) { _is_user = yn; }
20 virtual void add_to_node (XMLNode& node) = 0;
21 virtual bool set_from_node (const XMLNode& node) = 0;
29 class ConfigVariable : public ConfigVariableBase
32 ConfigVariable (std::string str) : ConfigVariableBase (str) {}
33 ConfigVariable (std::string str, T val) : ConfigVariableBase (str), value (val) {}
35 virtual void set (T val) {
43 void add_to_node (XMLNode& node) {
46 XMLNode* child = new XMLNode ("Option");
47 child->add_property ("name", _name);
48 child->add_property ("value", ss.str());
49 node.add_child_nocopy (*child);
52 bool set_from_node (const XMLNode& node) {
53 const XMLProperty* prop;
55 XMLNodeConstIterator niter;
58 nlist = node.children();
60 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
64 if (child->name() == "Option") {
65 if ((prop = child->property ("name")) != 0) {
66 if (prop->value() == _name) {
67 if ((prop = child->property ("value")) != 0) {
82 virtual T get_for_save() { return value; }
87 class ConfigVariableWithMutation : public ConfigVariable<T>
90 ConfigVariableWithMutation (std::string name, T val, T (*m)(T))
91 : ConfigVariable<T> (name, val), mutator (m) {}
94 unmutated_value = val;
95 ConfigVariable<T>::set (mutator (val));
99 virtual T get_for_save() { return unmutated_value; }
106 #endif /* __ardour_configuration_variable_h__ */