Skip to content

Commit 3ee7a28

Browse files
committed
Cloning code-path flow changed, major refactor.
1 parent 4e215c9 commit 3ee7a28

32 files changed

+422
-289
lines changed
File renamed without changes.

CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace proxy_test
1919
{
2020
const auto orgMethod = OriginalReflection::getClass()->getMethod(pFunctionName);
2121
if (!orgMethod.has_value()) {
22-
return { rtl::error::FunctionNotRegisterd, rtl::RObject{ } };
22+
return { rtl::error::FunctionNotRegistered, rtl::RObject{ } };
2323
}
2424
if (orgMethod->hasSignature<_args...>()) {
2525
return orgMethod->bind(m_originalObj).call(std::forward<_args>(params)...);
@@ -44,7 +44,7 @@ namespace proxy_test
4444
{
4545
const auto orgMethod = OriginalReflection::getClass()->getMethod(pFunctionName);
4646
if (!orgMethod.has_value()) {
47-
return { rtl::error::FunctionNotRegisterd, rtl::RObject{ } };
47+
return { rtl::error::FunctionNotRegistered, rtl::RObject{ } };
4848
}
4949
if (orgMethod->hasSignature<_args...>()) {
5050
return orgMethod->bind().call(std::forward<_args>(params)...);

RTLBenchmarkApp/src/BenchMark.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
namespace {
1010

11-
static const char* LONG_STR = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
12-
"do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
13-
"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
14-
"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
15-
"eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id"
16-
"Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo";
11+
static const char* LONG_STR = "Lorem ipsum";
12+
// dolor sit amet, consectetur adipiscing elit, sed do"
13+
//"do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
14+
//"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
15+
//"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
16+
//"eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id"
17+
//"Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo";
1718
}
1819

1920
// Pre-created string to isolate call overhead

RTLBenchmarkApp/src/BenchMark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using argStr_t = std::string_view;
1616
using retStr_t = std::string_view;
1717

18-
#define WORK_LOAD(S) (std::string(S) + std::string(S))
18+
#define WORK_LOAD(S) (std::string(S))
1919

2020

2121
namespace rtl_bench

RTLTestRunApp/src/FunctionalityTests/NameSpaceGlobalsTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ namespace rtl_tests
5959
{
6060
//Now for cases, if you want to handle it type-erased and pass around.
6161
RObject reflChar = rtl::reflect('Q');
62+
error reterr = cxx::mirror().enableCloning(reflChar);
63+
ASSERT_TRUE(reterr == error::None);
6264
{
6365
//Internally calls the copy constructor.
6466
auto [err, rchar] = reflChar.clone<rtl::alloc::Stack>();

RTLTestRunApp/src/FunctionalityTests/ReflectionOpErrorCodeTests.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* rtl::error::NonConstOverloadMissing
99
* rtl::error::ConstCallViolation
1010
* and,
11-
* rtl::error::FunctionNotRegisterd, is not internally used by RTL.
11+
* rtl::error::FunctionNotRegistered, is not internally used by RTL.
1212
* Function/Method objects are returned wrapped in std::optional<>, which will
1313
* be empty if its not in registered in Reflection-system.
1414
*
@@ -69,6 +69,10 @@ namespace rtl_tests
6969
{
7070
char ch = 'R';
7171
RObject rCh = rtl::reflect(ch);
72+
73+
error reterr = cxx::mirror().enableCloning(rCh);
74+
ASSERT_TRUE(reterr == error::None);
75+
7276
EXPECT_FALSE(rCh.isAllocatedByRtl());
7377
{
7478
auto [err, rch] = rCh.clone<alloc::Stack, copy::Value>();
@@ -105,10 +109,14 @@ namespace rtl_tests
105109

106110
{
107111
RObject rChptr = rtl::reflect(chPtr);
108-
112+
109113
ASSERT_FALSE(rChptr.isEmpty());
110114
EXPECT_FALSE(rChptr.isAllocatedByRtl());
111115
ASSERT_TRUE(rtl::getRtlManagedHeapInstanceCount() == 1);
116+
117+
error reterr = cxx::mirror().enableCloning(rChptr);
118+
ASSERT_TRUE(reterr == error::None);
119+
112120
EXPECT_TRUE(rChptr.canViewAs<char>());
113121
{
114122
auto viewCh = rChptr.view<char>();
@@ -187,11 +195,20 @@ namespace rtl_tests
187195
ASSERT_FALSE(event.isEmpty());
188196

189197
// Try to call copy-constructor of class Event.
190-
auto [err2, eventCp] = event.clone<alloc::Heap>();
198+
auto [err2, eventCp0] = event.clone<alloc::Heap>();
199+
200+
EXPECT_TRUE(err2 == error::CloningDisabled);
201+
ASSERT_TRUE(eventCp0.isEmpty());
202+
203+
error reterr = cxx::mirror().enableCloning(event);
204+
ASSERT_TRUE(reterr == error::None);
205+
206+
// Try to call copy-constructor of class Event.
207+
auto [err3, eventCp1] = event.clone<alloc::Heap>();
191208

192209
// Cannot create heap instance: Calender's copy constructor is deleted.
193-
EXPECT_TRUE(err2 == error::TypeNotCopyConstructible);
194-
ASSERT_TRUE(eventCp.isEmpty());
210+
EXPECT_TRUE(err3 == error::TypeNotCopyConstructible);
211+
ASSERT_TRUE(eventCp1.isEmpty());
195212
}
196213
EXPECT_TRUE(calender::assert_zero_instance_count());
197214
ASSERT_TRUE(rtl::getRtlManagedHeapInstanceCount() == 0);

RTLTestRunApp/src/FunctionalityTests/ReturnValueReflectionTest.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,22 @@ namespace rtl_tests
4646
ASSERT_FALSE(event.isEmpty());
4747
EXPECT_TRUE(event.getTypeId() == reflected_id::event);
4848
{
49-
auto [err, robj] = event.clone<rtl::alloc::Heap>();
50-
//Event's copy-constructor private or deleted.
51-
EXPECT_TRUE(err == rtl::error::TypeNotCopyConstructible);
52-
ASSERT_TRUE(robj.isEmpty());
53-
// Two 'Event' instances, owned by 'Calender'
54-
EXPECT_TRUE(event::get_instance_count() == 2);
49+
{
50+
auto [err, robj] = event.clone<rtl::alloc::Heap>();
51+
EXPECT_TRUE(err == rtl::error::CloningDisabled);
52+
}
53+
54+
rtl::error reterr = cxx::mirror().enableCloning(event);
55+
ASSERT_TRUE(reterr == rtl::error::None);
56+
57+
{
58+
auto [err, robj] = event.clone<rtl::alloc::Heap>();
59+
//Event's copy-constructor private or deleted.
60+
EXPECT_TRUE(err == rtl::error::TypeNotCopyConstructible);
61+
ASSERT_TRUE(robj.isEmpty());
62+
// Two 'Event' instances, owned by 'Calender'
63+
EXPECT_TRUE(event::get_instance_count() == 2);
64+
}
5565
} {
5666
auto [err, robj] = event.clone<rtl::alloc::Stack>();
5767
//Event's copy-constructor private or deleted.

RTLTestRunApp/src/RObjectTests/RObjectReflecting_stdSharedPtr.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
using namespace test_utils;
99
using namespace rtl;
1010

11+
namespace {
12+
13+
// Cloning is only available for types explicitly registered by the user.
14+
// This is because cloning requires a lambda to be stored in a static table.
15+
// Types reflected via rtl::reflect or obtained as the return value of a reflective call
16+
// cannot be cloned unless they are explicitly registered.
17+
18+
static rtl::CxxMirror cxx_mirror()
19+
{
20+
static rtl::CxxMirror m = rtl::CxxMirror({
21+
rtl::type().record<int>("int").build(),
22+
rtl::type().record<Node>("Node").build()
23+
});
24+
return m;
25+
}
26+
}
27+
1128
namespace rtl::unit_test
1229
{
1330
TEST(RObject_reflecting_shared_ptr, sharing_semantics__pod)
@@ -101,6 +118,10 @@ namespace rtl::unit_test
101118
{
102119
constexpr const int NUM = -20438;
103120
RObject robj = reflect(std::make_shared<int>(NUM));
121+
122+
error reterr = cxx_mirror().enableCloning(robj);
123+
ASSERT_TRUE(reterr == error::None);
124+
104125
ASSERT_FALSE(robj.isEmpty());
105126

106127
// --- Step 1: Clone by default (entity::Auto semantics) ---
@@ -193,6 +214,9 @@ namespace rtl::unit_test
193214
RObject robj = reflect(std::make_shared<int>(NUM));
194215
ASSERT_FALSE(robj.isEmpty());
195216

217+
error reterr = cxx_mirror().enableCloning(robj);
218+
ASSERT_TRUE(reterr == error::None);
219+
196220
// --- Step 1: Clone by default (entity::Auto semantics) ---
197221
{
198222
// Default cloning shallow-copies the wrapper.
@@ -247,6 +271,9 @@ namespace rtl::unit_test
247271
ASSERT_FALSE(robj.isEmpty());
248272
ASSERT_TRUE(Node::instanceCount() == 1);
249273

274+
error reterr = cxx_mirror().enableCloning(robj);
275+
ASSERT_TRUE(reterr == error::None);
276+
250277
// --- Step 2: Clone by default (entity::Auto semantics) ---
251278
{
252279
// Default cloning shallow-copies the wrapper.
@@ -326,6 +353,10 @@ namespace rtl::unit_test
326353
{
327354
constexpr const int NUM = 241054;
328355
RObject robj = reflect(std::make_shared<Node>(NUM));
356+
357+
error reterr = cxx_mirror().enableCloning(robj);
358+
ASSERT_TRUE(reterr == error::None);
359+
329360
ASSERT_FALSE(robj.isEmpty());
330361
ASSERT_TRUE(Node::instanceCount() == 1);
331362

@@ -568,6 +599,9 @@ namespace rtl::unit_test
568599
constexpr const int NUM = 10742;
569600
RObject robj = reflect(std::make_shared<Node>(NUM));
570601

602+
error reterr = cxx_mirror().enableCloning(robj);
603+
ASSERT_TRUE(reterr == error::None);
604+
571605
ASSERT_FALSE(robj.isEmpty());
572606
EXPECT_TRUE(robj.canViewAs<std::shared_ptr<Node>>());
573607

ReflectionTemplateLib/access/inc/CxxMirror.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ namespace rtl
1717
{
1818
// Forward declarations
1919
class Record;
20+
class RObject;
2021
class Function;
21-
22+
2223
/* @class CxxMirror
2324
* Provides the primary interface to access registered functions and methods by name.
2425
* This is the single point of access to the entire reflection system.
@@ -49,6 +50,8 @@ namespace rtl
4950
// Constructs CxxMirror using a set of Function objects. All other constructors are disabled.
5051
explicit CxxMirror(const std::vector<Function>& pFunctions);
5152

53+
error enableCloning(const RObject& pTarget) const;
54+
5255
// Returns a Record containing function hash-keys for the given record ID.
5356
std::optional<Record> getRecord(const std::size_t pRecordId) const;
5457

ReflectionTemplateLib/access/inc/Function.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ namespace rtl {
6060

6161
void addOverload(const Function& pOtherFunc) const;
6262

63-
GETTER_REF(std::vector<detail::FunctorId>, FunctorIds, m_functorIds)
64-
6563
protected:
6664

6765
Function(const Function& pOther, const detail::FunctorId& pFunctorId,
@@ -71,6 +69,8 @@ namespace rtl {
7169

7270
GETTER(detail::methodQ, Qualifier, m_qualifier);
7371

72+
GETTER_REF(std::vector<detail::FunctorId>, FunctorIds, m_functorIds)
73+
7474
public:
7575

7676
//simple inlined getters.

0 commit comments

Comments
 (0)