From c5bbca0cf560014e14d0d5863fb824952cb4908f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 28 Jun 2010 00:34:09 +0000 Subject: 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 --- libs/pbd/pbd/properties.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'libs/pbd/pbd/properties.h') 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 EnumProperty : public Property +{ +public: + EnumProperty (PropertyDescriptor q, T const& v) + : Property (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 (string_2_enum (s, this->_current)); + } +}; + } /* namespace PBD */ #include "pbd/property_list_impl.h" -- cgit v1.2.3