registration.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_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 #include "rttr/detail/visitor/visitor_registration.h"
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, typename Visitor_List = READ_TL(rttr_visitor_list)>
129  class class_
130  {
131  public:
138  class_(string_view name);
139  ~class_();
140 
141 
146  template<typename...Args>
147  class_<Class_Type, Visitor_List>& 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, Visitor_List, Args...> constructor(acc_level level = acc_level());
164 
179 
180 
196  bind<detail::prop, Class_Type, A, acc_level, Visitor_List> property(string_view name, A acc, acc_level level = acc_level());
197 
214  bind<detail::prop_readonly, Class_Type, A, acc_level, Visitor_List> property_readonly(string_view name, A acc, acc_level level = acc_level());
215 
234  bind<detail::prop, Class_Type, A1, A2, acc_level, Visitor_List> property(string_view 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, Visitor_List> method(string_view 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, typename Visitor_List = READ_TL(rttr_visitor_list)>
292 
308  template<typename A, typename Visitor_List = READ_TL(rttr_visitor_list)>
310 
326  template<typename A1, typename A2, typename Visitor_List = READ_TL(rttr_visitor_list)>
328 
342  template<typename F, typename Visitor_List = READ_TL(rttr_visitor_list)>
344 
356  template<typename Enum_Type>
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 
572 #ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE
573 
578 template<typename ClassType, typename ReturnType, typename... Args>
579 auto select_const(ReturnType (ClassType::*func)(Args...) const noexcept) -> decltype(func)
580 {
581  return func;
582 }
583 #endif
584 
621 template<typename ClassType, typename ReturnType, typename... Args>
622 auto select_non_const(ReturnType(ClassType::*func)(Args...)) -> decltype(func)
623 {
624  return func;
625 }
626 
627 #ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE
628 
634 template<typename ClassType, typename ReturnType, typename... Args>
635 auto select_non_const(ReturnType(ClassType::*func)(Args...) noexcept) -> decltype(func)
636 {
637  return func;
638 }
639 #endif
640 
646 RTTR_INLINE detail::metadata metadata(variant key, variant value);
647 
648 
656 template<typename Enum_Type>
657 RTTR_INLINE detail::enum_data<Enum_Type> value(string_view, Enum_Type value);
658 
690 template<typename...TArgs>
691 RTTR_INLINE detail::default_args<TArgs...> default_arguments(TArgs&&...args);
692 
718 template<typename...TArgs>
719 RTTR_INLINE detail::parameter_names<detail::decay_t<TArgs>...> parameter_names(TArgs&&...args);
720 
721 
725 
726 #ifdef DOXYGEN
727 
728 
745 #define RTTR_REGISTRATION
746 
769 #define RTTR_PLUGIN_REGISTRATION
770 
793 #define RTTR_REGISTRATION_FRIEND
794 
806 template<typename...T>
807 class registration::bind : public detail::base_class
808 {
809  public:
813  template<typename... Args>
814  base_class operator()(Args&&... arg);
815 };
816 
817 #endif
818 
819 } // end namespace rttr
820 
821 #include "rttr/detail/registration/registration_impl.h"
822 
823 #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:622
The type class holds the type information for any arbitrary object.
Definition: type.h:177
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
detail::enum_data< Enum_Type > value(string_view, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...
The enumeration class provides several meta information about an enum.
Definition: enumeration.h:112
The method class provides several meta information about a method and can be invoked.
Definition: method.h:121
The class template basic_string_view describes an non-owning reference to a constant contiguous seque...
Definition: string_view.h:48
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:117
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:89
Declares that this member was registered with public access.
basic_string_view< char > string_view
A class to hold a reference to a continuous sequence of char objects.
Definition: string_view.h:493