forward port ConfigVariable<bool> fix from 2.X

git-svn-id: svn://localhost/ardour2/branches/3.0@7216 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis
2010-06-02 19:54:05 +00:00
parent 71c876109f
commit baacf1c7b4
2 changed files with 40 additions and 1 deletions

View File

@@ -25,6 +25,7 @@
#include "pbd/xml++.h"
#include "ardour/types.h"
#include "ardour/utils.h"
namespace ARDOUR {
@@ -87,6 +88,43 @@ class ConfigVariable : public ConfigVariableBase
T value;
};
template<>
class ConfigVariable<bool> : public ConfigVariableBase
{
public:
ConfigVariable (std::string str) : ConfigVariableBase (str), value (false) {}
ConfigVariable (std::string str, bool val) : ConfigVariableBase (str), value (val) {}
bool get() const {
return value;
}
std::string get_as_string () const {
std::ostringstream ss;
ss << value;
return ss.str ();
}
virtual bool set (bool val) {
if (val == value) {
miss ();
return false;
}
value = val;
notify ();
return true;
}
void set_from_string (std::string const & s) {
value = string_is_affirmative (s);
}
protected:
virtual bool get_for_save() { return value; }
bool value;
};
template<class T>
class ConfigVariableWithMutation : public ConfigVariable<T>
{

View File

@@ -32,6 +32,8 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
bool string_is_affirmative (const std::string&);
#include "ardour.h"
class XMLNode;
@@ -39,7 +41,6 @@ class XMLNode;
Glib::ustring legalize_for_path (Glib::ustring str);
XMLNode* find_named_node (const XMLNode& node, std::string name);
std::string bool_as_string (bool);
bool string_is_affirmative (const std::string&);
static inline float f_max(float x, float a) {
x -= a;