Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
22 
23 #include <glib.h>
24 #include <set>
25 #include <vector>
26 #include <ostream>
27 
28 #include "pbd/libpbd_visibility.h"
29 #include "pbd/xml++.h"
30 
31 namespace PBD {
32 class LIBPBD_API Command;
33 class LIBPBD_API PropertyList;
34 class LIBPBD_API StatefulDiffCommand;
35 
37 typedef GQuark PropertyID;
38 
39 template<typename T>
41  PropertyDescriptor () : property_id (0) {}
42  PropertyDescriptor (PropertyID pid) : property_id (pid) {}
43 
45  typedef T value_type;
46 };
47 
49 class LIBPBD_TEMPLATE_API PropertyChange : public std::set<PropertyID>
50 {
51 public:
54 
55  template<typename T> PropertyChange(PropertyDescriptor<T> p);
56 
58 
60  clear ();
61  insert (other.begin (), other.end ());
62  return *this;
63  }
64 
65  template<typename T> PropertyChange operator=(PropertyDescriptor<T> p);
66  template<typename T> bool contains (PropertyDescriptor<T> p) const;
67 
69  for (const_iterator x = other.begin (); x != other.end (); ++x) {
70  if (find (*x) != end ()) {
71  return true;
72  }
73  }
74  return false;
75  }
76 
77  void add (PropertyID id) { insert (id); }
78  void add (const PropertyChange& other) { insert (other.begin (), other.end ()); }
79  template<typename T> void add (PropertyDescriptor<T> p);
80 
81  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; } }
82 };
83 
90 {
91 public:
93  : _property_id (pid)
94  {}
95 
96  virtual ~PropertyBase () {}
97 
98 
99  /* MANAGEMENT OF Stateful STATE */
100 
104  virtual bool set_value (XMLNode const &) = 0;
105 
107  virtual void get_value (XMLNode& node) const = 0;
108 
109 
110  /* MANAGEMENT OF HISTORY */
111 
113  virtual void clear_changes () = 0;
114 
116  virtual void clear_owned_changes () {}
117 
121  virtual bool changed () const = 0;
122 
124  virtual void invert () = 0;
125 
126 
127  /* TRANSFERRING HISTORY TO / FROM A StatefulDiffCommand */
128 
132  virtual void get_changes_as_xml (XMLNode *) const = 0;
133 
137  virtual void get_changes_as_properties (PropertyList& changes, Command *) const = 0;
138 
140  virtual void rdiff (std::vector<PBD::Command*> &) const {}
141 
145  virtual PropertyBase* clone_from_xml (const XMLNode &) const { return 0; }
146 
147 
148  /* VARIOUS */
149 
150  virtual PropertyBase* clone () const = 0;
151 
153  virtual void apply_change (PropertyBase const *) = 0;
154 
155  const gchar* property_name () const { return g_quark_to_string (_property_id); }
156  PropertyID property_id () const { return _property_id; }
157 
158  bool operator==(PropertyID pid) const {
159  return _property_id == pid;
160  }
161 
162 protected:
163  /* copy construction only by subclasses */
165  : _property_id (b._property_id)
166  {}
167 
168 private:
170 
171 };
172 
173 }
174 
175 namespace std {
176 ostream& operator<< (std::ostream& os, PBD::PropertyChange const & pc);
177 }
178 
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)