Ardour  8.12
property_basics.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2014 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2013-2014 John Emmas <john@creativepost.co.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __libpbd_property_basics_h__
22 #define __libpbd_property_basics_h__
23 
24 #include <glib.h>
25 #include <set>
26 #include <vector>
27 #include <ostream>
28 
29 #include "pbd/libpbd_visibility.h"
30 #include "pbd/xml++.h"
31 
32 namespace PBD {
33 class LIBPBD_API Command;
34 class LIBPBD_API PropertyList;
35 class LIBPBD_API StatefulDiffCommand;
36 
38 typedef GQuark PropertyID;
39 
40 template<typename T>
42  PropertyDescriptor () : property_id (0) {}
43  PropertyDescriptor (PropertyID pid) : property_id (pid) {}
44 
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 
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  void dump (std::ostream& out) const { int n = 0; for (auto const & what_changed : *this) { if (n > 0) { out << ',' ; } out << g_quark_to_string (what_changed); ++n; } }
83 };
84 
91 {
92 public:
94  : _property_id (pid)
95  {}
96 
97  virtual ~PropertyBase () {}
98 
99 
100  /* MANAGEMENT OF Stateful STATE */
101 
105  virtual bool set_value (XMLNode const &) = 0;
106 
108  virtual void get_value (XMLNode& node) const = 0;
109 
110 
111  /* MANAGEMENT OF HISTORY */
112 
114  virtual void clear_changes () = 0;
115 
117  virtual void clear_owned_changes () {}
118 
122  virtual bool changed () const = 0;
123 
125  virtual void invert () = 0;
126 
127 
128  /* TRANSFERRING HISTORY TO / FROM A StatefulDiffCommand */
129 
133  virtual void get_changes_as_xml (XMLNode *) const = 0;
134 
138  virtual void get_changes_as_properties (PropertyList& changes, Command *) const = 0;
139 
141  virtual void rdiff (std::vector<PBD::Command*> &) const {}
142 
146  virtual PropertyBase* clone_from_xml (const XMLNode &) const { return 0; }
147 
148 
149  /* VARIOUS */
150 
151  virtual PropertyBase* clone () const = 0;
152 
154  virtual void apply_change (PropertyBase const *) = 0;
155 
156  const gchar* property_name () const { return g_quark_to_string (_property_id); }
157  PropertyID property_id () const { return _property_id; }
158 
159  bool operator==(PropertyID pid) const {
160  return _property_id == pid;
161  }
162 
163 protected:
164  /* copy construction only by subclasses */
166  : _property_id (b._property_id)
167  {}
168 
169 private:
171 
172 };
173 
174 }
175 
176 namespace std {
177 ostream& operator<< (std::ostream& os, PBD::PropertyChange const & pc);
178 }
179 
180 #endif /* __libpbd_property_basics_h__ */
virtual ~PropertyBase()
virtual void clear_owned_changes()
virtual void get_changes_as_properties(PropertyList &changes, Command *) const =0
virtual void get_value(XMLNode &node) const =0
virtual void rdiff(std::vector< PBD::Command * > &) const
PropertyID _property_id
virtual void apply_change(PropertyBase const *)=0
virtual bool changed() const =0
virtual void get_changes_as_xml(XMLNode *) const =0
virtual PropertyBase * clone() const =0
const gchar * property_name() const
PropertyBase(PropertyBase const &b)
virtual void invert()=0
virtual PropertyBase * clone_from_xml(const XMLNode &) const
virtual bool set_value(XMLNode const &)=0
PropertyBase(PropertyID pid)
virtual void clear_changes()=0
PropertyID property_id() const
bool operator==(PropertyID pid) const
LIBPBD_TEMPLATE_MEMBER_API ~PropertyChange()
void add(const PropertyChange &other)
LIBPBD_TEMPLATE_MEMBER_API PropertyChange operator=(const PropertyChange &other)
void dump(std::ostream &out) const
LIBPBD_TEMPLATE_MEMBER_API PropertyChange()
void add(PropertyID id)
LIBPBD_TEMPLATE_MEMBER_API PropertyChange(const PropertyChange &other)
LIBPBD_TEMPLATE_MEMBER_API bool contains(const PropertyChange &other) const
Definition: xml++.h:114
#define LIBPBD_TEMPLATE_API
#define LIBPBD_TEMPLATE_MEMBER_API
#define LIBPBD_API
void add(const Gtk::StockItem &item)
Definition: axis_view.h:42
GQuark PropertyID
PropertyDescriptor(PropertyID pid)