Skip to content

Commit 07c7ce5

Browse files
committed
refactor, files reorganized.
1 parent 1121dc5 commit 07c7ce5

16 files changed

+132
-93
lines changed

ReflectionTemplateLib/rtl/CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
set(LOCAL_HEADERS
55
"${CMAKE_CURRENT_SOURCE_DIR}/access.h"
66
"${CMAKE_CURRENT_SOURCE_DIR}/builder.h"
7-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_forward_decls.h"
8-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_constants.h"
7+
98
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_errors.h"
109
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_traits.h"
1110
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_typeid.h"
11+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_constants.h"
12+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_forward_decls.h"
13+
14+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_function.h"
15+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_function_erased_return.h"
16+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_function_erased_return.hpp"
17+
18+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method.h"
19+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased.h"
20+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_return.h"
21+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_target.h"
22+
23+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_const.h"
24+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_const.h"
25+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_return_const.h"
26+
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_target_const.h"
1227
)
1328

1429
target_sources(ReflectionTemplateLib PRIVATE ${LOCAL_HEADERS})

ReflectionTemplateLib/rtl/detail/inc/FunctionCaller.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "functor_cast.h"
2020
#include "function_ptr.h"
2121
#include "rtl_function.h"
22-
#include "rtl_function_erased_return.h"
22+
#include "rtl_function_erased_return.hpp"
2323

2424
namespace rtl::detail
2525
{

ReflectionTemplateLib/rtl/dispatch/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@ set(LOCAL_HEADERS
2424
"${CMAKE_CURRENT_SOURCE_DIR}/aware_constructor.h"
2525
"${CMAKE_CURRENT_SOURCE_DIR}/aware_return_n_target.h"
2626
"${CMAKE_CURRENT_SOURCE_DIR}/aware_return_n_target_const.h"
27-
28-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_function.h"
29-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_function_erased_return.h"
30-
31-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method.h"
32-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased.h"
33-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_return.h"
34-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_target.h"
35-
36-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_const.h"
37-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_const.h"
38-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_return_const.h"
39-
"${CMAKE_CURRENT_SOURCE_DIR}/rtl_method_erased_target_const.h"
4027
)
4128

4229
target_sources(ReflectionTemplateLib PRIVATE ${LOCAL_HEADERS})

ReflectionTemplateLib/rtl/inc/RObject.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
#pragma once
1313

14-
//#include <atomic>
15-
#include <cstddef>
16-
1714
#include "view.h"
1815
#include "RObjectId.h"
1916

@@ -121,6 +118,6 @@ namespace rtl
121118

122119
struct [[nodiscard]] Return {
123120
error err;
124-
RObject rObject;
121+
RObject robject;
125122
};
126123
}

ReflectionTemplateLib/rtl/rtl_forward_decls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace rtl
2828
struct type_meta;
2929

3030
template<class return_t, class ...signature_t>
31-
struct function;
31+
class function;
3232

3333
template<class return_t, class ...signature_t>
3434
struct static_method;
File renamed without changes.

ReflectionTemplateLib/rtl/dispatch/rtl_function_erased_return.h renamed to ReflectionTemplateLib/rtl/rtl_function_erased_return.h

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,43 @@
1717
namespace rtl
1818
{
1919
template<class ...signature_t>
20-
struct function<Return(signature_t...)>
20+
class function<Return(signature_t...)>
2121
{
22-
template<class ...args_t> requires (sizeof...(args_t) == sizeof...(signature_t))
23-
[[nodiscard]] [[gnu::hot]] [[gnu::flatten]]
24-
constexpr Return operator()(args_t&&...params) const noexcept
25-
{
26-
if (!(*this)) [[unlikely]] {
27-
return { m_init_err, RObject{} };
28-
}
22+
using lambda_vt = std::function<void(const dispatch::functor&, signature_t...)>;
2923

30-
if (must_bind_refs()) [[unlikely]] {
31-
return { error::ExplicitRefBindingRequired, RObject{} };
32-
}
24+
using lambda_rt = std::function<std::any(const dispatch::functor&, signature_t...)>;
3325

34-
auto index = (m_functors[call_by::value] != nullptr ? call_by::value : call_by::cref);
35-
if (m_functors[index]->is_void())
36-
{
37-
m_vhop[index](*m_functors[index], std::forward<args_t>(params)...);
38-
return { error::None, RObject{} };
39-
}
40-
else
41-
{
42-
return { error::None,
43-
RObject{ m_rhop[index](*m_functors[index], std::forward<args_t>(params)...),
44-
m_functors.back()->get_robject_id(), nullptr
45-
}
46-
};
47-
}
48-
}
26+
std::vector<lambda_rt> m_rhop = {};
27+
28+
std::vector<lambda_vt> m_vhop = {};
29+
30+
std::vector<const dispatch::functor*> m_functors = {};
31+
32+
error m_init_err = error::InvalidCaller;
33+
34+
void set_init_error(error p_err);
35+
36+
GETTER_REF(std::vector<lambda_rt>, _rhop, m_rhop)
37+
GETTER_REF(std::vector<lambda_vt>, _vhop, m_vhop)
38+
GETTER_REF(std::vector<const dispatch::functor*>, _overloads, m_functors)
39+
40+
public:
41+
42+
enum call_by {
43+
value = 0,
44+
cref = 1, //const ref.
45+
ncref = 2 //non-const ref.
46+
};
47+
48+
GETTER(rtl::error, _init_error, m_init_err)
49+
50+
constexpr operator bool() const noexcept;
51+
52+
constexpr bool must_bind_refs() const noexcept;
53+
54+
template<class ...args_t>
55+
requires (sizeof...(args_t) == sizeof...(signature_t))
56+
constexpr Return operator()(args_t&&...params) const noexcept;
4957

5058
template<class ...fwd_args_t>
5159
struct perfect_fwd
@@ -88,57 +96,14 @@ namespace rtl
8896
};
8997

9098
template<class ...args_t>
91-
requires (std::is_same_v<traits::normal_sign_id_t<args_t...>, std::tuple<signature_t...>>)
92-
constexpr const perfect_fwd<args_t...> bind() const noexcept {
93-
return perfect_fwd<args_t...>{ *this };
94-
}
95-
96-
constexpr operator bool() const noexcept {
97-
return !(m_init_err != error::None || m_functors.empty() ||
98-
(m_functors.size() == 1 && m_functors[0] == nullptr));
99-
}
100-
101-
constexpr bool must_bind_refs() const noexcept {
102-
return (m_functors[call_by::value] == nullptr &&
103-
(m_functors.size() > call_by::ncref || m_functors[call_by::cref]->is_any_arg_ncref()));
104-
}
105-
106-
enum call_by
107-
{
108-
value = 0,
109-
cref = 1, //const ref.
110-
ncref = 2 //non-const ref.
111-
};
112-
113-
GETTER(rtl::error, _init_error, m_init_err)
114-
115-
private:
116-
117-
using lambda_vt = std::function<void(const dispatch::functor&, signature_t...)>;
118-
119-
using lambda_rt = std::function<std::any(const dispatch::functor&, signature_t...)>;
120-
121-
std::vector<lambda_rt> m_rhop = {};
122-
123-
std::vector<lambda_vt> m_vhop = {};
124-
125-
std::vector<const dispatch::functor*> m_functors = {};
126-
127-
error m_init_err = error::InvalidCaller;
128-
129-
void set_init_error(error p_err) {
130-
m_init_err = p_err;
131-
}
132-
133-
GETTER_REF(std::vector<lambda_rt>, _rhop, m_rhop)
134-
GETTER_REF(std::vector<lambda_vt>, _vhop, m_vhop)
135-
GETTER_REF(std::vector<const dispatch::functor*>, _overloads, m_functors)
99+
requires (std::is_same_v<traits::normal_sign_id_t<args_t...>, std::tuple<signature_t...>>)
100+
constexpr const perfect_fwd<args_t...> bind() const noexcept;
136101

137102
template<detail::member, class ...>
138103
friend struct detail::HopFunction;
139104

140105
static_assert((!std::is_reference_v<signature_t> && ...),
141-
"rtl::function<...>: any type cannot be specified as reference here");
106+
"rtl::function<...>: any type cannot be specified as reference here");
142107
};
143108
}
144109

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*************************************************************************
2+
* *
3+
* Reflection Template Library (RTL) - Modern C++ Reflection Framework *
4+
* https://github.com/ReflectCxx/ReflectionTemplateLibrary-CPP *
5+
* *
6+
* Copyright (c) 2025 Neeraj Singh <reflectcxx@outlook.com> *
7+
* SPDX-License-Identifier: MIT *
8+
* *
9+
*************************************************************************/
10+
11+
12+
#pragma once
13+
14+
#include "rtl_function_erased_return.h"
15+
16+
namespace rtl
17+
{
18+
template<class ...signature_t>
19+
inline void function<Return(signature_t...)>::set_init_error(error p_err) {
20+
m_init_err = p_err;
21+
}
22+
23+
template<class ...signature_t>
24+
inline constexpr function<Return(signature_t...)>::operator bool() const noexcept {
25+
return !(m_init_err != error::None || m_functors.empty() ||
26+
(m_functors.size() == 1 && m_functors[0] == nullptr));
27+
}
28+
29+
30+
template<class ...signature_t>
31+
inline constexpr bool function<Return(signature_t...)>::must_bind_refs() const noexcept {
32+
return (m_functors[call_by::value] == nullptr &&
33+
(m_functors.size() > call_by::ncref || m_functors[call_by::cref]->is_any_arg_ncref()));
34+
}
35+
36+
37+
template<class ...signature_t>
38+
template<class ...args_t>
39+
requires (std::is_same_v<traits::normal_sign_id_t<args_t...>, std::tuple<signature_t...>>)
40+
inline constexpr const function<Return(signature_t...)>::perfect_fwd<args_t...>
41+
function<Return(signature_t...)>::bind() const noexcept {
42+
return perfect_fwd<args_t...>{ *this };
43+
}
44+
45+
46+
template<class ...signature_t>
47+
template<class ...args_t>
48+
requires (sizeof...(args_t) == sizeof...(signature_t))
49+
[[nodiscard]] [[gnu::hot]] [[gnu::flatten]]
50+
inline constexpr Return function<Return(signature_t...)>::operator()(args_t&&...params) const noexcept
51+
{
52+
if (!(*this)) [[unlikely]] {
53+
return { m_init_err, RObject{} };
54+
}
55+
56+
if (must_bind_refs()) [[unlikely]] {
57+
return { error::ExplicitRefBindingRequired, RObject{} };
58+
}
59+
60+
auto index = (m_functors[call_by::value] != nullptr ? call_by::value : call_by::cref);
61+
if (m_functors[index]->is_void())
62+
{
63+
m_vhop[index](*m_functors[index], std::forward<args_t>(params)...);
64+
return { error::None, RObject{} };
65+
}
66+
else
67+
{
68+
return { error::None,
69+
RObject{ m_rhop[index](*m_functors[index], std::forward<args_t>(params)...),
70+
m_functors.back()->get_robject_id(), nullptr
71+
}
72+
};
73+
}
74+
}
75+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)