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"
40namespace rttr
41{
42
43namespace 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
120{
121public:
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:
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>
164
179
180
197
215
235
236
251 template<typename F, typename acc_level = detail::public_access>
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
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
436private:
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
442private:
443 std::shared_ptr<detail::registration_executer> m_reg_exec;
444 template<typename...T>
445 friend class bind;
446};
447
451
480template<typename Signature>
482{
483 return func;
484}
485
486
524template<typename Signature, typename ClassType>
526{
527 return func;
528}
529
530
566template<typename ClassType, typename ReturnType, typename... Args>
568{
569 return func;
570}
571
572#ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE
578template<typename ClassType, typename ReturnType, typename... Args>
580{
581 return func;
582}
583#endif
584
621template<typename ClassType, typename ReturnType, typename... Args>
623{
624 return func;
625}
626
627#ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE
628
634template<typename ClassType, typename ReturnType, typename... Args>
636{
637 return func;
638}
639#endif
640
647
648
656template<typename Enum_Type>
657RTTR_INLINE detail::enum_data<Enum_Type> value(string_view, Enum_Type value);
658
690template<typename...TArgs>
691RTTR_INLINE detail::default_args<TArgs...> default_arguments(TArgs&&...args);
692
718template<typename...TArgs>
719RTTR_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
806template<typename...T>
807class 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_
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
array_range()
Default constructor.
The bind class is used to chain registration calls.
Definition registration.h:808
base_class operator()(Args &&... arg)
The bracket operator can be used to add additional meta data or policies.
The class_ is used to register classes to RTTR.
Definition registration.h:130
class_< Class_Type, Visitor_List > & operator()(Args &&...args)
The bracket operator can be used to add additional meta data to the class type.
bind< detail::meth, Class_Type, F, acc_level, Visitor_List > method(string_view name, F f, acc_level level=acc_level())
Register a method to this class.
class_(string_view name)
Construct a class_ object with the given name name.
bind< detail::ctor_func, Class_Type, F, acc_level, Visitor_List > constructor(F func, acc_level level=acc_level())
Register a constructor for this class type which uses a function F.
bind< detail::prop_readonly, Class_Type, A, acc_level, Visitor_List > property_readonly(string_view name, A acc, acc_level level=acc_level())
Register a read only property to this class.
bind< detail::enum_, Class_Type, Enum_Type > enumeration(string_view name)
Register a nested enumeration of type Enum_Type.
bind< detail::ctor, Class_Type, acc_level, Visitor_List, Args... > constructor(acc_level level=acc_level())
Register a constructor for this class type with or without arguments.
bind< detail::prop, Class_Type, A1, A2, acc_level, Visitor_List > property(string_view name, A1 getter, A2 setter, acc_level level=acc_level())
Register a property to this class.
bind< detail::prop, Class_Type, A, acc_level, Visitor_List > property(string_view name, A acc, acc_level level=acc_level())
Register a property to this class.
The registration class is the entry point for the manual registration of reflection information to th...
Definition registration.h:120
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
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
static bind< detail::enum_, detail::invalid_type, Enum_Type > enumeration(string_view name)
Register a global enumeration of type Enum_Type.
static bind< detail::prop_readonly, detail::invalid_type, A, detail::public_access, Visitor_List > property_readonly(string_view name, A acc)
Register a global read only property.
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::prop, detail::invalid_type, A, detail::public_access, Visitor_List > property(string_view name, A acc)
Register a global property with read write access.
static bind< detail::prop, detail::invalid_type, A1, A2, detail::public_access, Visitor_List > property(string_view name, A1 getter, A2 setter)
Register a property to this class.
static bind< detail::meth, detail::invalid_type, F, detail::public_access, Visitor_List > method(string_view name, F f)
Register a method to this class.
The variant class allows to store data of any type and convert between these types transparently.
Definition variant.h:199
Definition access_levels.h:34
detail::default_args< TArgs... > default_arguments(TArgs &&...args)
The default_arguments function should be used add default arguments, for constructors or a methods du...
detail::metadata metadata(variant key, variant value)
The metadata function can be used to add additional meta data information during the registration pro...
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...
Signature * select_overload(Signature *func)
This is a helper function to register overloaded functions.
Definition registration.h:481
@ protected_access
Declares that this member was registered with protected access.
@ public_access
Declares that this member was registered with public access.
@ private_access
Declares that this member was registered with private access.
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
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
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,...