Skip to content

Commit 4c009a7

Browse files
committed
cleanup: phasing old dispatch, call() api.
1 parent 8d2d178 commit 4c009a7

File tree

7 files changed

+4
-148
lines changed

7 files changed

+4
-148
lines changed

ReflectionTemplateLib/rtl/builder/SetupFunction.hpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ namespace rtl
2929
{
3030
return [](const FunctorId& pFunctorId, _signature&&... params) -> Return
3131
{
32-
using function_t = dispatch::function_ptr<void, _signature...>;
33-
34-
auto fptr = static_cast<const function_t&>(pFunctorId.get_functor()).f_ptr();
35-
36-
fptr(std::forward<_signature>(params)...);
37-
return { error::None, RObject{} };
32+
return { error::InvalidCaller, RObject{} };
3833
};
3934
}
4035

@@ -48,32 +43,7 @@ namespace rtl
4843
this is stored in _derivedType's (FunctorContainer) vector holding lambda's.
4944
*/ return [](const FunctorId& pFunctorId, _signature&&...params)-> Return
5045
{
51-
using function_t = dispatch::function_ptr<_returnType, _signature...>;
52-
53-
auto fptr = static_cast<const function_t&>(pFunctorId.get_functor()).f_ptr();
54-
55-
constexpr bool isConstCastSafe = (!traits::is_const_v<_returnType>);
56-
57-
if constexpr (std::is_reference_v<_returnType>) {
58-
/* if the function returns reference, this block will be retained by compiler.
59-
Note: reference to temporary or dangling is not checked here.
60-
*/ using _rawRetType = traits::raw_t<_returnType>;
61-
const _rawRetType& retObj = fptr(std::forward<_signature>(params)...);
62-
return { error::None,
63-
RObjectBuilder<const _rawRetType*>::template
64-
build<rtl::alloc::Stack>(&retObj, isConstCastSafe)
65-
};
66-
}
67-
else {
68-
//if the function returns anything (not refrence), this block will be retained by compiler.
69-
auto&& retObj = fptr(std::forward<_signature>(params)...);
70-
using T = std::remove_cvref_t<decltype(retObj)>;
71-
72-
return { error::None,
73-
RObjectBuilder<const T>::template
74-
build<rtl::alloc::Stack>(std::forward<decltype(retObj)>(retObj), isConstCastSafe)
75-
};
76-
}
46+
return { error::InvalidCaller, RObject{} };
7747
};
7848
}
7949

ReflectionTemplateLib/rtl/detail/inc/FunctionCaller.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,6 @@
1414
#include "type_meta.h"
1515
#include "rtl_forward_decls.h"
1616

17-
namespace rtl::detail
18-
{
19-
template<bool is_binding_v, class ..._signature>
20-
struct ErasedCaller
21-
{
22-
const Function& m_function;
23-
24-
template<class ..._args>
25-
rtl::Return call(_args&&...) const noexcept;
26-
27-
template<class ..._args> requires (is_binding_v == false)
28-
constexpr rtl::Return operator()(_args&&...params) const noexcept
29-
{
30-
return { error::InvalidCaller, RObject{} };
31-
}
32-
33-
template<class ..._args> requires (is_binding_v == true)
34-
constexpr rtl::Return operator()(_args&&...params) const noexcept
35-
{
36-
return { error::SignatureMismatch, RObject{} };
37-
}
38-
};
39-
}
40-
41-
4217
namespace rtl::detail
4318
{
4419
template<member member_kind, class ..._signature>

ReflectionTemplateLib/rtl/detail/inc/FunctionCaller.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@
2121
#include "rtl_function.h"
2222
#include "rtl_function_erased_return.hpp"
2323

24-
namespace rtl::detail
25-
{
26-
template<bool is_binding_v, class ..._signature>
27-
template<class ..._args>
28-
ForceInline Return ErasedCaller<is_binding_v, _signature...>::call(_args&&...params) const noexcept
29-
{
30-
using Container = std::conditional_t<sizeof...(_signature) == 0,
31-
FunctorContainer<std::remove_reference_t<_args>...>,
32-
FunctorContainer<_signature...>>;
33-
34-
const detail::FunctorId* functorId = m_function.hasFunctorId(Container::getContainerId());
35-
if (functorId != nullptr) [[likely]] {
36-
return Container::template forwardCall<_args...>(*functorId, std::forward<_args>(params)...);
37-
}
38-
return { error::SignatureMismatch, RObject{} };
39-
}
40-
}
41-
42-
4324
namespace rtl::detail
4425
{
4526
template<member member_kind, class ...args_t>

ReflectionTemplateLib/rtl/detail/inc/MethodInvoker.hpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ namespace rtl::detail
3535
template<class ..._args>
3636
ForceInline Return DefaultInvoker<_signature...>::call(_args&& ...params) const noexcept
3737
{
38-
//Only static-member-functions have Qualifier- 'member::None'
39-
if (m_method->getQualifier() == member::None) [[unlikely]] {
40-
return static_cast<Function>(*m_method).bind().call(std::forward<_args>(params)...);
41-
}
42-
else if (m_target->isEmpty()) [[unlikely]] {
38+
if (m_target->isEmpty()) [[unlikely]] {
4339
//if the target is empty.
4440
return { error::EmptyRObject, RObject{} };
4541
}
@@ -104,10 +100,7 @@ namespace rtl::detail
104100
template<class ..._args>
105101
ForceInline Return NonConstInvoker<_signature...>::call(_args&& ...params) const noexcept
106102
{
107-
if (m_method->getQualifier() == member::None) [[unlikely]] {
108-
return static_cast<Function>(*m_method).bind().call(std::forward<_args>(params)...);
109-
}
110-
else if (m_target->isEmpty()) [[unlikely]] {
103+
if (m_target->isEmpty()) [[unlikely]] {
111104
//if the target is empty.
112105
return { error::EmptyRObject, RObject{} };
113106
}

ReflectionTemplateLib/rtl/inc/Function.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ namespace rtl {
7171

7272
const detail::FunctorId* hasFunctorId(const std::size_t pSignatureId) const;
7373

74-
std::pair<std::optional<type_meta>, bool> getLambdaByNormalId(const std::size_t pSignatureId) const;
75-
76-
constexpr std::optional<type_meta> getLambdaByStrictId(const std::size_t pSignatureId) const;
77-
7874
GETTER(detail::member, Qualifier, m_member_kind);
7975

8076
GETTER_REF_C(std::vector<detail::FunctorId>, FunctorIds, m_functorIds)
@@ -103,15 +99,6 @@ namespace rtl {
10399
template<class ..._args>
104100
bool hasSignature() const;
105101

106-
template<class ..._signature>
107-
constexpr const detail::ErasedCaller<true, _signature...> bind() const noexcept;
108-
109-
template<class ..._args>
110-
constexpr rtl::Return operator()(_args&&...params) const noexcept
111-
{
112-
return detail::ErasedCaller<false, _args...>{ (*this) }(std::forward<_args>(params)...);
113-
}
114-
115102
friend detail::CxxReflection;
116103
friend detail::ReflectionBuilder;
117104

ReflectionTemplateLib/rtl/inc/Function.hpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616

1717
namespace rtl
1818
{
19-
template<class ..._signature>
20-
inline constexpr const detail::ErasedCaller<true, _signature...> Function::bind() const noexcept
21-
{
22-
return detail::ErasedCaller<true, _signature...>{ (*this) };
23-
}
24-
2519
template<class ...signatureT>
2620
inline constexpr const detail::HopFunction<detail::member::None, signatureT...> Function::argsT() const
2721
{
@@ -70,43 +64,4 @@ namespace rtl
7064
}
7165
return nullptr;
7266
}
73-
74-
75-
inline constexpr std::optional<type_meta> Function::getLambdaByStrictId(const std::size_t pSignatureId) const
76-
{
77-
//simple linear-search, efficient for small set of elements.
78-
for (const auto& functorMeta : m_functorsMeta) {
79-
if (pSignatureId == functorMeta.get_strict_args_id()) [[likely]] {
80-
return { functorMeta };
81-
}
82-
}
83-
return std::nullopt;
84-
}
85-
86-
87-
ForceInline std::pair<std::optional<type_meta>, bool> Function::getLambdaByNormalId(const std::size_t pSignatureId) const
88-
{
89-
std::optional<type_meta> functorMeta = getLambdaByStrictId(pSignatureId);
90-
if (functorMeta) {
91-
return { functorMeta, false };
92-
}
93-
94-
std::size_t index = rtl::index_none;
95-
for (int i = 0; i < m_functorsMeta.size(); i++)
96-
{
97-
if (pSignatureId == m_functorsMeta[i].get_normal_args_id()) [[likely]] {
98-
if (index == rtl::index_none) {
99-
index = i;
100-
}
101-
else return { std::nullopt, true };
102-
}
103-
}
104-
105-
if (index != rtl::index_none)
106-
{
107-
auto isAnyNonConstRefInArgsT = (m_functorsMeta[index].is_any_arg_ncref());
108-
return { (isAnyNonConstRefInArgsT ? std::nullopt : std::make_optional(m_functorsMeta[index])), isAnyNonConstRefInArgsT };
109-
}
110-
return { std::nullopt, false };
111-
}
11267
}

ReflectionTemplateLib/rtl/inc/Method.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ namespace rtl {
5252

5353
GETTER_BOOL(Const, (getQualifier() == detail::member::Const));
5454

55-
using Function::bind;
56-
57-
template<class ..._args>
58-
constexpr const detail::ErasedCaller<false, _args...> operator()(_args&&...params) const noexcept = delete;
59-
6055
template<class ...signatureT>
6156
constexpr const detail::HopFunction<detail::member::Static, signatureT...> argsT() const;
6257

0 commit comments

Comments
 (0)