visitor.h
Go to the documentation of this file.
1 /************************************************************************************
2 * *
3 * Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
4 * *
5 * This file is part of RTTR (Run Time Type Reflection) *
6 * License: MIT License *
7 * *
8 * Permission is hereby granted, free of charge, to any person obtaining *
9 * a copy of this software and associated documentation files (the "Software"), *
10 * to deal in the Software without restriction, including without limitation *
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
12 * and/or sell copies of the Software, and to permit persons to whom the *
13 * Software is furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included in *
16 * all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
24 * SOFTWARE. *
25 * *
26 *************************************************************************************/
27 
28 #ifndef RTTR_VISITOR_H_
29 #define RTTR_VISITOR_H_
30 
31 #include "rttr/detail/base/core_prerequisites.h"
32 #include "rttr/rttr_enable.h"
33 #include "rttr/type_list.h"
34 #include "rttr/detail/visitor/visitor_registration.h"
35 
36 #include <type_traits>
37 #include <functional>
38 #include <tuple>
39 
40 namespace rttr
41 {
42 
43 class property;
44 class method;
45 class constructor;
46 
98 class RTTR_API visitor
99 {
100 public:
105  visitor();
106 
111  virtual ~visitor();
112 
118  void visit(type t);
119 
124  void visit(method meth);
125 
130  void visit(constructor ctor);
131 
140  void visit(property prop);
141 
142 #ifdef DOXYGEN
143 
147  template<typename T>
148  struct type_info
149  {
150  using declaring_type = T;
153  using base_classes = type_list<Base_Classes...>;
154  const type& type_item;
155  };
156 
161  template<typename T>
163  {
164  using declaring_type = T;
165  using policy = Policy;
167  };
168 
173  template<typename T>
175  {
176  using declaring_type = T;
177  using policy = Policy;
180  };
181 
186  template<typename T>
187  struct method_info
188  {
189  using declaring_type = T;
190  using policy = Policy;
193  };
194 
199  template<typename T>
201  {
202  using declaring_type = T;
203  using policy = Policy;
204  const property property_item;
206  };
207 
212  template<typename T>
214  {
215  using declaring_type = T;
216  using policy = Policy;
217  const property property_item;
220  };
221 #else
222  template<typename T>
223  struct type_info;
224 
225  template<typename T, typename...Base_Classes>
226  struct type_info<type_list<T, type_list<Base_Classes...>>>
227  {
228  using declaring_type = T;
229  using base_classes = type_list<Base_Classes...>;
230  const type& type_item;
231  };
232 
233  template<typename T>
234  struct constructor_info;
235 
236  template<typename T, typename Policy, typename...Ctor_args>
237  struct constructor_info<type_list<T, Policy, type_list<Ctor_args...>>>
238  {
239  using declaring_type = T;
240  using ctor_args = type_list<Ctor_args...>;
241  using policy = Policy;
242  const constructor& ctor_item;
243  };
244 
245  template<typename T>
246  struct constructor_function_info;
247 
248  template<typename T, typename Policy, typename Acc>
249  struct constructor_function_info<type_list<T, Policy, Acc>>
250  {
251  using declaring_type = T;
252  using policy = Policy;
253  const constructor ctor_item;
254  Acc function_ptr;
255  };
256 
257  template<typename T>
258  struct method_info;
259 
260  template<typename T, typename Policy, typename Acc>
261  struct method_info<type_list<T, Policy, Acc>>
262  {
263  using declaring_type = T;
264  using policy = Policy;
265  const method method_item;
266  Acc function_ptr;
267  };
268 
269  template<typename T>
270  struct property_info;
271 
272  template<typename T, typename Policy, typename Acc>
273  struct property_info<type_list<T, Policy, Acc>>
274  {
275  using declaring_type = T;
276  using policy = Policy;
277  const property property_item;
278  Acc property_accessor;
279  };
280 
281  template<typename T>
282  struct property_getter_setter_info;
283 
284  template<typename T, typename Policy, typename Getter, typename Setter>
285  struct property_getter_setter_info<type_list<T, Policy, Getter, Setter>>
286  {
287  using declaring_type = T;
288  using policy = Policy;
289  const property property_item;
290  Getter property_getter;
291  Setter property_setter;
292  };
293 #endif
294 
315  template<typename T, typename...Base_Classes>
316  void visit_type_begin(const type_info<T>& info);
317 
338  template<typename T, typename...Base_Classes>
339  void visit_type_end(const type_info<T>& info);
340 
355  template<typename T, typename...Ctor_Args>
356  void visit_constructor(const constructor_info<T>& info);
357 
371  template<typename T>
372  void visit_constructor_function(const constructor_function_info<T>& info);
373 
386  template<typename T>
387  void visit_method(const method_info<T>& info);
388 
401  template<typename T>
402  void visit_global_method(const method_info<T>& info);
403 
416  template<typename T>
417  void visit_property(const property_info<T>& info);
418 
431  template<typename T>
432  void visit_getter_setter_property(const property_getter_setter_info<T>& info);
433 
446  template<typename T>
447  void visit_global_property(const property_info<T>& info);
448 
461  template<typename T>
462  void visit_global_getter_setter_property(const property_getter_setter_info<T>& info);
463 
476  template<typename T>
477  void visit_readonly_property(const property_info<T>& info);
478 
491  template<typename T>
492  void visit_global_readonly_property(const property_info<T>& info);
493 
494 private:
495  void visit_impl(const type& t);
496 
497 private:
498  RTTR_ENABLE();
499 };
500 
501 } // end namespace rttr
502 
503 #include "rttr/detail/visitor/visitor_impl.h"
504 
505 #endif // RTTR_VISITOR_H_
T declaring_type
Definition: visitor.h:202
Definition: access_levels.h:33
The policy class contains all policies that can be used during the registration of reflection informa...
Definition: policy.h:49
Acc property_accessor
Definition: visitor.h:205
The type class holds the type information for any arbitrary object.
Definition: type.h:177
Policy policy
The used policy during registration.
Definition: visitor.h:177
The constructor_function_info class is used to forward all information during registration of a const...
Definition: visitor.h:174
Getter property_getter
Definition: visitor.h:218
The method_info class is used to forward all information during registration of a property...
Definition: visitor.h:213
T declaring_type
Definition: visitor.h:215
The method class provides several meta information about a method and can be invoked.
Definition: method.h:121
#define RTTR_ENABLE(...)
This macro is necessary in order to retrieve type information about the inheritance graph of a class...
Definition: rttr_enable.h:76
const constructor ctor_item
The constructor object.
Definition: visitor.h:178
The class visitor, is used for visiting your registered accessors of a type at compile time...
Definition: visitor.h:98
Policy policy
The used policy during registration.
Definition: visitor.h:190
T declaring_type
The type T where this method is declared to.
Definition: visitor.h:189
Policy policy
Definition: visitor.h:203
The method_info class is used to forward all information during registration of a method...
Definition: visitor.h:187
T declaring_type
The type T where this constructor is declared to.
Definition: visitor.h:164
T declaring_type
The type T where this constructor is declared to.
Definition: visitor.h:176
Setter property_setter
Definition: visitor.h:219
const property property_item
Definition: visitor.h:217
const type & type_item
The type object.
Definition: visitor.h:154
The constructor_info class is used to forward all information during registration of a constructor...
Definition: visitor.h:162
The property class provides several meta information about a property and gives read/write access to ...
Definition: property.h:117
Acc function_ptr
The function pointer of the method (can be a member- or free function)
Definition: visitor.h:192
The type_info class is used to forward all information during registration of a class.
Definition: visitor.h:148
T declaring_type
Definition: visitor.h:151
Policy policy
Definition: visitor.h:216
Acc function_ptr
The function pointer to create object T.
Definition: visitor.h:179
Contains a list of template parameters.
Definition: type_list.h:40
The constructor class provides several meta information about a constructor and can be invoked...
Definition: constructor.h:89
The property_info class is used to forward all information during registration of a property...
Definition: visitor.h:200
const method & method_item
The method object.
Definition: visitor.h:191
Policy policy
The used policy during registration.
Definition: visitor.h:165
const property property_item
Definition: visitor.h:204
const constructor & ctor_item
The constructor object.
Definition: visitor.h:166