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 
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:
140 
141 
146  template<typename...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(string_view name, A acc, acc_level level = acc_level());
197 
215 
234  bind<detail::prop, Class_Type, A1, A2, acc_level> 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> 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>
292 
308  template<typename A>
310 
326  template<typename A1, typename A2>
328 
342  template<typename F>
344 
356  template<typename Enum_Type>
358 
360 
382  static const detail::public_access public_access;
383 
408  static const detail::protected_access protected_access;
409 
434  static const detail::private_access private_access;
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 
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_
static bind< detail::prop_readonly, detail::invalid_type, A, detail::public_access > property_readonly(string_view name, A acc)
Register a global read only property.
@ public_access
Declares that this member was registered with public access.
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,...
bind< detail::prop, Class_Type, A, acc_level > property(string_view name, A acc, acc_level level=acc_level())
Register a property to this class.
bind< detail::ctor_func, Class_Type, F, acc_level > constructor(F func, acc_level level=acc_level())
Register a constructor for this class type which uses a function F.
The registration class is the entry point for the manual registration of reflection information to th...
Definition: registration.h:120
bind< detail::ctor, Class_Type, acc_level, Args... > constructor(acc_level level=acc_level())
Register a constructor for this class type with or without arguments.
class_< Class_Type > & operator()(Args &&...args)
The bracket operator can be used to add additional meta data to the class type.
bind< detail::prop, Class_Type, A1, A2, acc_level > property(string_view name, A1 getter, A2 setter, acc_level level=acc_level())
Register a property to this class.
class_(string_view name)
Construct a class_ object with the given name name.
bind< detail::prop_readonly, Class_Type, A, acc_level > property_readonly(string_view name, A acc, acc_level level=acc_level())
Register a read only property to this class.
static bind< detail::prop, detail::invalid_type, A1, A2, detail::public_access > property(string_view name, A1 getter, A2 setter)
Register a property to this class.
Definition: access_levels.h:34
detail::metadata metadata(variant key, variant value)
The metadata function can be used to add additional meta data information during the registration pro...
base_class operator()(Args &&... arg)
The bracket operator can be used to add additional meta data or policies.
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...
bind< detail::meth, Class_Type, F, acc_level > method(string_view name, F f, acc_level level=acc_level())
Register a method to this class.
The class template basic_string_view describes an non-owning reference to a constant contiguous seque...
Definition: string_view.h:49
static bind< detail::meth, detail::invalid_type, F, detail::public_access > method(string_view name, F f)
Register a method to this class.
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
bind< detail::enum_, Class_Type, Enum_Type > enumeration(string_view name)
Register a nested enumeration of type Enum_Type.
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:130
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
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 bind class is used to chain registration calls.
Definition: registration.h:808
The variant class allows to store data of any type and convert between these types transparently.
Definition: variant.h:198
static bind< detail::prop, detail::invalid_type, A, detail::public_access > property(string_view name, A acc)
Register a global property with read write access.
The type class holds the type information for any arbitrary object.
Definition: type.h:171
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
static bind< detail::enum_, detail::invalid_type, Enum_Type > enumeration(string_view name)
Register a global enumeration of type Enum_Type.