Skip to content

Commit 36087b4

Browse files
committed
introduced rtl::Return, removed std::pair<error, RObject>.
1 parent 0a0c3fa commit 36087b4

File tree

24 files changed

+129
-129
lines changed

24 files changed

+129
-129
lines changed

CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace proxy_test {
3030
* @return The result of the function call as a std::any object.
3131
*/
3232
template<class ..._args>
33-
std::pair<rtl::error, rtl::RObject> forwardCall(const std::string& pFunctionName, _args&& ...params);
33+
rtl::Return forwardCall(const std::string& pFunctionName, _args&& ...params);
3434

3535
/**
3636
* @brief Forwards a call to a static method of the "Original" class.
@@ -41,6 +41,6 @@ namespace proxy_test {
4141
* @return The result of the function call as a std::any object.
4242
*/
4343
template<class ..._args>
44-
static std::pair<rtl::error, rtl::RObject> forwardStaticCall(const std::string& pFunctionName, _args&& ...params);
44+
static rtl::Return forwardStaticCall(const std::string& pFunctionName, _args&& ...params);
4545
};
4646
}

CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace proxy_test
1515
* @return The result of the function call as a std::any object. If the method does not exist or the signature does not match, returns an empty std::any object.
1616
*/
1717
template<class ..._args>
18-
inline std::pair<rtl::error, rtl::RObject> Proxy::forwardCall(const std::string& pFunctionName, _args&& ...params)
18+
inline rtl::Return Proxy::forwardCall(const std::string& pFunctionName, _args&& ...params)
1919
{
2020
const auto orgMethod = OriginalReflection::getClass()->getMethod(pFunctionName);
2121
if (!orgMethod.has_value()) {
@@ -40,7 +40,7 @@ namespace proxy_test
4040
* @return The result of the function call as a std::any object. If the method does not exist or the signature does not match, returns an empty std::any object.
4141
*/
4242
template<class ..._args>
43-
inline std::pair<rtl::error, rtl::RObject> Proxy::forwardStaticCall(const std::string& pFunctionName, _args&& ...params)
43+
inline rtl::Return Proxy::forwardStaticCall(const std::string& pFunctionName, _args&& ...params)
4444
{
4545
const auto orgMethod = OriginalReflection::getClass()->getMethod(pFunctionName);
4646
if (!orgMethod.has_value()) {

RTLBenchmarkApp/src/BenchMark.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,21 @@ namespace rtl_bench
9494
static auto sendMsgCall = sendMsg.bind<const char*>();
9595
for (auto _ : state)
9696
{
97-
benchmark::DoNotOptimize(sendMsgCall.call("reflected"));//*/.call("reflected"));
97+
benchmark::DoNotOptimize(sendMsgCall.call("reflected"));
9898
}
9999
}
100100

101101

102102
void BenchMark::reflectedMethodCall_noReturn(benchmark::State& state)
103103
{
104-
//rtl::Record rNode = cxx_mirror().getRecord("node").value();
105-
//rtl::Method sendMsg = rNode.getMethod("sendMessage").value();
106-
//rtl::RObject robj = rNode.create<rtl::alloc::Stack>().second;
107-
108-
//for (auto _ : state)
109-
//{
110-
// benchmark::DoNotOptimize(sendMsg.bind<const char*>(robj).call("reflected"));
111-
//}
104+
static rtl::Record rNode = cxx_mirror().getRecord("node").value();
105+
static rtl::Method sendMsg = rNode.getMethod("sendMessage").value();
106+
static rtl::RObject robj = rNode.create<rtl::alloc::Stack>().robj;
107+
108+
for (auto _ : state)
109+
{
110+
benchmark::DoNotOptimize(sendMsg.bind<const char*>(robj).call("reflected"));
111+
}
112112
}
113113

114114

@@ -146,13 +146,13 @@ namespace rtl_bench
146146

147147
void BenchMark::reflectedMethodCall_withReturn(benchmark::State& state)
148148
{
149-
//rtl::Record rNode = cxx_mirror().getRecord("node").value();
150-
//rtl::Method getMsg = rNode.getMethod("getMessage").value();
151-
//rtl::RObject robj = rNode.create<rtl::alloc::Stack>().second;
152-
153-
//for (auto _ : state)
154-
//{
155-
// benchmark::DoNotOptimize(getMsg.bind<const char*>(robj).call("reflected"));
156-
//}
149+
static rtl::Record rNode = cxx_mirror().getRecord("node").value();
150+
static rtl::Method getMsg = rNode.getMethod("getMessage").value();
151+
static rtl::RObject robj = rNode.create<rtl::alloc::Stack>().robj;
152+
153+
for (auto _ : state)
154+
{
155+
benchmark::DoNotOptimize(getMsg.bind<const char*>(robj).call("reflected"));
156+
}
157157
}
158158
}

RTLBenchmarkApp/src/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
BENCHMARK(rtl_bench::BenchMark::directCall_noReturn);
1212
BENCHMARK(rtl_bench::BenchMark::lambdaCall_noReturn);
1313
BENCHMARK(rtl_bench::BenchMark::reflectedCall_noReturn);
14-
//BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_noReturn);
15-
//BENCHMARK(rtl_bench::BenchMark::directCall_withReturn);
16-
//BENCHMARK(rtl_bench::BenchMark::lambdaCall_withReturn);
17-
//BENCHMARK(rtl_bench::BenchMark::reflectedCall_withReturn);
18-
//BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_withReturn);
14+
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_noReturn);
15+
BENCHMARK(rtl_bench::BenchMark::directCall_withReturn);
16+
BENCHMARK(rtl_bench::BenchMark::lambdaCall_withReturn);
17+
BENCHMARK(rtl_bench::BenchMark::reflectedCall_withReturn);
18+
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_withReturn);
1919
BENCHMARK_MAIN();

ReflectionTemplateLib/access/inc/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace rtl {
9292
bool hasSignature() const;
9393

9494
template<class ..._args>
95-
std::pair<error, RObject> operator()(_args&&...params) const noexcept;
95+
Return operator()(_args&&...params) const noexcept;
9696

9797
template<class ..._signature>
9898
const detail::FunctionCaller<_signature...> bind() const;

ReflectionTemplateLib/access/inc/Function.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ namespace rtl
3737

3838
/* @method: operator()()
3939
@param: variadic arguments.
40-
@return: std::pair<error, RObject>, possible error & return value of from the reflected call.
40+
@return: Return, possible error & return value of from the reflected call.
4141
* if the arguments did not match with any overload, returns RObject with error::SignatureMismatch
4242
* providing optional syntax, Function::call() does the exact same thing.
4343
*/ template<class ..._args>
44-
inline std::pair<error, RObject> Function::operator()(_args&& ...params) const noexcept
44+
inline Return Function::operator()(_args&& ...params) const noexcept
4545
{
4646
return bind().call(std::forward<_args>(params)...);
4747
}

ReflectionTemplateLib/access/inc/Method.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace rtl {
4343

4444
//invokes the constructor associated with this 'Method'
4545
template<class ..._args>
46-
std::pair<error, RObject> invokeCtor(alloc&& pAllocType, _args&&...params) const;
46+
Return invokeCtor(alloc&& pAllocType, _args&&...params) const;
4747

4848
public:
4949

@@ -94,7 +94,7 @@ namespace rtl {
9494
* provides syntax like, 'method(pTarget)(params...)', keeping the target & params seperate.
9595
*/ constexpr auto operator()(const RObject& pTarget) const
9696
{
97-
return [&](auto&&...params)-> std::pair<error, RObject> {
97+
return [&](auto&&...params)-> Return {
9898
return bind(pTarget).call(std::forward<decltype(params)>(params)...);
9999
};
100100
}

ReflectionTemplateLib/access/inc/Method.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace rtl
3434
@return: RStatus
3535
* calls the constructor with given arguments.
3636
*/ template<class ..._args>
37-
inline std::pair<error, RObject> Method::invokeCtor(alloc&& pAllocType, _args&& ...params) const
37+
inline Return Method::invokeCtor(alloc&& pAllocType, _args&& ...params) const
3838
{
3939
return Function::bind().call<alloc, _args...>(std::forward<alloc>(pAllocType), std::forward<_args>(params)...);
4040
}

ReflectionTemplateLib/access/inc/RObject.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace rtl::detail
3434

3535
namespace rtl
3636
{
37+
struct Return;
3738
class Function;
3839

3940
//Reflecting the object within.
@@ -55,7 +56,7 @@ namespace rtl
5556
std::size_t getConverterIndex(const std::size_t pToTypeId) const;
5657

5758
template<rtl::alloc _allocOn, detail::EntityKind _entityKind>
58-
std::pair<rtl::error, RObject> createCopy() const;
59+
Return createCopy() const;
5960

6061
template<class T>
6162
std::optional<rtl::view<T>> performConversion(const std::size_t pIndex) const;
@@ -83,7 +84,7 @@ namespace rtl
8384
bool canViewAs() const;
8485

8586
template<rtl::alloc _allocOn, rtl::copy _copyTarget = rtl::copy::Auto>
86-
std::pair<rtl::error, RObject> clone() const;
87+
Return clone() const;
8788

8889
template<class T, std::enable_if_t<traits::is_unique_ptr_v<T>, int> = 0>
8990
std::optional<rtl::view<T>> view() const;
@@ -100,4 +101,9 @@ namespace rtl
100101
friend detail::RObjExtractor;
101102
friend detail::RObjectBuilder;
102103
};
104+
105+
struct [[nodiscard]] Return {
106+
error err;
107+
RObject robj;
108+
};
103109
}

ReflectionTemplateLib/access/inc/RObject.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace rtl
4141
// Explicitly clear moved-from source
4242
pOther.m_object.reset();
4343
pOther.m_objectId = { };
44-
pOther.m_getClone = nullptr;
44+
//pOther.m_getClone = nullptr;
4545
pOther.m_converters = nullptr;
4646
}
4747

@@ -161,37 +161,39 @@ namespace rtl
161161
namespace rtl
162162
{
163163
template<>
164-
inline std::pair<error, RObject> RObject::createCopy<alloc::Heap, detail::EntityKind::Value>() const
164+
inline Return RObject::createCopy<alloc::Heap, detail::EntityKind::Value>() const
165165
{
166166
error err = error::None;
167-
return { err, m_getClone(err, *this, alloc::Heap) };
167+
RObject robj/*;//*/ = m_getClone(err, *this, alloc::Heap);
168+
return { err, std::move(robj) };
168169
}
169170

170171

171172
template<>
172-
inline std::pair<error, RObject> RObject::createCopy<alloc::Stack, detail::EntityKind::Value>() const
173+
inline Return RObject::createCopy<alloc::Stack, detail::EntityKind::Value>() const
173174
{
174175
error err = error::None;
175-
return { err, m_getClone(err, *this, alloc::Stack) };
176+
RObject robj/*;//*/ = m_getClone(err, *this, alloc::Stack);
177+
return { err, std::move(robj) };
176178
}
177179

178180

179181
template<>
180-
inline std::pair<error, RObject> RObject::createCopy<alloc::Heap, detail::EntityKind::Wrapper>() const
182+
inline Return RObject::createCopy<alloc::Heap, detail::EntityKind::Wrapper>() const
181183
{
182-
return { error::StlWrapperHeapAllocForbidden, RObject{ } };
184+
return { error::StlWrapperHeapAllocForbidden, RObject{} };
183185
}
184186

185187

186188
template<>
187-
inline std::pair<error, RObject> RObject::createCopy<alloc::Stack, detail::EntityKind::Wrapper>() const
189+
inline Return RObject::createCopy<alloc::Stack, detail::EntityKind::Wrapper>() const
188190
{
189191
if (m_objectId.m_wrapperType == detail::Wrapper::None) {
190-
return { error::NotWrapperType, RObject{ } };
192+
return { error::NotWrapperType, RObject{} };
191193
}
192194
else if (m_objectId.m_wrapperType == detail::Wrapper::Unique)
193195
{
194-
return { error::TypeNotCopyConstructible, RObject{ } };
196+
return { error::TypeNotCopyConstructible, RObject{} };
195197
}
196198
else {
197199
return { error::None, RObject(*this) };
@@ -200,7 +202,7 @@ namespace rtl
200202

201203

202204
template<alloc _allocOn, copy _copyTarget>
203-
inline std::pair<error, RObject> RObject::clone() const
205+
inline Return RObject::clone() const
204206
{
205207
if (isEmpty()) {
206208
return { error::EmptyRObject, RObject{ } };

0 commit comments

Comments
 (0)