registration.h Source File - 0.9.5 |RTTR
registration.h
Go to the documentation of this file.
1 /************************************************************************************
2 * *
3 * Copyright (c) 2014, 2015 - 2016 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_REGISTRATION_H_
29 #define RTTR_REGISTRATION_H_
30 
31 #include "rttr/detail/base/core_prerequisites.h"
32 #include "rttr/policy.h"
33 #include "rttr/access_levels.h"
34 #include "rttr/detail/registration/bind_types.h"
35 #include "rttr/detail/registration/registration_executer.h"
36 #include "rttr/detail/default_arguments/default_arguments.h"
37 #include "rttr/detail/parameter_info/parameter_names.h"
38 #include "rttr/variant.h"
39 
40 namespace rttr
41 {
42 
43 namespace detail
44 {
45  class metadata;
46  template<typename Enum_Type>
47  class enum_data;
48  struct public_access {};
49  struct protected_access {};
50  struct private_access {};
51  using access_levels_list = type_list<public_access, protected_access, private_access>;
52 }
53 
119 class RTTR_API registration
120 {
121 public:
122  template<typename...T>
123  class bind;
124 
128  template<typename Class_Type>
129  class class_
130  {
131  public:
138  class_(const char* name);
139  ~class_();
140 
141 
146  template<typename...Args>
147  class_<Class_Type>& operator()(Args&&...args);
148 
149 
162  template<typename... Args, typename acc_level = detail::public_access, typename Tp = typename std::enable_if<detail::contains<acc_level, detail::access_levels_list>::value>::type>
163  bind<detail::ctor, Class_Type, acc_level, Args...> constructor(acc_level level = acc_level());
164 
178  bind<detail::ctor_func, Class_Type, F, acc_level> constructor(F func, acc_level level = acc_level());
179 
180 
196  bind<detail::prop, Class_Type, A, acc_level> property(const char* name, A acc, acc_level level = acc_level());
197 
214  bind<detail::prop_readonly, Class_Type, A, acc_level> property_readonly(const char* name, A acc, acc_level level = acc_level());
215 
234  bind<detail::prop, Class_Type, A1, A2, acc_level> property(const char* name, A1 getter, A2 setter, acc_level level = acc_level());
235 
236 
251  template<typename F, typename acc_level = detail::public_access>
252  bind<detail::meth, Class_Type, F, acc_level> method(const char* name, F f, acc_level level = acc_level());
253 
254 
264  template<typename Enum_Type>
266  private:
267  class_(const std::shared_ptr<detail::registration_executer>& reg_exec);
268  class_(const class_& other);
269  class_& operator=(const class_& other);
270  private:
271  std::shared_ptr<detail::registration_executer> m_reg_exec;
272  template<typename...T>
273  friend class bind;
274  };
275 
290  template<typename A>
291  static bind<detail::prop, void, A, detail::public_access> property(const char* name, A acc);
292 
308  template<typename A>
309  static bind<detail::prop_readonly, void, A, detail::public_access> property_readonly(const char* name, A acc);
310 
326  template<typename A1, typename A2>
327  static bind<detail::prop, void, A1, A2, detail::public_access> property(const char* name, A1 getter, A2 setter);
328 
342  template<typename F>
343  static bind<detail::meth, void, F, detail::public_access> method(const char* name, F f);
344 
356  template<typename Enum_Type>
357  static bind<detail::enum_, void, Enum_Type> enumeration(const char* name);
358 
360 
383 
409 
435 
436 private:
437  registration() {}
438  registration(const std::shared_ptr<detail::registration_executer>& reg_exec) : m_reg_exec(reg_exec) { }
439  registration(const registration& other);
440  registration& operator=(const registration& other);
441 
442 private:
443  std::shared_ptr<detail::registration_executer> m_reg_exec;
444  template<typename...T>
445  friend class bind;
446 };
447 
451 
480 template<typename Signature>
481 Signature* select_overload(Signature* func)
482 {
483  return func;
484 }
485 
486 
524 template<typename Signature, typename ClassType>
525 auto select_overload(Signature (ClassType::*func)) -> decltype(func)
526 {
527  return func;
528 }
529 
530 
566 template<typename ClassType, typename ReturnType, typename... Args>
567 auto select_const(ReturnType (ClassType::*func)(Args...) const) -> decltype(func)
568 {
569  return func;
570 }
571 
608 template<typename ClassType, typename ReturnType, typename... Args>
609 auto select_non_const(ReturnType(ClassType::*func)(Args...)) -> decltype(func)
610 {
611  return func;
612 }
613 
619 RTTR_INLINE detail::metadata metadata(variant key, variant value);
620 
621 
629 template<typename Enum_Type>
630 RTTR_INLINE detail::enum_data<Enum_Type> value(const char* name, Enum_Type value);
631 
663 template<typename...TArgs>
664 RTTR_INLINE detail::default_args<TArgs...> default_arguments(TArgs&&...args);
665 
691 template<typename...TArgs>
692 RTTR_INLINE detail::parameter_names<detail::decay_t<TArgs>...> parameter_names(TArgs&&...args);
693 
694 
698 
699 #ifdef DOXYGEN
700 
701 
718 #define RTTR_REGISTRATION
719 
742 #define RTTR_REGISTRATION_FRIEND
743 
755 template<typename...T>
756 class registration::bind : public base_class
757 {
758  public:
762  template<typename... Args>
763  base_class operator()(Args&&... arg);
764 };
765 
766 #endif
767 
768 } // end namespace rttr
769 
770 #include "rttr/detail/registration/registration_impl.h"
771 
772 #endif // RTTR_REGISTRATION_H_
Definition: access_levels.h:33
Declares that this member was registered with protected access.
auto select_non_const(ReturnType(ClassType::*func)(Args...)) -> decltype(func)
This is a helper function to register overloaded const member functions.
Definition: registration.h:609
The type class holds the type information for any arbitrary object.
Definition: type.h:153
base_class operator()(Args &&...arg)
The bracket operator can be used to add additional meta data or policies.
static const detail::protected_access protected_access
This variable can be used to specify during registration of a class member the access level: protecte...
Definition: registration.h:408
detail::default_args< TArgs... > default_arguments(TArgs &&...args)
The default_arguments function should be used add default arguments, for constructors or a methods du...
The class_ is used to register classes to RTTR.
Definition: registration.h:129
The enumeration class provides several meta information about an enum.
Definition: enumeration.h:101
The method class provides several meta information about a method and can be invoked.
Definition: method.h:116
detail::enum_data< Enum_Type > value(const char *name, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...
auto select_const(ReturnType(ClassType::*func)(Args...) const) -> decltype(func)
This is a helper function to register overloaded const member functions.
Definition: registration.h:567
Signature * select_overload(Signature *func)
This is a helper function to register overloaded functions.
Definition: registration.h:481
Declares that this member was registered with private access.
static const detail::public_access public_access
This variable can be used to specify during registration of a class member the access level: public...
Definition: registration.h:382
The registration class is the entry point for the manual registration of reflection information to th...
Definition: registration.h:119
The property class provides several meta information about a property and gives read/write access to ...
Definition: property.h:114
static const detail::private_access private_access
This variable can be used to specify during registration of a class member the access level: private...
Definition: registration.h:434
friend class bind
Definition: registration.h:445
detail::parameter_names< detail::decay_t< TArgs >... > parameter_names(TArgs &&...args)
The parameter_names function should be used add human-readable names of the parameters, for constructors or a methods during the registration process of reflection information.
detail::metadata metadata(variant key, variant value)
The metadata function can be used to add additional meta data information during the registration pro...
The bind class is used to chain registration calls.
Definition: registration.h:123
The constructor class provides several meta information about a constructor and can be invoked...
Definition: constructor.h:85
Declares that this member was registered with public access.