Skip to content

Commit df419e9

Browse files
committed
comments added
1 parent 7da7009 commit df419e9

31 files changed

+1000
-623
lines changed

CxxReflectionTests/src/ConstMethodOverloadTests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,42 @@ namespace rtl_tests
6969
}
7070

7171

72+
TEST(ConstMethodOverload, const_method_no_overload_call_on_const_target_returns_string)
73+
{
74+
{
75+
CxxMirror& cxxMirror = MyReflection::instance();
76+
77+
optional<Record> recOpt = cxxMirror.getRecord(person::class_);
78+
ASSERT_TRUE(recOpt.has_value());
79+
80+
const Record& classPerson = recOpt.value();
81+
optional<Method> updateLastName = classPerson.getMethod(person::str_updateLastName);
82+
ASSERT_TRUE(updateLastName);
83+
84+
const std::string firstName = person::FIRST_NAME;
85+
auto [status, personObj] = classPerson.instance(firstName);
86+
87+
ASSERT_TRUE(status);
88+
ASSERT_FALSE(personObj.isEmpty());
89+
90+
personObj.makeConst();
91+
ASSERT_TRUE(personObj.isConst());
92+
93+
optional<Method> getFirstName = classPerson.getMethod(person::str_getFirstName);
94+
ASSERT_TRUE(getFirstName);
95+
96+
const RStatus& rstatus = getFirstName->on(personObj).call();
97+
ASSERT_TRUE(rstatus);
98+
ASSERT_TRUE(rstatus.isOfType<std::string>());
99+
100+
const std::string retStr = std::any_cast<std::string>(rstatus.getReturn());
101+
ASSERT_EQ(retStr, firstName);
102+
}
103+
EXPECT_TRUE(person::assert_zero_instance_count());
104+
EXPECT_TRUE(Instance::getInstanceCount() == 0);
105+
}
106+
107+
72108
TEST(ConstMethodOverload, const_method_string_call_on_const_target)
73109
{
74110
{

CxxTestProject/inc/Person.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Person
2222

2323
void updateAddress() const;
2424

25+
std::string getFirstName() const;
26+
2527
void updateAddress(std::string pAddress);
2628

2729
void updateAddress(std::string pAddress) const;

CxxTestProject/src/Person.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ void Person::updateAddress() const
6262
}
6363

6464

65+
std::string Person::getFirstName() const
66+
{
67+
return m_firstName;
68+
}
69+
70+
6571
const bool Person::operator==(const Person& pOther) const
6672
{
6773
return (m_address == pOther.m_address && m_firstName == pOther.m_firstName && m_lastName == pOther.m_lastName);

CxxTypeRegistration/inc/TestUtilsPerson.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace test_utils
2121
static constexpr const char* class_ = "Person";
2222
static constexpr const char* str_getProfile = "getProfile";
2323
static constexpr const char* str_getDefaults = "getDefaults";
24+
static constexpr const char* str_getFirstName = "getFirstName";
2425
static constexpr const char* str_updateAddress = "updateAddress";
2526
static constexpr const char* str_updateLastName = "updateLastName";
2627

CxxTypeRegistration/src/MyReflection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ CxxMirror& MyReflection::instance()
6969
Reflect().record<Person>(person::class_).constructor<const Person&>().build(), //copy constructor taking const ref argument.
7070
Reflect().record<Person>(person::class_).method<void>(person::str_updateAddress).build(&Person::updateAddress),
7171
Reflect().record<Person>(person::class_).method<string>(person::str_updateAddress).build(&Person::updateAddress),
72+
Reflect().record<Person>(person::class_).methodConst(person::str_getFirstName).build(&Person::getFirstName),
7273
Reflect().record<Person>(person::class_).methodConst(person::str_updateLastName).build(&Person::updateLastName), //const method registration, 'methodConst()' function must be used. compiler error otherwise.
7374
Reflect().record<Person>(person::class_).methodConst<void>(person::str_updateAddress).build(&Person::updateAddress),
7475
Reflect().record<Person>(person::class_).methodConst<string>(person::str_updateAddress).build(&Person::updateAddress), //overloaded method based on 'const'.

ReflectionTemplateLib/access/inc/CxxMirror.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ namespace rtl {
2020
* all the type registration is done while constructing its object.
2121
* its objects can be createed locally and will be destroyed as regular object, at scope's end.
2222
* deleted copy constructor and assignment operator, can only be passed around as reference or wrapped in a smart pointer.
23-
* the inherited data members are freed upon destruction, except the functors (function/method pointer) tables, they have static lifetime.
24-
* functor tables are not member of this or base class, this class contains 'Function' objects which is a hash-key for looking up a particular functor.
25-
* creating multiple objects of CxxMirror and registring the same functor will not increase the functor tables size.
26-
* once a functor is registered, no entry will be added to the functor table for the same functor, it acts as a set.
27-
* registring the same functor will create duplicate hash-key 'Function' object, which will be ignored if in the same 'CxxMirror' object.
28-
if two different 'CxxMirror' objects are created and registering the same functor, the functor table will have only one entry for the functor
29-
but two duplicate 'Function' objects will be created, held by respective 'CxxMirror' object.
23+
* the inherited data members are freed upon destruction, except the 'functor-containers', they have static lifetime.
24+
* 'functor-containers' are not member of this or base class, base only contains 'Function' objects which is a hash-key for looking up a particular functor.
25+
* creating multiple objects of CxxMirror and registring the same functor will not increase the 'functor-container' size.
26+
* once a functor is registered, no entry will be added to the 'functor-container' for the same functor.
27+
* registering the same functor will create duplicate hash-key 'Function' object, which will be ignored if in the same 'CxxMirror' object.
28+
if two different 'CxxMirror' objects are created and registering the same functor, the functor-container will have only one entry for the functor
29+
but two identical 'Function' objects will be created, held by respective 'CxxMirror' object.
3030
*/ class CxxMirror : public detail::CxxReflection
3131
{
3232
public:

ReflectionTemplateLib/access/inc/Function.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace rtl {
1717
*/ template<class _arg0, class ..._args>
1818
inline const bool Function::hasSignature() const
1919
{
20-
//hasSignatureId() returns the index of functor in functor table, which cannot be '-1'.
20+
//hasSignatureId() returns the index of the 'lambda' in functor-container, which cannot be '-1'.
2121
return (hasSignatureId(detail::FunctorContainer<_arg0, _args...>::getContainerId()) != -1);
2222
}
2323

@@ -28,7 +28,7 @@ namespace rtl {
2828
*/ template<>
2929
inline const bool Function::hasSignature<void>() const
3030
{
31-
//hasSignatureId() returns the index of functor in functor table, which cannot be '-1'.
31+
//hasSignatureId() returns the index of 'lambda' in functor-container, which cannot be '-1'.
3232
return (hasSignatureId(detail::FunctorContainer<>::getContainerId()) != -1);
3333
}
3434

ReflectionTemplateLib/access/inc/Method.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ namespace rtl {
7171
*/ class Method : public Function
7272
{
7373
//private ctor, called by 'Record' class.
74-
Method(const Function& pFunction);
74+
explicit Method(const Function& pFunction);
7575

7676
//private ctor, called by 'Record' class.
77-
Method(const Function& pFunction, const detail::FunctorId& pFunctorId, const std::string& pFunctorName);
77+
explicit Method(const Function& pFunction, const detail::FunctorId& pFunctorId, const std::string& pFunctorName);
7878

7979
//invokes the constructor associated with this 'Method'
8080
template<class ..._args>

ReflectionTemplateLib/access/inc/Method.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace rtl
1717
@params: params... (corresponding to functor associated with 'm_method')
1818
@return: RStatus, indicating success of the reflected call.
1919
* invokes non-static-member-function functor associated with 'm_method' on object 'm_target'.
20-
*/ template<FunctorType _type>
20+
*/ template<FunctorType _type>
2121
template<class ..._args>
2222
inline RStatus MethodInvoker<_type>::call(_args ...params) const noexcept
2323
{
@@ -27,7 +27,7 @@ namespace rtl
2727
}
2828

2929
if (m_target.getTypeId() != m_method.getRecordTypeId()) {
30-
//if the m_target's type-id & type-id of the 'class/struct' owner of the associated functor(m_method's) do not match.
30+
//if the m_target's type-id & type-id of the 'class/struct' owner of the associated functor(m_method's) do not match.
3131
return RStatus(Error::InstanceTypeMismatch);
3232
}
3333

@@ -40,7 +40,7 @@ namespace rtl
4040
case TypeQ::Const: return m_method.invokeConst(m_target, params...);
4141
}
4242

43-
//only an empty 'Instance' will have TypeQ::None.
43+
//only an empty 'Instance' will have TypeQ::None.
4444
return RStatus(Error::EmptyInstance);
4545
}
4646

@@ -60,7 +60,7 @@ namespace rtl
6060

6161

6262
namespace access
63-
{
63+
{
6464
/* @method: on()
6565
@return: MethodInvoker<FunctorType::Static>
6666
* accepts no arguments for 'target', since associated functor is static-member-functions.
@@ -70,7 +70,10 @@ namespace rtl
7070
}
7171

7272

73-
inline const MethodInvoker<FunctorType::Method> Method::on(const Instance& pTarget) const
73+
/* @method: on()
74+
@return: MethodInvoker<FunctorType::Method>
75+
* accepts 'pTarget', which contains the actual object on which the member-function functor associated with 'this' is invoked.
76+
*/ inline const MethodInvoker<FunctorType::Method> Method::on(const Instance& pTarget) const
7477
{
7578
return MethodInvoker<FunctorType::Method>(*this, pTarget);
7679
}
@@ -88,9 +91,9 @@ namespace rtl
8891

8992

9093
/* @method: invokeStatic()
91-
@params: variable arguments.
92-
@return: RStatus
93-
* with given arguments, calls the static-member-function functor associated with this 'Method'.
94+
@params: variable arguments.
95+
@return: RStatus
96+
* with given arguments, calls the static-member-function functor associated with this 'Method'.
9497
*/ template<class ..._args>
9598
inline RStatus Method::invokeStatic(_args ...params) const
9699
{
@@ -173,7 +176,7 @@ namespace rtl
173176
return detail::MethodContainer<TypeQ::Mute, _args...>::forwardCall(pTarget.get(), index, params...);
174177
}
175178
else {
176-
//if no such member-functor is found in non-const MethodContainer, check if such functor is present in const MethodContainer.
179+
//if no such member-functor is found in non-const MethodContainer, check if such functor is present in const MethodContainer and call.
177180
return invokeConst(pTarget, params...);
178181
}
179182
}

ReflectionTemplateLib/access/inc/RStatus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace rtl
3232
//used when the reflected call doesn't have any return value, or in case of call failure.
3333
RStatus(const Error pCallStatus);
3434

35-
//used when the reflected call returns a value, always in case of no call failure.
35+
//used when the reflected call returns a value, called only in case of no call failure.
3636
RStatus(const std::any& pRetObj, const std::size_t pTypeId, const TypeQ pQualifier);
3737

3838
GETTER(std::any, Return, m_returnObj)

0 commit comments

Comments
 (0)