2 Copyright (C) 2010 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 __libpbd_property_basics_h__
21 #define __libpbd_property_basics_h__
26 #include "pbd/xml++.h"
31 typedef GQuark PropertyID;
34 struct PropertyDescriptor {
35 PropertyDescriptor () : property_id (0) {}
36 PropertyDescriptor (PropertyID pid) : property_id (pid) {}
38 PropertyID property_id;
42 class PropertyChange : public std::set<PropertyID>
47 template<typename T> PropertyChange(PropertyDescriptor<T> p);
49 PropertyChange(const PropertyChange& other) : std::set<PropertyID> (other) {}
51 PropertyChange operator=(const PropertyChange& other) {
53 insert (other.begin (), other.end ());
57 template<typename T> PropertyChange operator=(PropertyDescriptor<T> p);
58 template<typename T> bool contains (PropertyDescriptor<T> p) const;
60 bool contains (const PropertyChange& other) const {
61 for (const_iterator x = other.begin (); x != other.end (); ++x) {
62 if (find (*x) != end ()) {
69 void add (PropertyID id) { insert (id); }
70 void add (const PropertyChange& other) { insert (other.begin (), other.end ()); }
71 template<typename T> void add (PropertyDescriptor<T> p);
74 /** Base (non template) part of Property */
78 PropertyBase (PropertyID pid)
83 /** Forget about any old value for this state */
84 virtual void clear_history () {
88 virtual void add_history_state (XMLNode*) const = 0;
89 virtual void diff (PropertyList&, PropertyList&) const = 0;
91 virtual PropertyBase* maybe_clone_self_if_found_in_history_node (const XMLNode&) const { return 0; }
93 virtual bool set_state_from_owner_state (XMLNode const&) = 0;
94 virtual void add_state_to_owner_state (XMLNode&) const = 0;
96 const gchar*property_name () const { return g_quark_to_string (_property_id); }
97 PropertyID property_id () const { return _property_id; }
99 bool operator==(PropertyID pid) const {
100 return _property_id == pid;
104 PropertyID _property_id;
108 class PropertyFactory
111 static PropertyBase* create (const XMLNode&);
116 #endif /* __libpbd_property_basics_h__ */