Skip to content

Commit 5f8ec48

Browse files
committed
organizing metadata: function_ptr.h, inits. wip.
1 parent 0dd9111 commit 5f8ec48

File tree

11 files changed

+148
-6
lines changed

11 files changed

+148
-6
lines changed

ReflectionTemplateLib/rtl/cache/cache_function_ptr.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include <list>
1515

16-
#include "function_ptr.h"
16+
#include "function_ptr.hpp"
1717

1818
namespace rtl::cache
1919
{
@@ -31,7 +31,15 @@ namespace rtl::cache
3131
const dispatch::functor& push(return_t(*fptr)(signature_t...), traits::uid_t p_record_uid, detail::member member_kind, std::size_t lambda_index) const
3232
{
3333
m_cache.emplace_back(std::make_pair(function_t(fptr, p_record_uid, member_kind), lambda_index));
34-
return m_cache.back().first;
34+
35+
function_t& fn = m_cache.back().first;
36+
if (member_kind == detail::member::UserCtor) {
37+
fn.init_erased_ctor();
38+
}
39+
else {
40+
fn.init_erased_fn();
41+
}
42+
return fn;
3543
}
3644

3745
std::pair<dispatch::functor*, std::size_t> find(return_t(*fptr)(signature_t...)) const

ReflectionTemplateLib/rtl/dispatch/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ set(LOCAL_HEADERS
99
"${CMAKE_CURRENT_SOURCE_DIR}/fn_signature_rec.h"
1010

1111
"${CMAKE_CURRENT_SOURCE_DIR}/method_ptr.h"
12+
"${CMAKE_CURRENT_SOURCE_DIR}/method_ptr.hpp"
1213
"${CMAKE_CURRENT_SOURCE_DIR}/function_ptr.h"
14+
"${CMAKE_CURRENT_SOURCE_DIR}/function_ptr.hpp"
1315
"${CMAKE_CURRENT_SOURCE_DIR}/method_ptr_const.h"
16+
"${CMAKE_CURRENT_SOURCE_DIR}/method_ptr_const.hpp"
1417

1518
"${CMAKE_CURRENT_SOURCE_DIR}/lambda_base.h"
1619
"${CMAKE_CURRENT_SOURCE_DIR}/lambda_method.h"

ReflectionTemplateLib/rtl/dispatch/fn_signature.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ namespace rtl::dispatch
3333
void set_ctor_hop(const lambda_t& lambda) {
3434
m_lambda = lambda;
3535
}
36+
37+
template<class return_t, class ...signature_t>
38+
friend struct function_ptr;
3639
};
3740
}
3841

@@ -64,5 +67,8 @@ namespace rtl::dispatch
6467
void set_method_rhop(const lambda_rt& lambda) {
6568
m_lambda = lambda;
6669
}
70+
71+
template<class return_t, class ...signature_t>
72+
friend struct function_ptr;
6773
};
6874
}

ReflectionTemplateLib/rtl/dispatch/function_ptr.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace rtl::dispatch
1818
{
1919
template<class return_t, class ...signature_t>
20-
struct function_ptr: functor//, fn_meta
20+
struct function_ptr: functor
2121
{
2222
using functor_t = return_t(*)(signature_t...);
2323

@@ -52,6 +52,13 @@ namespace rtl::dispatch
5252
using ctor_et = function_er_ctor<signature_t...>;
5353
using func_et = function_er_return<signature_t...>;
5454

55-
std::variant<func_et, ctor_et> erased_return;
55+
std::variant<func_et, ctor_et> erased_fn;
56+
57+
void init_erased_fn();
58+
59+
void init_erased_ctor();
60+
61+
template<class return_t, class ...signature_t>
62+
friend struct cache::function_ptr;
5663
};
5764
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 <[email protected]> *
7+
* SPDX-License-Identifier: MIT *
8+
* *
9+
*************************************************************************/
10+
11+
12+
#pragma once
13+
14+
#include "function_ptr.h"
15+
#include "fn_signature.h"
16+
#include "aware_return.h"
17+
18+
namespace rtl::dispatch
19+
{
20+
template<class return_t, class ...signature_t>
21+
void rtl::dispatch::function_ptr<return_t, signature_t...>::init_erased_fn()
22+
{
23+
erased_fn = func_et();
24+
func_et& fn = std::get<func_et>(erased_fn);
25+
m_lambdas.push_back(&fn);
26+
27+
//if constexpr (std::is_void_v<return_t>) {
28+
// fn.set_method_vhop(aware_return<return_t, signature_t..>::get_lambda_void())
29+
//}
30+
//else {
31+
// fn.set_method_rhop(aware_return<return_t, signature_t..>::get_lambda_any_return())
32+
//}
33+
}
34+
35+
template<class return_t, class ...signature_t>
36+
void function_ptr<return_t, signature_t...>::init_erased_ctor()
37+
{
38+
erased_fn = ctor_et();
39+
m_lambdas.push_back(&std::get<ctor_et>(erased_fn));
40+
}
41+
}

ReflectionTemplateLib/rtl/dispatch/functor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ namespace rtl::dispatch
3939

4040
detail::member m_member_kind = detail::member::None;
4141

42+
enum index {
43+
ctor = 0, // constructor
44+
fn_eret = 0, // function-erased-return
45+
mth_eret = 0, // method-erased-return
46+
mth_etar = 1 // method-erased-target
47+
};
48+
49+
std::vector<fn_lambda*> m_lambdas;
50+
4251
private:
4352

4453
constexpr void set_lambda(const dispatch::lambda_base* p_lambda) const {

ReflectionTemplateLib/rtl/dispatch/method_ptr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace rtl::dispatch
2020
{
2121
template<class record_t, class return_t, class ...signature_t>
22-
struct method_ptr : functor//, fn_meta
22+
struct method_ptr : functor
2323
{
2424
using functor_t = return_t(record_t::*)(signature_t...);
2525

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 <[email protected]> *
7+
* SPDX-License-Identifier: MIT *
8+
* *
9+
*************************************************************************/
10+
11+
12+
#pragma once
13+
14+
#include "function_ptr.h"
15+
16+
namespace rtl::dispatch
17+
{
18+
template<class return_t, class ...signature_t>
19+
void rtl::dispatch::function_ptr<return_t, signature_t...>::init_erased_fn()
20+
{
21+
erased_fn = func_et();
22+
m_lambdas.push_back(&std::get<func_et>(erased_fn));
23+
}
24+
25+
template<class return_t, class ...signature_t>
26+
void function_ptr<return_t, signature_t...>::init_erased_ctor()
27+
{
28+
erased_fn = ctor_et();
29+
m_lambdas.push_back(&std::get<ctor_et>(erased_fn));
30+
}
31+
}

ReflectionTemplateLib/rtl/dispatch/method_ptr_const.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace rtl::dispatch
2020
{
2121
template<class record_t, class return_t, class ...signature_t>
22-
struct method_ptr<const record_t, return_t, signature_t...> : functor//, fn_meta
22+
struct method_ptr<const record_t, return_t, signature_t...> : functor
2323
{
2424
using functor_t = return_t(record_t::*)(signature_t...) const;
2525

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 <[email protected]> *
7+
* SPDX-License-Identifier: MIT *
8+
* *
9+
*************************************************************************/
10+
11+
12+
#pragma once
13+
14+
#include "function_ptr.h"
15+
16+
namespace rtl::dispatch
17+
{
18+
template<class return_t, class ...signature_t>
19+
void rtl::dispatch::function_ptr<return_t, signature_t...>::init_erased_fn()
20+
{
21+
erased_fn = func_et();
22+
m_lambdas.push_back(&std::get<func_et>(erased_fn));
23+
}
24+
25+
template<class return_t, class ...signature_t>
26+
void function_ptr<return_t, signature_t...>::init_erased_ctor()
27+
{
28+
erased_fn = ctor_et();
29+
m_lambdas.push_back(&std::get<ctor_et>(erased_fn));
30+
}
31+
}

0 commit comments

Comments
 (0)