2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_configuration_variable_h__
21 #define __ardour_configuration_variable_h__
27 #include "pbd/xml++.h"
31 class ConfigVariableBase {
34 ConfigVariableBase (std::string str) : _name (str) {}
35 virtual ~ConfigVariableBase() {}
37 std::string name () const { return _name; }
38 void add_to_node (XMLNode&);
39 bool set_from_node (XMLNode const &);
41 virtual std::string get_as_string () const = 0;
42 virtual void set_from_string (std::string const &) = 0;
44 void show_stored_value (const std::string&);
46 static void set_show_stored_values (bool);
50 static bool show_stores;
57 class ConfigVariable : public ConfigVariableBase
61 ConfigVariable (std::string str) : ConfigVariableBase (str) {}
62 ConfigVariable (std::string str, T val) : ConfigVariableBase (str), value (val) {}
68 std::string get_as_string () const {
74 virtual bool set (T val) {
84 void set_from_string (std::string const & s) {
91 virtual T get_for_save() { return value; }
96 class ConfigVariableWithMutation : public ConfigVariable<T>
99 ConfigVariableWithMutation (std::string name, T val, T (*m)(T))
100 : ConfigVariable<T> (name, val), mutator (m) {}
103 if (unmutated_value != val) {
104 unmutated_value = val;
105 return ConfigVariable<T>::set (mutator (val));
111 virtual T get_for_save() { return unmutated_value; }
118 #endif /* __ardour_configuration_variable_h__ */