ardour
property_basics.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #ifndef __libpbd_property_basics_h__
21 #define __libpbd_property_basics_h__
22 
23 #include <glib.h>
24 #include <set>
25 #include <vector>
26 
27 #include "pbd/libpbd_visibility.h"
28 #include "pbd/xml++.h"
29 
30 class Command;
31 
32 namespace PBD {
33 
36 
38 typedef GQuark PropertyID;
39 
40 template<typename T>
42  PropertyDescriptor () : property_id (0) {}
43  PropertyDescriptor (PropertyID pid) : property_id (pid) {}
44 
45  PropertyID property_id;
46  typedef T value_type;
47 };
48 
50 class LIBPBD_TEMPLATE_API PropertyChange : public std::set<PropertyID>
51 {
52 public:
55 
56  template<typename T> PropertyChange(PropertyDescriptor<T> p);
57 
58  LIBPBD_TEMPLATE_MEMBER_API PropertyChange(const PropertyChange& other) : std::set<PropertyID> (other) {}
59 
61  clear ();
62  insert (other.begin (), other.end ());
63  return *this;
64  }
65 
66  template<typename T> PropertyChange operator=(PropertyDescriptor<T> p);
67  template<typename T> bool contains (PropertyDescriptor<T> p) const;
68 
70  for (const_iterator x = other.begin (); x != other.end (); ++x) {
71  if (find (*x) != end ()) {
72  return true;
73  }
74  }
75  return false;
76  }
77 
78  void add (PropertyID id) { insert (id); }
79  void add (const PropertyChange& other) { insert (other.begin (), other.end ()); }
80  template<typename T> void add (PropertyDescriptor<T> p);
81 };
82 
89 {
90 public:
91  PropertyBase (PropertyID pid)
92  : _property_id (pid)
93  {}
94 
95  virtual ~PropertyBase () {}
96 
97 
98  /* MANAGEMENT OF Stateful STATE */
99 
103  virtual bool set_value (XMLNode const &) = 0;
104 
106  virtual void get_value (XMLNode& node) const = 0;
107 
108 
109  /* MANAGEMENT OF HISTORY */
110 
112  virtual void clear_changes () = 0;
113 
115  virtual void clear_owned_changes () {}
116 
120  virtual bool changed () const = 0;
121 
123  virtual void invert () = 0;
124 
125 
126  /* TRANSFERRING HISTORY TO / FROM A StatefulDiffCommand */
127 
131  virtual void get_changes_as_xml (XMLNode *) const = 0;
132 
136  virtual void get_changes_as_properties (PropertyList& changes, Command *) const = 0;
137 
139  virtual void rdiff (std::vector<Command*> &) const {}
140 
144  virtual PropertyBase* clone_from_xml (const XMLNode &) const { return 0; }
145 
146 
147  /* VARIOUS */
148 
149  virtual PropertyBase* clone () const = 0;
150 
152  virtual void apply_changes (PropertyBase const *) = 0;
153 
154  const gchar* property_name () const { return g_quark_to_string (_property_id); }
155  PropertyID property_id () const { return _property_id; }
156 
157  bool operator==(PropertyID pid) const {
158  return _property_id == pid;
159  }
160 
161 protected:
162  /* copy construction only by subclasses */
164  : _property_id (b._property_id)
165  {}
166 
167 private:
168  PropertyID _property_id;
169 
170 };
171 
172 }
173 
174 #endif /* __libpbd_property_basics_h__ */
bool operator==(PropertyID pid) const
LIBPBD_TEMPLATE_MEMBER_API PropertyChange operator=(const PropertyChange &other)
#define LIBPBD_API
LIBPBD_TEMPLATE_MEMBER_API bool contains(const PropertyChange &other) const
virtual void clear_owned_changes()
PropertyBase(PropertyBase const &b)
#define LIBPBD_TEMPLATE_MEMBER_API
Definition: Beats.hpp:239
GQuark PropertyID
PropertyID property_id() const
LIBPBD_TEMPLATE_MEMBER_API ~PropertyChange()
virtual void rdiff(std::vector< Command * > &) const
LIBPBD_TEMPLATE_MEMBER_API PropertyChange(const PropertyChange &other)
virtual ~PropertyBase()
#define LIBPBD_TEMPLATE_API
const gchar * property_name() const
virtual PropertyBase * clone_from_xml(const XMLNode &) const
void add(const PropertyChange &other)
Definition: xml++.h:95
PropertyDescriptor(PropertyID pid)
Definition: debug.h:30
LIBPBD_TEMPLATE_MEMBER_API PropertyChange()
PropertyID _property_id
static LilvNode * get_value(LilvWorld *world, const LilvNode *subject, const LilvNode *predicate)
Definition: lv2_plugin.cc:971
PropertyBase(PropertyID pid)
void add(PropertyID id)