argument.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_ARGUMENT_H_
29#define RTTR_ARGUMENT_H_
30
31#include "rttr/detail/base/core_prerequisites.h"
32#include "rttr/detail/misc/misc_type_traits.h"
33#include "rttr/detail/misc/std_type_traits.h"
34
35#include <type_traits>
36#include <utility>
37
38namespace rttr
39{
40class type;
41class variant;
42class variant_array;
43class instance;
44
45
51class RTTR_API argument
52{
53 template<typename T>
54 using decay_arg_t = detail::enable_if_t<!std::is_same<argument, T>::value, T>;
55
56 template<typename T>
57 using is_variant = std::is_same<detail::remove_cv_t<detail::remove_reference_t<T>>, variant>;
58
59 template<typename T>
60 using arg_value_t = detail::enable_if_t<!std::is_rvalue_reference<T>::value && !is_variant<T>::value, T>;
61
62 template<typename T>
63 using arg_rvalue_t = detail::enable_if_t<std::is_rvalue_reference<T>::value && !is_variant<T>::value, detail::remove_reference_t<T> >;
64
65 template<typename T>
66 using ptr_type = detail::enable_if_t<std::is_pointer<T>::value, bool>;
67
68 template<typename T>
69 using non_ptr_type = detail::enable_if_t<!std::is_pointer<T>::value, bool>;
70
71 template<typename T>
72 using is_variant_t = detail::enable_if_t<is_variant<T>::value && !std::is_rvalue_reference<T>::value, T>;
73
74 template<typename T>
75 using is_variant_ref_t = detail::enable_if_t<is_variant<T>::value && std::is_rvalue_reference<T>::value, detail::remove_reference_t<T>>;
76
77public:
78
79 RTTR_INLINE argument() RTTR_NOEXCEPT;
80 RTTR_INLINE argument(argument&& arg) RTTR_NOEXCEPT;
81 RTTR_INLINE argument(const argument& other) RTTR_NOEXCEPT;
82 RTTR_INLINE argument(variant& var) RTTR_NOEXCEPT;
83 RTTR_INLINE argument(const variant& var) RTTR_NOEXCEPT;
84
85 template<typename T, typename Tp = decay_arg_t<T>>
86 RTTR_INLINE argument(const T& data) RTTR_NOEXCEPT;
87 template<typename T, typename Tp = decay_arg_t<T>>
88 RTTR_INLINE argument(T& data) RTTR_NOEXCEPT;
89
90 RTTR_INLINE argument& operator=(const argument& other) RTTR_NOEXCEPT;
91
92 RTTR_INLINE type get_type() const RTTR_NOEXCEPT;
93#ifdef DOXYGEN
94 template<typename T>
95 RTTR_INLINE bool is_type() const RTTR_NOEXCEPT;
96
97 template<typename T>
98 RTTR_INLINE T& get_value() const RTTR_NOEXCEPT;
99#else
100 template<typename T>
101 RTTR_INLINE ptr_type<T> is_type() const RTTR_NOEXCEPT;
102 template<typename T>
103 RTTR_INLINE non_ptr_type<T> is_type() const RTTR_NOEXCEPT;
104
105 template<typename T>
106 RTTR_INLINE arg_value_t<T>& get_value() const RTTR_NOEXCEPT;
107 template<typename T>
108 RTTR_INLINE arg_rvalue_t<T> && get_value() const RTTR_NOEXCEPT;
109
110 template<typename T>
111 RTTR_INLINE is_variant_t<T>& get_value() const RTTR_NOEXCEPT;
112 template<typename T>
113 RTTR_INLINE is_variant_ref_t<T> && get_value() const RTTR_NOEXCEPT;
114#endif
115
116private:
117 const void* m_data;
118 const variant* m_variant;
119 const rttr::type m_type;
120};
121
122} // end namespace rttr
123
124#include "rttr/detail/impl/argument_impl.h"
125
126#endif // RTTR_ARGUMENT_H_
The argument class is used for forwarding arguments to properties or methods.
Definition argument.h:52
bool is_type() const noexcept
argument() noexcept
The type class holds the type information for any arbitrary object.
Definition type.h:178
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