Refureku v2.2.0
C++17 runtime reflection library.
Method.h
1
8#pragma once
9
10#include <type_traits> //std::enable_if_v, std::is_const_v
11#include <cassert>
12
13#include "Refureku/TypeInfo/Cast.h"
14#include "Refureku/TypeInfo/MethodFieldHelpers.h"
15#include "Refureku/TypeInfo/Archetypes/Struct.h"
16#include "Refureku/TypeInfo/Functions/MethodBase.h"
17#include "Refureku/TypeInfo/Functions/MemberFunction.h"
18#include "Refureku/Misc/CopyConstness.h"
19#include "Refureku/Exceptions/InvalidArchetype.h"
20
21namespace rfk
22{
23 class Method final : public MethodBase
24 {
25 public:
26 REFUREKU_INTERNAL Method(char const* name,
27 std::size_t id,
28 Type const& returnType,
29 ICallable* internalMethod,
30 EMethodFlags flags,
31 Entity const* outerEntity) noexcept;
32 REFUREKU_INTERNAL Method(Method&&) noexcept;
33 REFUREKU_INTERNAL ~Method() noexcept;
34
56 template <typename ReturnType = void, typename CallerType, typename... ArgTypes, typename = internal::IsAdjustableInstance<CallerType>>
57 ReturnType invoke(CallerType& caller, ArgTypes&&... args) const;
58
82 template <typename ReturnType = void, typename... ArgTypes>
83 ReturnType invokeUnsafe(void* caller, ArgTypes&&... args) const;
84
108 template <typename ReturnType = void, typename... ArgTypes>
109 ReturnType invokeUnsafe(void const* caller, ArgTypes&&... args) const;
110
137 template <typename ReturnType = void, typename CallerType, typename... ArgTypes, typename = internal::IsAdjustableInstance<CallerType>>
138 ReturnType checkedInvoke(CallerType& caller, ArgTypes&&... args) const;
139
170 template <typename ReturnType = void, typename... ArgTypes>
171 ReturnType checkedInvokeUnsafe(void* caller, ArgTypes&&... args) const;
172
203 template <typename ReturnType = void, typename... ArgTypes>
204 ReturnType checkedInvokeUnsafe(void const* caller, ArgTypes&&... args) const;
205
210 REFUREKU_API void inheritBaseMethodProperties() noexcept;
211
212 private:
213 //Forward declaration
214 class MethodImpl;
215
216 template <typename FunctionPrototype>
217 class MemberFunctionSafeCallWrapper;
218
219 template <typename ReturnType, typename... ArgTypes>
220 class MemberFunctionSafeCallWrapper<ReturnType(ArgTypes...)>
221 {
222 private:
223 template <typename T>
224 using PointerToMemberMethod = ReturnType (T::*)(ArgTypes...);
225
226 public:
227 MemberFunctionSafeCallWrapper() = delete;
228
241 template <typename T, typename = std::enable_if_t<std::is_same_v<T, void> || std::is_same_v<T, void const>>>
242 static ReturnType invoke(ICallable const& memberFunction,
243 T* caller,
244 ArgTypes&&... args);
245 };
246
258 template <typename ReturnType, typename... ArgTypes>
259 ReturnType internalInvoke(void* caller,
260 ArgTypes&&... args) const;
261 template <typename ReturnType, typename... ArgTypes>
262 ReturnType internalInvoke(void const* caller,
263 ArgTypes&&... args) const;
264
276 template <typename CallerType>
277 RFK_NODISCARD CallerType* adjustCallerPointerAddress(CallerType* caller) const;
278
284 RFK_NORETURN REFUREKU_API void throwConstViolationException() const;
285 };
286
287 REFUREKU_TEMPLATE_API(rfk::Allocator<Method const*>);
288 REFUREKU_TEMPLATE_API(rfk::Vector<Method const*, rfk::Allocator<Method const*>>);
289
290 #include "Refureku/TypeInfo/Functions/Method.inl"
291}
Definition: Allocator.h:19
Definition: Entity.h:29
Definition: ICallable.h:13
Definition: MethodBase.h:16
Definition: Method.h:24
ReturnType invoke(CallerType &caller, ArgTypes &&... args) const
Call the function with the forwarded argument(s) if any, and return the result. Providing bad return ...
ReturnType checkedInvokeUnsafe(void *caller, ArgTypes &&... args) const
Call the function with the forwarded argument(s) if any, and return the result. The return type and a...
ReturnType checkedInvoke(CallerType &caller, ArgTypes &&... args) const
Call the function with the forwarded argument(s) if any, and return the result. The return type and a...
ReturnType invokeUnsafe(void const *caller, ArgTypes &&... args) const
Call the function with the forwarded argument(s) if any, and return the result. Providing bad return ...
REFUREKU_API void inheritBaseMethodProperties() noexcept
Inherit from the properties this method overrides. If the method is not an override,...
ReturnType invokeUnsafe(void *caller, ArgTypes &&... args) const
Call the function with the forwarded argument(s) if any, and return the result. Providing bad return ...
ReturnType checkedInvokeUnsafe(void const *caller, ArgTypes &&... args) const
Call the function with the forwarded argument(s) if any, and return the result. The return type and a...
Definition: Type.h:20
Definition: Vector.h:19
Definition: Allocator.h:16
EMethodFlags
Definition: EMethodFlags.h:17