diff --git a/CxxReflectionTests/src/RTLUnitTests.cpp b/CxxReflectionTests/src/RTLUnitTests.cpp index 423f9f69..d7fd7c5d 100644 --- a/CxxReflectionTests/src/RTLUnitTests.cpp +++ b/CxxReflectionTests/src/RTLUnitTests.cpp @@ -48,11 +48,41 @@ int main() const auto& classDateOpt = cxxMirror.getRecord("test_project", "Date"); std::cout << "\n\n[Reflection]-------Constructor/Destroctor call--------"; if (classDateOpt.has_value()) { + + std::cout << "\nCreating \"Date\" instances via reflection.."; + const auto& classDate = classDateOpt.value(); auto dateObj0 = classDate.newInstance(); + if (dateObj0 == nullptr) { + std::cout << "\nError..! \"Date()\" ctor call via reflection failed."; + return 0; + } + const std::string& dateStr = "17/06/2024"; auto dateObj1 = classDate.newInstance(dateStr); + + if (dateObj1 == nullptr) { + std::cout << "\nError..! \"Date(std::string)\" ctor call via reflection failed."; + return 0; + } + + + std::cout << "\n\n[Reflection]-------Member function call--------"; + const auto& getDateOpt = classDate.getMethod("getDateAsString"); + if (getDateOpt.has_value()) { + const auto& getDateStr = getDateOpt.value(); + const auto& retOpt = getDateStr(dateObj1).invoke(); + + if (retOpt != nullptr) { + std::cout << "\ncall to Date::getDateAsString() return value : " << retOpt->get().value(); + } + } + else { + std::cout << "error..! couldn't resolve function call - Date::getDateAsString()."; + } + + std::cout << "\n\"Date\" instances created via reflection will destroy now.\n"; } std::cout << std::endl; diff --git a/CxxTestProject/inc/Date.h b/CxxTestProject/inc/Date.h index 9e228a87..1a8518c9 100644 --- a/CxxTestProject/inc/Date.h +++ b/CxxTestProject/inc/Date.h @@ -12,5 +12,7 @@ namespace test_project ~Date(); Date(const std::string& pDateStr); const bool operator==(const Date& pOther) const; + + std::string getDateAsString(); }; } \ No newline at end of file diff --git a/CxxTestProject/src/Date.cpp b/CxxTestProject/src/Date.cpp index e163152d..cd814e71 100644 --- a/CxxTestProject/src/Date.cpp +++ b/CxxTestProject/src/Date.cpp @@ -49,4 +49,11 @@ namespace test_project { return (m_day == pOther.m_day && m_month == pOther.m_month && m_year == pOther.m_year); } + + + std::string Date::getDateAsString() + { + std::cout << "\n[Method] Date::getDateAsString() called."; + return std::to_string(m_day) + "/" + std::to_string(m_month) + "/" + std::to_string(m_year); + } } \ No newline at end of file diff --git a/CxxTypeRegistration/inc/Reflection.h b/CxxTypeRegistration/inc/Reflection.h index 2a2599e5..3a375198 100644 --- a/CxxTypeRegistration/inc/Reflection.h +++ b/CxxTypeRegistration/inc/Reflection.h @@ -1,6 +1,6 @@ #pragma once -#include "CxxMirror.h" +#include "ReflectionTemplateLib.h" namespace rtl_tests { diff --git a/CxxTypeRegistration/src/Reflection.cpp b/CxxTypeRegistration/src/Reflection.cpp index 79dfec56..b8a852d2 100644 --- a/CxxTypeRegistration/src/Reflection.cpp +++ b/CxxTypeRegistration/src/Reflection.cpp @@ -23,7 +23,9 @@ namespace rtl_tests { Reflect().nameSpace("test_project").record("Date").constructor().build(), //Constructor registration, Date(std::string) - Reflect().nameSpace("test_project").record("Date").constructor().build() + Reflect().nameSpace("test_project").record("Date").constructor().build(), + + Reflect().nameSpace("test_project").record("Date").function("getDateAsString").build(&Date::getDateAsString) }); return cxxMirror; diff --git a/README.md b/README.md index 4c95fb8b..ad8a8351 100644 --- a/README.md +++ b/README.md @@ -81,15 +81,15 @@ const CxxMirror& MyReflection() Registration syntax is simple **Builder Pattern**, ```c++ - Reflect().nameSpace("..") //use if type is enclosed in a namespace, pass namespace as string. - .record("..") //pass class/struct name as string. - .function("..") //pass function name as string. - .build(*); //pass function pointer. +Reflect().nameSpace("..") //use if type is enclosed in a namespace, pass namespace as string. + .record("..") //pass class/struct name as string. + .function("..") //pass function name as string. + .build(*); //pass function pointer. - Reflect().nameSpace("..") - .record("..") - .constructor<..>() //pass struct/class type as template parameter. - .build<..>(); //zero args for constructors, register constructor signature as template params. +Reflect().nameSpace("..") + .record("..") + .constructor<..>() //pass struct/class type as template parameter. + .build<..>(); //zero args for constructors, register constructor signature as template params. ``` - In main.cpp, Use **Person** class via Reflection without exposing the **Person Type**. (*New underlying access-mechanism is in progress. These will not work currenty but final design will stay the same as below.*) @@ -153,5 +153,6 @@ Create instance using overloaded constructor *(the one registered as **ctorArgs< - Unit test cases (WIP) - Class/Struct's Field reflection (Currently only methods are supported). - Enum Class reflection. +- Exception handling (WIP) - Access specifiers for reflection *(presently any Method/Field registerd is considered as public)* -- Light weight JSON Serialization/Deserialization feature. \ No newline at end of file +- Light weight JSON Serialization/Deserialization feature. diff --git a/ReflectionTemplateLib/inc/Constants.h b/ReflectionTemplateLib/inc/Constants.h index 6cb20bc3..78dfd03f 100644 --- a/ReflectionTemplateLib/inc/Constants.h +++ b/ReflectionTemplateLib/inc/Constants.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace rtl { const char* const NS_GLOBAL = "namespace_global"; diff --git a/ReflectionTemplateLib/inc/ConstructorBuilder.h b/ReflectionTemplateLib/inc/ConstructorBuilder.h index 572263e2..c6322964 100644 --- a/ReflectionTemplateLib/inc/ConstructorBuilder.h +++ b/ReflectionTemplateLib/inc/ConstructorBuilder.h @@ -1,9 +1,9 @@ #pragma once -#include "Function.h" - namespace rtl { + class Function; + template class ConstructorBuilder { diff --git a/ReflectionTemplateLib/inc/ConstructorBuilder.hpp b/ReflectionTemplateLib/inc/ConstructorBuilder.hpp index 4d3c9b8b..635ff839 100644 --- a/ReflectionTemplateLib/inc/ConstructorBuilder.hpp +++ b/ReflectionTemplateLib/inc/ConstructorBuilder.hpp @@ -1,3 +1,5 @@ + +#include "Function.h" #include "ConstructorBuilder.h" namespace rtl { diff --git a/ReflectionTemplateLib/inc/CxxMirror.h b/ReflectionTemplateLib/inc/CxxMirror.h index c18974d5..5f7e9756 100644 --- a/ReflectionTemplateLib/inc/CxxMirror.h +++ b/ReflectionTemplateLib/inc/CxxMirror.h @@ -4,11 +4,13 @@ #include #include -#include "RObject.hpp" #include "NameSpace.h" namespace rtl { + class Record; + class Function; + class CxxMirror { std::unordered_map m_namespaces; diff --git a/ReflectionTemplateLib/inc/CxxMirrorBuilder.h b/ReflectionTemplateLib/inc/CxxMirrorBuilder.h index eab0b9ac..741aad1b 100644 --- a/ReflectionTemplateLib/inc/CxxMirrorBuilder.h +++ b/ReflectionTemplateLib/inc/CxxMirrorBuilder.h @@ -1,7 +1,7 @@ #pragma once -#include "Function.hpp" #include "Constants.h" +#include "NameSpace.h" #include "FunctionBuilder.h" #include "ConstructorBuilder.hpp" diff --git a/ReflectionTemplateLib/inc/Function.h b/ReflectionTemplateLib/inc/Function.h index e088d57c..bacb7c25 100644 --- a/ReflectionTemplateLib/inc/Function.h +++ b/ReflectionTemplateLib/inc/Function.h @@ -3,11 +3,13 @@ #include #include -#include "RObject.h" #include "Constants.h" namespace rtl { + class RObject; + class MethodInvoker; + class Function { const std::size_t m_functorId; @@ -19,9 +21,12 @@ namespace rtl { const std::string m_namespace; Function(const std::string& pNamespace, const std::string& pClassName, const std::string& pFuncName, - const std::string& pSignature, const std::size_t& pSignatureId, const std::size_t& pFunctorId); + const std::string& pSignature, const std::size_t& pSignatureId, const std::size_t& pFunctorId); + + template + std::unique_ptr execute(const std::unique_ptr& pTarget, _args...params) const; - public: + public: friend MethodInvoker; Function() = delete; @@ -39,6 +44,11 @@ namespace rtl { static const Function addConstructor(const std::string& pNamespace, const std::string& pRecord); template - static const Function addFunctor(const std::string& pNamespace, const std::string& pRecord, const std::string& pFunction, _returnType(*pFunctor)(_signature...)); + static const Function addFunctor(const std::string& pNamespace, const std::string& pRecord, + const std::string& pFunction, _returnType(*pFunctor)(_signature...)); + + template + static const Function addFunctor(const std::string& pNamespace, const std::string& pRecord, + const std::string& pFunction, _returnType(_recordType::* pFunctor)(_signature...)); }; } \ No newline at end of file diff --git a/ReflectionTemplateLib/inc/Function.hpp b/ReflectionTemplateLib/inc/Function.hpp index b80e403f..16ec641b 100644 --- a/ReflectionTemplateLib/inc/Function.hpp +++ b/ReflectionTemplateLib/inc/Function.hpp @@ -2,7 +2,6 @@ #include "TypeList.h" #include "Function.h" -#include "Constants.h" #include "FunctorContainer.hpp" namespace rtl { @@ -20,6 +19,19 @@ namespace rtl { } + template + inline std::unique_ptr Function::execute(const std::unique_ptr& pTarget, _args ...params) const + { + if (m_signatureId == FunctorContainer<_args...>::getContainerId()) { + return FunctorContainer<_args...>::reflectCall(pTarget, m_functorId, params...); + } + else { + assert(false && "Throw bad call exception"); + } + return nullptr; + } + + template inline const Function Function::addConstructor(const std::string& pNamespace, const std::string& pRecord) { @@ -35,7 +47,19 @@ namespace rtl { template - inline const Function Function::addFunctor(const std::string& pNamespace, const std::string& pClassName, const std::string& pFunctionName, _returnType(*pFunctor)(_signature...)) + inline const Function Function::addFunctor(const std::string& pNamespace, const std::string& pClassName, + const std::string& pFunctionName, _returnType(*pFunctor)(_signature...)) + { + const std::size_t signatureId = FunctorContainer<_signature...>::getContainerId(); + const std::size_t functorId = FunctorContainer<_signature...>::addFunctor(pFunctor); + const std::string& signature = "(" + TypeList<_signature...>::toString() + ")"; + return Function(pNamespace, pClassName, pFunctionName, signature, signatureId, functorId); + } + + + template + inline const Function Function::addFunctor(const std::string& pNamespace, const std::string& pClassName, + const std::string& pFunctionName, _returnType(_recordType::* pFunctor)(_signature...)) { const std::size_t signatureId = FunctorContainer<_signature...>::getContainerId(); const std::size_t functorId = FunctorContainer<_signature...>::addFunctor(pFunctor); diff --git a/ReflectionTemplateLib/inc/FunctionBuilder.h b/ReflectionTemplateLib/inc/FunctionBuilder.h index 962315ea..9c30b0c3 100644 --- a/ReflectionTemplateLib/inc/FunctionBuilder.h +++ b/ReflectionTemplateLib/inc/FunctionBuilder.h @@ -21,5 +21,12 @@ namespace rtl { { return Function::addFunctor(m_namespace, m_record, m_function, pFunctor); } + + + template + inline constexpr const Function build(_returnType(_recordType::* pFunctor)(_signature...)) const + { + return Function::addFunctor(m_namespace, m_record, m_function, pFunctor); + } }; } \ No newline at end of file diff --git a/ReflectionTemplateLib/inc/FunctorContainer.h b/ReflectionTemplateLib/inc/FunctorContainer.h index e9c2e28e..997a82cd 100644 --- a/ReflectionTemplateLib/inc/FunctorContainer.h +++ b/ReflectionTemplateLib/inc/FunctorContainer.h @@ -18,24 +18,36 @@ namespace rtl { public: friend class Function; static const std::size_t& getContainerId(); - using FunctorType = std::function < std::unique_ptr (_signature...)>; + + using FunctorType = std::function < std::unique_ptr (_signature...) >; + using MethodPtrType = std::function < std::unique_ptr (const std::unique_ptr&, _signature...) >; private: static const std::size_t m_containerId; static std::vector m_functors; + static std::vector m_methodPtrs; template - static int addFunctor(_returnType(*pFunctor)(_signature...), enable_if_same<_returnType, void>* _ = nullptr); + static int addFunctor(_returnType(*pFunctor)(_signature...), enable_if_same<_returnType, void> *_ = nullptr); template - static int addFunctor(_returnType(*pFunctor)(_signature...), enable_if_notSame<_returnType, void>* _ = nullptr); + static int addFunctor(_returnType(*pFunctor)(_signature...), enable_if_notSame<_returnType, void> *_ = nullptr); + + template + static int addFunctor(_returnType(_recordType::* pFunctor)(_signature...), enable_if_same<_returnType, void> *_ = nullptr); + + template + static int addFunctor(_returnType(_recordType::* pFunctor)(_signature...), enable_if_notSame<_returnType, void> *_ = nullptr); template static int addConstructor(const std::string& pCtorType); template static std::unique_ptr reflectCall(std::size_t pFunctorId, _params..._args); + + template + static std::unique_ptr reflectCall(const std::unique_ptr& pTarget, std::size_t pFunctorId, _params..._args); }; } diff --git a/ReflectionTemplateLib/inc/FunctorContainer.hpp b/ReflectionTemplateLib/inc/FunctorContainer.hpp index 72398d99..f44b7d74 100644 --- a/ReflectionTemplateLib/inc/FunctorContainer.hpp +++ b/ReflectionTemplateLib/inc/FunctorContainer.hpp @@ -17,6 +17,10 @@ namespace rtl { std::vector::FunctorType> FunctorContainer<_signature...>::m_functors; + template + std::vector::MethodPtrType> FunctorContainer<_signature...>::m_methodPtrs; + + template inline const std::size_t& FunctorContainer<_signature...>::getContainerId() { @@ -38,6 +42,20 @@ namespace rtl { } + template + template + inline std::unique_ptr FunctorContainer<_signature...>::reflectCall(const std::unique_ptr& pTarget, std::size_t pFunctorId, _params ..._args) + { + if (pFunctorId < m_methodPtrs.size()) { + return m_methodPtrs.at(pFunctorId)(pTarget, _args...); + } + else { + assert(false && "Throw bad call exception"); + } + return nullptr; + } + + template template inline int FunctorContainer<_signature...>::addConstructor(const std::string& pCtorType) @@ -78,4 +96,49 @@ namespace rtl { m_functors.push_back(functor); return (m_functors.size() - 1); } + + + template + template + inline int FunctorContainer<_signature...>::addFunctor(_returnType(_recordType::* pFunctor)(_signature...), enable_if_same<_returnType, void> *_) + { + const auto functor = [=](const std::unique_ptr& pTargetObj, _signature...params)->std::unique_ptr + { + auto targetObj = pTargetObj->get<_recordType*>(); + if (targetObj.has_value()) + { + _recordType* target = targetObj.value(); + (target->*pFunctor)(params...); + } + else { + assert(false && "Throw bad call exception"); + } + return nullptr; + }; + m_methodPtrs.push_back(functor); + return (m_methodPtrs.size() - 1); + } + + + template + template + inline int FunctorContainer<_signature...>::addFunctor(_returnType(_recordType::* pFunctor)(_signature...), enable_if_notSame<_returnType, void> *_) + { + const auto functor = [=](const std::unique_ptr& pTargetObj, _signature...params)->std::unique_ptr + { + auto targetObj = pTargetObj->get<_recordType*>(); + if (targetObj.has_value()) + { + _recordType* target = targetObj.value(); + const auto& retObj = (target->*pFunctor)(params...); + return std::unique_ptr(new ReturnObject<_returnType>(TypeList<_returnType>::toString(), retObj)); + } + else { + assert(false && "Throw bad call exception"); + return nullptr; + } + }; + m_methodPtrs.push_back(functor); + return (m_methodPtrs.size() - 1); + } } \ No newline at end of file diff --git a/ReflectionTemplateLib/inc/Method.h b/ReflectionTemplateLib/inc/Method.h new file mode 100644 index 00000000..786e87db --- /dev/null +++ b/ReflectionTemplateLib/inc/Method.h @@ -0,0 +1,35 @@ +#pragma once + +#include "Function.h" +#include "RObject.hpp" + +namespace rtl { + + class Record; + class MethodInvoker; + + class Method + { + const Function& m_function; + + Method(const Function& pFunction); + + public: friend Record; + + const MethodInvoker operator()(const std::unique_ptr& pTarget) const; + }; + + + class MethodInvoker + { + const Function& m_function; + const std::unique_ptr& m_target; + + MethodInvoker(const Function& pFunction, const std::unique_ptr& pTarget); + + public: friend Method; + + template + std::unique_ptr invoke(_args...params) const; + }; +} \ No newline at end of file diff --git a/ReflectionTemplateLib/inc/Method.hpp b/ReflectionTemplateLib/inc/Method.hpp new file mode 100644 index 00000000..63dcac41 --- /dev/null +++ b/ReflectionTemplateLib/inc/Method.hpp @@ -0,0 +1,10 @@ +#include "Method.h" + +namespace rtl { + + template + inline std::unique_ptr MethodInvoker::invoke(_args ...params) const + { + return m_function.execute(m_target, params...); + } +} \ No newline at end of file diff --git a/ReflectionTemplateLib/inc/NameSpace.h b/ReflectionTemplateLib/inc/NameSpace.h index 1128648e..3412b775 100644 --- a/ReflectionTemplateLib/inc/NameSpace.h +++ b/ReflectionTemplateLib/inc/NameSpace.h @@ -5,11 +5,12 @@ #include #include -#include "Record.hpp" -#include "Function.hpp" - namespace rtl { + class Record; + class Function; + class NameSpace; + class NameSpace { using RecordsMap = std::unordered_map; diff --git a/ReflectionTemplateLib/inc/Record.h b/ReflectionTemplateLib/inc/Record.h index 7af55a6b..b6287905 100644 --- a/ReflectionTemplateLib/inc/Record.h +++ b/ReflectionTemplateLib/inc/Record.h @@ -3,10 +3,14 @@ #include #include #include -#include "Function.h" namespace rtl { + class Method; + class RObject; + class Function; + class NameSpace; + class Record { using FunctionMap = std::unordered_map; @@ -21,7 +25,9 @@ namespace rtl { void addConstructor(const Function& pFunction) const; - public: + static void addFunction(const Function& pFunctions, std::unordered_map& pNamespaces); + + public: friend NameSpace; Record() = delete; Record(const Record& pRecord); @@ -30,9 +36,7 @@ namespace rtl { void operator=(const Record& pRecord); void operator=(Record&& pRecord) noexcept; - std::optional getFunction(const std::string& pFunction) const; - - static void addFunction(const Function& pFunctions, std::unordered_map& pNamespaces); + std::optional getMethod(const std::string& pMethod) const; template std::unique_ptr newInstance(_ctorArgs ...params) const; diff --git a/ReflectionTemplateLib/inc/Record.hpp b/ReflectionTemplateLib/inc/Record.hpp index 4fb55823..b3908e26 100644 --- a/ReflectionTemplateLib/inc/Record.hpp +++ b/ReflectionTemplateLib/inc/Record.hpp @@ -2,6 +2,7 @@ #include #include "Record.h" +#include "Function.h" #include "Constants.h" #include "FunctorContainer.hpp" diff --git a/ReflectionTemplateLib/inc/ReflectionTemplateLib.h b/ReflectionTemplateLib/inc/ReflectionTemplateLib.h new file mode 100644 index 00000000..81cfe293 --- /dev/null +++ b/ReflectionTemplateLib/inc/ReflectionTemplateLib.h @@ -0,0 +1,9 @@ +#pragma once + +#include "Record.hpp" //Reflects user defined classes/structs. + +#include "Method.hpp" //Reflects methods(member functions) of classes/structs. + +#include "Function.hpp" //Reflects global functions (may be in a namespace), static member functions of classes/structs. + +#include "CxxMirror.h" //A complete library interface class, provides reflection functionality. \ No newline at end of file diff --git a/ReflectionTemplateLib/src/CMakeLists.txt b/ReflectionTemplateLib/src/CMakeLists.txt index 372878d2..19af3e34 100644 --- a/ReflectionTemplateLib/src/CMakeLists.txt +++ b/ReflectionTemplateLib/src/CMakeLists.txt @@ -5,6 +5,7 @@ set(LOCAL_SOURCES "${CMAKE_CURRENT_LIST_DIR}/Function.cpp" "${CMAKE_CURRENT_LIST_DIR}/FunctionBuilder.cpp" "${CMAKE_CURRENT_LIST_DIR}/FunctorContainer.cpp" + "${CMAKE_CURRENT_LIST_DIR}/Method.cpp" "${CMAKE_CURRENT_LIST_DIR}/NameSpace.cpp" "${CMAKE_CURRENT_LIST_DIR}/Record.cpp" "${CMAKE_CURRENT_LIST_DIR}/RObject.cpp" @@ -21,9 +22,12 @@ SET(LOCAL_HEADERS "${PROJECT_SOURCE_DIR}/inc/FunctorContainer.h" "${PROJECT_SOURCE_DIR}/inc/FunctorContainer.hpp" "${PROJECT_SOURCE_DIR}/inc/FunctionBuilder.h" + "${PROJECT_SOURCE_DIR}/inc/Method.h" + "${PROJECT_SOURCE_DIR}/inc/Method.hpp" "${PROJECT_SOURCE_DIR}/inc/NameSpace.h" "${PROJECT_SOURCE_DIR}/inc/Record.h" "${PROJECT_SOURCE_DIR}/inc/Record.hpp" + "${PROJECT_SOURCE_DIR}/inc/ReflectionTemplateLib.h" "${PROJECT_SOURCE_DIR}/inc/RObject.h" "${PROJECT_SOURCE_DIR}/inc/RObject.hpp" "${PROJECT_SOURCE_DIR}/inc/TypeDescriptorList.h" diff --git a/ReflectionTemplateLib/src/CxxMirror.cpp b/ReflectionTemplateLib/src/CxxMirror.cpp index f0b2668f..b2641d2b 100644 --- a/ReflectionTemplateLib/src/CxxMirror.cpp +++ b/ReflectionTemplateLib/src/CxxMirror.cpp @@ -1,6 +1,8 @@ + +#include "Record.h" +#include "Function.h" #include "CxxMirror.h" #include "Constants.h" -#include "NameSpace.h" #include "FunctorContainer.hpp" namespace rtl { diff --git a/ReflectionTemplateLib/src/Function.cpp b/ReflectionTemplateLib/src/Function.cpp index 8ac1b68a..29cacc34 100644 --- a/ReflectionTemplateLib/src/Function.cpp +++ b/ReflectionTemplateLib/src/Function.cpp @@ -4,13 +4,13 @@ namespace rtl { Function::Function(const std::string& pNamespace, const std::string& pRecord, const std::string& pFunction, - const std::string& pSignature, const std::size_t& pSignatureId, const std::size_t& pFunctorId) + const std::string& pSignature, const std::size_t& pSignatureId, const std::size_t& pFunctorId) : m_functorId(pFunctorId) , m_signatureId(pSignatureId) , m_record(pRecord) , m_function(pFunction) , m_signature(pSignature) - , m_namespace(pNamespace) + , m_namespace(pNamespace) { } } \ No newline at end of file diff --git a/ReflectionTemplateLib/src/FunctionBuilder.cpp b/ReflectionTemplateLib/src/FunctionBuilder.cpp index 335de99e..136134f0 100644 --- a/ReflectionTemplateLib/src/FunctionBuilder.cpp +++ b/ReflectionTemplateLib/src/FunctionBuilder.cpp @@ -1,3 +1,5 @@ + + #include "FunctionBuilder.h" namespace rtl { diff --git a/ReflectionTemplateLib/src/Method.cpp b/ReflectionTemplateLib/src/Method.cpp new file mode 100644 index 00000000..db362536 --- /dev/null +++ b/ReflectionTemplateLib/src/Method.cpp @@ -0,0 +1,21 @@ +#include "Method.h" + + +namespace rtl { + + Method::Method(const Function& pFunction) + :m_function(pFunction) + { + } + + MethodInvoker::MethodInvoker(const Function& pFunction, const std::unique_ptr& pTarget) + : m_function(pFunction) + , m_target(pTarget) + { + } + + const MethodInvoker Method::operator()(const std::unique_ptr& pTarget) const + { + return MethodInvoker(m_function, pTarget); + } +} \ No newline at end of file diff --git a/ReflectionTemplateLib/src/NameSpace.cpp b/ReflectionTemplateLib/src/NameSpace.cpp index e4682a37..bfd30cde 100644 --- a/ReflectionTemplateLib/src/NameSpace.cpp +++ b/ReflectionTemplateLib/src/NameSpace.cpp @@ -1,3 +1,6 @@ + +#include "Record.h" +#include "Function.h" #include "NameSpace.h" namespace rtl { diff --git a/ReflectionTemplateLib/src/Record.cpp b/ReflectionTemplateLib/src/Record.cpp index 253edcc8..05bcd306 100644 --- a/ReflectionTemplateLib/src/Record.cpp +++ b/ReflectionTemplateLib/src/Record.cpp @@ -1,4 +1,7 @@ + #include "Record.h" +#include "RObject.h" +#include "Method.h" #include "Constants.h" namespace rtl { @@ -38,6 +41,16 @@ namespace rtl { } + std::optional Record::getMethod(const std::string& pMethod) const + { + const auto& itr = m_functions->find(pMethod); + if (itr != m_functions->end()) { + return std::optional(Method(itr->second)); + } + return std::nullopt; + } + + void Record::operator=(const Record& pRecord) { if (this == &pRecord) { @@ -61,16 +74,6 @@ namespace rtl { } - std::optional Record::getFunction(const std::string& pFunction) const - { - const auto& itr = m_functions->find(pFunction); - if (itr != m_functions->end()) { - return std::optional(itr->second); - } - return std::nullopt; - } - - void Record::addFunction(const Function& pFunction, std::unordered_map& pRecordMap) { const auto& recordName = pFunction.getRecordName();