MIRA
PropertyReflector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_PROPERTYREFLECTOR_H_
48 #define _MIRA_PROPERTYREFLECTOR_H_
49 
50 #include <serialization/Accessor.h>
52 
53 namespace mira {
54 
56 
61 template <typename Derived>
63 {
65 
66 public:
67 
69  {
70  }
71 
72 public:
73 
74  template<typename T>
75  void member(const char* name, T& member, const char* comment,
78  roproperty(name, member, comment, PropertyHint(), flags);
79  }
80 
81  template<typename T>
82  void member(const char* name, const std::string& id, T& member,
83  const char* comment, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {
85  roproperty(name, id, member, comment, PropertyHint(), flags);
86  }
87 
88  template<typename T>
89  void member(const char* name, const T& member, Setter<T> setter,
90  const char* comment, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {
92  roproperty(name, member, comment, PropertyHint(), flags);
93  }
94 
95  template<typename T>
96  void member(const char* name, Getter<T> getter, Setter<T> setter,
97  const char* comment, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {
99  roproperty(name, getter, comment, PropertyHint(), flags);
100  }
101 
102  template<typename T, typename U>
103  void member(const char* name, T& member, const char* comment,
104  const U& defaultValue, ReflectCtrlFlags flags = REFLECT_CTRLFLAG_NONE) {
106  roproperty(name, member, comment, PropertyHint(), flags);
107  }
108 
109  template<typename T, typename U>
110  void member(const char* name, const T& member, Setter<T> setter,
111  const char* comment, const U& defaultValue,
114  roproperty(name, member, comment, PropertyHint(), flags);
115  }
116 
117  template<typename T, typename U>
118  void member(const char* name, Getter<T> getter, Setter<T> setter,
119  const char* comment, const U& defaultValue,
122  roproperty(name, getter, comment, PropertyHint(), flags);
123  }
124 
125  template<typename T>
126  void property(const char* name, T& member, const char* comment,
127  PropertyHint&& hint = PropertyHint(),
129  if (flags & REFLECT_CTRLFLAG_TEMP_TRACKING) {
130  this->This()->pushObjectTrackingStore();
131  invokePropertyMember(member, ReflectMemberMeta(name, name, comment),
132  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
133  this->This()->popObjectTrackingStore();
134  } else
135  invokePropertyMember(member, ReflectMemberMeta(name, name, comment),
136  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
137  }
138 
139  template<typename T>
140  void property(const char* name, const std::string& id, T& member,
141  const char* comment, PropertyHint&& hint = PropertyHint(),
143  if (flags & REFLECT_CTRLFLAG_TEMP_TRACKING) {
144  this->This()->pushObjectTrackingStore();
145  invokePropertyMember(member, ReflectMemberMeta(name, id.c_str(), comment),
146  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
147  this->This()->popObjectTrackingStore();
148  } else
149  invokePropertyMember(member, ReflectMemberMeta(name, id.c_str(), comment),
150  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
151  }
152 
153  template<typename T>
154  void property(const char* name, const T& member, Setter<T> setter,
155  const char* comment, PropertyHint&& hint = PropertyHint(),
157  auto a = makeAccessor(member, setter);
158  this->This()->pushObjectTrackingStore();
159  invokePropertyMember(a, ReflectMemberMeta(name, name, comment),
160  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
161  this->This()->popObjectTrackingStore();
162  }
163 
164  template<typename T>
165  void property(const char* name, Getter<T> getter, Setter<T> setter,
166  const char* comment, PropertyHint&& hint = PropertyHint(),
168  auto a = makeAccessor(getter, setter);
169  this->This()->pushObjectTrackingStore();
170  invokePropertyMember(a, ReflectMemberMeta(name, name, comment),
171  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
172  this->This()->popObjectTrackingStore();
173  }
174 
175  template<typename T, typename U>
176  void property(const char* name, T& member, const char* comment,
177  const U& defaultValue, PropertyHint&& hint = PropertyHint(),
179  if (flags & REFLECT_CTRLFLAG_TEMP_TRACKING) {
180  this->This()->pushObjectTrackingStore();
181  invokePropertyMember(member, ReflectMemberMeta(name, name, comment),
182  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
183  this->This()->popObjectTrackingStore();
184  } else
185  invokePropertyMember(member, ReflectMemberMeta(name, name, comment),
186  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
187  }
188 
189  template<typename T, typename U>
190  void property(const char* name, const T& member, Setter<T> setter,
191  const char* comment, const U& defaultValue, PropertyHint&& hint = PropertyHint(),
193  auto a = makeAccessor(member, setter);
194  this->This()->pushObjectTrackingStore();
195  invokePropertyMember(a, ReflectMemberMeta(name, name, comment),
196  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
197  this->This()->popObjectTrackingStore();
198  }
199 
200  template<typename T, typename U>
201  void property(const char* name, Getter<T> getter, Setter<T> setter,
202  const char* comment, const U& defaultValue,
203  PropertyHint&& hint = PropertyHint(),
205  auto a = makeAccessor(getter, setter);
206  this->This()->pushObjectTrackingStore();
207  invokePropertyMember(a, ReflectMemberMeta(name, name, comment),
208  std::move(hint), false, flags & REFLECT_CTRLFLAG_VOLATILE);
209  this->This()->popObjectTrackingStore();
210  }
211 
212  template<typename T>
213  void roproperty(const char* name, const T& member, const char* comment,
214  PropertyHint&& hint = PropertyHint(),
216  // cast away constness, this is okay, since read only properties we
217  // will never write to the data
218  if (flags & REFLECT_CTRLFLAG_TEMP_TRACKING) {
219  this->This()->pushObjectTrackingStore();
220  invokePropertyMember(const_cast<T&>(member),
221  ReflectMemberMeta(name, name, comment),
222  std::move(hint), true, flags & REFLECT_CTRLFLAG_VOLATILE);
223  this->This()->popObjectTrackingStore();
224  } else
225  invokePropertyMember(const_cast<T&>(member),
226  ReflectMemberMeta(name, name, comment),
227  std::move(hint), true, flags & REFLECT_CTRLFLAG_VOLATILE);
228  }
229 
230  template<typename T>
231  void roproperty(const char* name, const std::string& id, const T& member,
232  const char* comment, PropertyHint&& hint = PropertyHint(),
234  // cast away constness, this is okay, since read only properties we
235  // will never write to the data
236  if (flags & REFLECT_CTRLFLAG_TEMP_TRACKING) {
237  this->This()->pushObjectTrackingStore();
238  invokePropertyMember(const_cast<T&>(member),
239  ReflectMemberMeta(name, id.c_str(), comment),
240  std::move(hint), true, flags & REFLECT_CTRLFLAG_VOLATILE);
241  this->This()->popObjectTrackingStore();
242  } else
243  invokePropertyMember(const_cast<T&>(member),
244  ReflectMemberMeta(name, id.c_str(), comment),
245  std::move(hint), true, flags & REFLECT_CTRLFLAG_VOLATILE);
246  }
247 
248  template<typename T>
249  void roproperty(const char* name, Getter<T> getter, const char* comment,
250  PropertyHint&& hint = PropertyHint(),
252  auto a = makeAccessor(getter, NullSetter<T>());
253  this->This()->pushObjectTrackingStore();
254  invokePropertyMember(a, ReflectMemberMeta(name, name, comment),
255  std::move(hint), true, flags & REFLECT_CTRLFLAG_VOLATILE);
256  this->This()->popObjectTrackingStore();
257  }
258 
259  template<typename T>
261  if (flags & REFLECT_CTRLFLAG_TEMP_TRACKING) {
262  this->This()->pushObjectTrackingStore();
263  invokePropertyMember(member, ReflectMemberMeta(NULL, NULL, ""),
264  PropertyHint(), false, flags & REFLECT_CTRLFLAG_VOLATILE);
265  this->This()->popObjectTrackingStore();
266  } else
267  invokePropertyMember(member, ReflectMemberMeta(NULL, NULL, ""),
268  PropertyHint(), false, flags & REFLECT_CTRLFLAG_VOLATILE);
269  }
270 
271  template<typename T>
272  void delegate(const T& member, Setter<T> setter,
274  auto a = makeAccessor(member, setter);
275  this->This()->pushObjectTrackingStore();
276  invokePropertyMember(a, ReflectMemberMeta(NULL, NULL, ""),
277  PropertyHint(), false, flags & REFLECT_CTRLFLAG_VOLATILE);
278  this->This()->popObjectTrackingStore();
279  }
280 
281  template<typename T>
284  auto a = makeAccessor(getter, setter);
285  this->This()->pushObjectTrackingStore();
286  invokePropertyMember(a, ReflectMemberMeta(NULL, NULL, ""),
287  PropertyHint(), false, flags & REFLECT_CTRLFLAG_VOLATILE);
288  this->This()->popObjectTrackingStore();
289  }
290 
291 
292 public:
293 
300  template<typename T>
302  {
303  static_assert(sizeof(T)==0, "This method should never be called, since"
304  " the PropertyReflector and derived classes uses their own"
305  " invokePropertyMember mechanism to invoke the"
306  " reflector and bypasses the invokeMember() /"
307  " invokeMemberOverwrite() methods");
308  }
309 
320  template<typename T>
322  PropertyHint&& hint, bool isReadOnly, bool isVolatile)
323  {
324  // delegate to the most derived invokePropertyMemberOverwrite
325  this->This()->invokePropertyMemberOverwrite(member, meta, std::move(hint),
326  isReadOnly, isVolatile);
327  }
328 
336  template<typename T>
338  PropertyHint&& hint, bool isReadOnly,
339  bool isVolatile)
340  {
341  // delegate to the real reflector invoke
343  }
344 };
345 
347 
348 } // namespace
349 
350 #endif
This object can use object tracking internally, but the object tracking system&#39;s state remains unchan...
Definition: ReflectControlFlags.h:82
void invokeMemberOverwrite(T &member, const ReflectMemberMeta &meta)
This method should never be called, since the PropertyReflector and derived classes uses their own in...
Definition: PropertyReflector.h:301
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:118
void property(const char *name, T &member, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:176
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void member(const char *name, const std::string &id, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:82
Setter< T > setter(void(*f)(const T &))
Creates a Setter for global or static class methods taking the argument by const reference.
Definition: GetterSetter.h:443
void delegate(Getter< T > getter, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:282
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
Stores meta information for each member.
Definition: ReflectMemberMeta.h:64
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:75
Contains internal accessor class that abstracts from the underlying getter and setter classes or dire...
A property hint gives optional instructions to the property editor, i.e.
Definition: PropertyHint.h:82
Derived * This()
"Curiously recurring template pattern" (CRTP).
Definition: AbstractReflector.h:246
void delegate(const T &member, Setter< T > setter, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:272
boost::mpl::bool_< true > isReadOnly
Specifies, if the Reflector is read-only (true) or write-only (false).
Definition: ReflectorInterface.h:121
void member(const char *name, T &member, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:103
void roproperty(const char *name, Getter< T > getter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:249
No flags.
Definition: ReflectControlFlags.h:65
void invokePropertyMember(T &member, const ReflectMemberMeta &meta, PropertyHint &&hint, bool isReadOnly, bool isVolatile)
Invokes the serializer.
Definition: PropertyReflector.h:321
void roproperty(const char *name, const T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:213
void property(const char *name, const T &member, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:154
Getter< T > getter(T(*f)())
Creates a Getter for global or static class methods returning the result by value.
Definition: GetterSetter.h:136
The RecursiveMemberReflectorBase is a base class for all Reflectors that are used to visit the reflec...
Definition: RecursiveMemberReflector.h:233
void member(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:110
This object is volatile: its memory location may become invalid to access.
Definition: ReflectControlFlags.h:90
void delegate(T &member, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:260
void property(const char *name, const std::string &id, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:140
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
Base class for all Reflectors that take care of properties.
Definition: PropertyReflector.h:62
void invokeMemberOverwrite(T &member, const ReflectMemberMeta &meta)
The actual invokeMember implementation that is called from invokeMember().
Definition: RecursiveMemberReflector.h:665
ReflectCtrlFlags
Control Flags that can modify the behavior of certain reflectors.
Definition: ReflectControlFlags.h:63
void roproperty(const char *name, const std::string &id, const T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:231
"Null-Setter" tag-class where the AccessorSetterPart does nothing.
Definition: Accessor.h:198
void member(const char *name, const T &member, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:89
Accessor< Getter, Setter > makeAccessor(const Getter &getter, const Setter &setter)
Helper method that creates an accessor from a different combination of either direct access to a vari...
Definition: Accessor.h:300
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:126
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:201
void property(const char *name, const T &member, Setter< T > setter, const char *comment, const U &defaultValue, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:190
void property(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:165
PropertyReflector()
Definition: PropertyReflector.h:68
When this flag is used in calls to Reflector::member(), that member is also reflected as read-only pr...
Definition: ReflectControlFlags.h:103
void invokePropertyMemberOverwrite(T &member, const ReflectMemberMeta &meta, PropertyHint &&hint, bool isReadOnly, bool isVolatile)
Is called by invokePropertyMember.
Definition: PropertyReflector.h:337
void member(const char *name, Getter< T > getter, Setter< T > setter, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:96