summaryrefslogtreecommitdiff
path: root/libs/pbd/pbd/properties.h
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-06-28 00:34:09 +0000
committerCarl Hetherington <carl@carlh.net>2010-06-28 00:34:09 +0000
commitc5bbca0cf560014e14d0d5863fb824952cb4908f (patch)
tree23a9399dfd1a70a5ed587d55475546cf671e78b9 /libs/pbd/pbd/properties.h
parent37978aa21437b9bb308efeb9828fbe4a06077cee (diff)
Add an EnumProperty for enumerated properties and hence make Region::position_lock_style a stateful property.
git-svn-id: svn://localhost/ardour2/branches/3.0@7306 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/pbd/properties.h')
-rw-r--r--libs/pbd/pbd/properties.h28
1 files changed, 26 insertions, 2 deletions
diff --git a/libs/pbd/pbd/properties.h b/libs/pbd/pbd/properties.h
index 1914344db9..03e42aa451 100644
--- a/libs/pbd/pbd/properties.h
+++ b/libs/pbd/pbd/properties.h
@@ -29,6 +29,7 @@
#include "pbd/xml++.h"
#include "pbd/property_basics.h"
#include "pbd/property_list.h"
+#include "pbd/enumwriter.h"
namespace PBD {
@@ -199,14 +200,14 @@ private:
* std::locale aborting on OS X if used with anything
* other than C or POSIX locales.
*/
- std::string to_string (T const& v) const {
+ virtual std::string to_string (T const& v) const {
std::stringstream s;
s.precision (12); // in case its floating point
s << v;
return s.str ();
}
- T from_string (std::string const& s) const {
+ virtual T from_string (std::string const& s) const {
std::stringstream t (s);
T v;
t >> v;
@@ -250,6 +251,29 @@ private:
};
+template<class T>
+class EnumProperty : public Property<T>
+{
+public:
+ EnumProperty (PropertyDescriptor<T> q, T const& v)
+ : Property<T> (q, v)
+ {}
+
+ T & operator=(T const& v) {
+ this->set (v);
+ return this->_current;
+ }
+
+private:
+ std::string to_string (T const & v) const {
+ return enum_2_string (v);
+ }
+
+ T from_string (std::string const & s) const {
+ return static_cast<T> (string_2_enum (s, this->_current));
+ }
+};
+
} /* namespace PBD */
#include "pbd/property_list_impl.h"