From 6a5c0cde6c9a56b699731958abfcfb587dd54e90 Mon Sep 17 00:00:00 2001 From: neeraj31285 Date: Tue, 16 Jul 2024 10:41:55 +0530 Subject: [PATCH 1/2] refactored, type data dump as json. --- CxxTypeRegistration/src/MyReflection.cpp | 87 ++++++-------- ReflectionTemplateLib/access/inc/CxxMirror.h | 4 +- .../access/inc/CxxMirrorToJson.h | 13 +++ ReflectionTemplateLib/access/inc/Function.h | 8 +- ReflectionTemplateLib/access/inc/Method.h | 3 +- ReflectionTemplateLib/access/inc/Record.hpp | 5 +- .../access/src/CMakeLists.txt | 3 + .../access/src/CxxMirrorToJson.cpp | 107 ++++++++++++++++++ ReflectionTemplateLib/access/src/Function.cpp | 9 +- ReflectionTemplateLib/access/src/Method.cpp | 11 +- ReflectionTemplateLib/access/src/Record.cpp | 7 +- ReflectionTemplateLib/builder/CMakeLists.txt | 1 + .../builder/inc/ConstructorBuilder.hpp | 7 +- ReflectionTemplateLib/common/Constants.h | 8 -- ReflectionTemplateLib/common/Constants.hpp | 22 ++++ .../detail/inc/CxxReflection.h | 4 +- .../detail/inc/FunctorContainer.h | 6 + ReflectionTemplateLib/detail/inc/FunctorId.h | 10 +- .../detail/inc/MethodContainer.h | 10 ++ .../detail/inc/ReflectionBuilder.hpp | 18 +-- .../detail/inc/SetupConstructor.hpp | 12 +- .../detail/inc/SetupFunction.hpp | 6 +- .../detail/inc/SetupMethod.hpp | 12 +- ReflectionTemplateLib/detail/inc/TypeId.h | 9 ++ .../detail/src/CxxReflection.cpp | 3 +- 25 files changed, 269 insertions(+), 116 deletions(-) create mode 100644 ReflectionTemplateLib/access/inc/CxxMirrorToJson.h create mode 100644 ReflectionTemplateLib/access/src/CxxMirrorToJson.cpp create mode 100644 ReflectionTemplateLib/common/Constants.hpp diff --git a/CxxTypeRegistration/src/MyReflection.cpp b/CxxTypeRegistration/src/MyReflection.cpp index a28152aa..adcb6d02 100644 --- a/CxxTypeRegistration/src/MyReflection.cpp +++ b/CxxTypeRegistration/src/MyReflection.cpp @@ -1,5 +1,8 @@ +#include + #include "MyReflection.h" +#include "CxxMirrorToJson.h" //User defined types to be reflected. #include "Date.h" @@ -8,9 +11,8 @@ #include "Complex.h" /* -TestUtils provide the interface to test/compare reflected type objects with actual objects (retrived/created using -strict Types) without exposing the actual type objects to "CxxReflectionTests" project. -*/ +TestUtils, provides the interface to test/compare reflected type objects with actual objects (created via strict typing) +without exposing the actual type objects to "CxxReflectionTests" project.*/ #include "TestUtilsBook.h" #include "TestUtilsDate.h" #include "TestUtilsPerson.h" @@ -26,76 +28,61 @@ CxxMirror& MyReflection::instance() { static CxxMirror cxxMirror = CxxMirror({ - //Global function, not contained in any namespace. - //No need to specify "function<>" template types, since its a unique function, no overloads. - Reflect().function(str_getComplexNumAsString).build(getComplexNumAsString), - - //Overloads, Specify the overload signature as template in "function<_signature...>" - //if one of the function takes zero params, must be used, else complie error. - Reflect().function(str_reverseString).build(reverseString), - Reflect().function(str_reverseString).build(reverseString), - Reflect().function(str_reverseString).build(reverseString), + //global functions, not contained in any namespace. + Reflect().function(str_reverseString).build(reverseString), //function taking no arguments. '' must be specified if other overload exists else not needed. compiler error otherwise. + Reflect().function(str_reverseString).build(reverseString), //overloaded function, takes 'string' arguments. '' must be specified as template parameter. + Reflect().function(str_reverseString).build(reverseString), //overloaded function, takes 'const char*' arguments. + Reflect().function(str_getComplexNumAsString).build(getComplexNumAsString), //unique function, no overloads, no need to specify signature as template parameters. - //Global functions, in "complex" namespace. + //Grouping functions under a namespace, which is optional. they can be registered without it as well. Reflect().nameSpace(str_complex).function(str_setReal).build(complex::setReal), Reflect().nameSpace(str_complex).function(str_setImaginary).build(complex::setImaginary), Reflect().nameSpace(str_complex).function(str_getMagnitude).build(complex::getMagnitude), - //Date struct, in nsdate namespace. Ctors, Date() - Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), - Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), - Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), + //Constructors registration, class/struct name and type must be passed 'record("NAME")'. + Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), //default constructor. Destructor gets registered automatically if any constructor is registered. + Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), //overloaded constructor, taking 'string' as argument, must be specified as template param. + Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), //again, the overloaded constructor. + Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), //Copy constructor, taking non-const ref as argument. - //Copy Ctor with non-const ref, Date() - Reflect().nameSpace(date::ns).record(date::struct_).constructor().build(), - - //Calender, in nsdate namespace. Ctor only. + //class Calender, default constructor. Instances will always be created on heap and managed using shared_ptr. Reflect().nameSpace(calender::ns).record(calender::struct_).constructor().build(), + Reflect().record(library::class_).methodStatic(library::str_addBook).build(&Library::addBook), //Static method registration, 'methodStatic()' function must be used. compiler error otherwise. - //class 'Book', no namespace. constructor overloads. + //class 'Book', methods & constructors. Reflect().record(book::class_).constructor().build(), + Reflect().record(book::class_).constructor().build(), //copy constructor, taking const-ref. Reflect().record(book::class_).constructor().build(), - //copy constructor with const ref - Reflect().record(book::class_).constructor().build(), - - //Library class, no constructors. - Reflect().record(library::class_).methodStatic(library::str_addBook).build(&Library::addBook), - - //unique methods. - Reflect().record(book::class_).method(book::str_setAuthor).build(&Book::setAuthor), + Reflect().record(book::class_).method(book::str_setAuthor).build(&Book::setAuthor), //unique methods, no overloads. Reflect().record(book::class_).method(book::str_setDescription).build(&Book::setDescription), Reflect().record(book::class_).method(book::str_getPublishedOn).build(&Book::getPublishedOn), - - //method overloads. - Reflect().record(book::class_).method(book::str_updateBookInfo).build(&Book::updateBookInfo), - Reflect().record(book::class_).method(book::str_updateBookInfo).build(&Book::updateBookInfo), + Reflect().record(book::class_).method(book::str_updateBookInfo).build(&Book::updateBookInfo), //method overloading, '' must be specified since other overloads exists. + Reflect().record(book::class_).method(book::str_updateBookInfo).build(&Book::updateBookInfo), Reflect().record(book::class_).method(book::str_updateBookInfo).build(&Book::updateBookInfo), - //Class 'Person', constructor. + //class 'Person', methods & constructors. Reflect().record(person::class_).constructor().build(), Reflect().record(person::class_).constructor().build(), - - //Copy constructor overload based on const argument - Reflect().record(person::class_).constructor().build(), - Reflect().record(person::class_).constructor().build(), - - //const method. must use 'methodConst()'. Unique method, so no need to specify signature as template params. - Reflect().record(person::class_).methodConst(person::str_updateLastName).build(&Person::updateLastName), - - //const based method overloads. same signatures, but one is const, registered via 'methodConst()'. + Reflect().record(person::class_).constructor().build(), //copy constructor taking non-const ref argument. + Reflect().record(person::class_).constructor().build(), //copy constructor taking const ref argument. Reflect().record(person::class_).method(person::str_updateAddress).build(&Person::updateAddress), - Reflect().record(person::class_).methodConst(person::str_updateAddress).build(&Person::updateAddress), Reflect().record(person::class_).method(person::str_updateAddress).build(&Person::updateAddress), - Reflect().record(person::class_).methodConst(person::str_updateAddress).build(&Person::updateAddress), - - //Static method. unique. + Reflect().record(person::class_).methodConst(person::str_updateLastName).build(&Person::updateLastName), //const method registration, 'methodConst()' function must be used. compiler error otherwise. + Reflect().record(person::class_).methodConst(person::str_updateAddress).build(&Person::updateAddress), + Reflect().record(person::class_).methodConst(person::str_updateAddress).build(&Person::updateAddress), //overloaded method based on 'const'. Reflect().record(person::class_).methodStatic(person::str_getDefaults).build(&Person::getDefaults), - - //Static method overloads. Reflect().record(person::class_).methodStatic(person::str_getProfile).build(&Person::getProfile), Reflect().record(person::class_).methodStatic(person::str_getProfile).build(&Person::getProfile), Reflect().record(person::class_).methodStatic(person::str_getProfile).build(&Person::getProfile) }); + + static bool dumped = false; + if (!dumped) { + const std::string pathStr = std::filesystem::current_path().string() + "/MyReflection.json"; + rtl::CxxMirrorToJson::dump(cxxMirror, pathStr); + dumped = true; + } + return cxxMirror; } \ No newline at end of file diff --git a/ReflectionTemplateLib/access/inc/CxxMirror.h b/ReflectionTemplateLib/access/inc/CxxMirror.h index 7598e7e6..ca510167 100644 --- a/ReflectionTemplateLib/access/inc/CxxMirror.h +++ b/ReflectionTemplateLib/access/inc/CxxMirror.h @@ -13,14 +13,12 @@ namespace rtl { class Record; class Function; - class CxxMirror : detail::CxxReflection + class CxxMirror : public detail::CxxReflection { public: CxxMirror(const std::vector& pFunctions); - void dumpReflectionJson(const std::string& pFilePath); - std::optional getRecord(const std::string& pFunction); std::optional getFunction(const std::string& pFunction); diff --git a/ReflectionTemplateLib/access/inc/CxxMirrorToJson.h b/ReflectionTemplateLib/access/inc/CxxMirrorToJson.h new file mode 100644 index 00000000..40ab5fbf --- /dev/null +++ b/ReflectionTemplateLib/access/inc/CxxMirrorToJson.h @@ -0,0 +1,13 @@ +#pragma once + +namespace rtl { + + namespace access { + class CxxMirror; + } + + struct CxxMirrorToJson + { + static void dump(access::CxxMirror& pCxxMirror, const std::string& pFilePathStr); + }; +} \ No newline at end of file diff --git a/ReflectionTemplateLib/access/inc/Function.h b/ReflectionTemplateLib/access/inc/Function.h index 623b5b28..f29e0fdc 100644 --- a/ReflectionTemplateLib/access/inc/Function.h +++ b/ReflectionTemplateLib/access/inc/Function.h @@ -26,13 +26,11 @@ namespace rtl { const std::string m_function; const std::string m_namespace; - mutable std::string m_signatures; mutable std::vector m_functorIds; Function(); Function(const std::string& pNamespace, const std::string& pClassName, const std::string& pFuncName, - const std::string& pSignature, const detail::FunctorId& pFunctorId, - std::size_t pRecordTypeId, const TypeQ pQualifier); + const detail::FunctorId& pFunctorId, std::size_t pRecordTypeId, const TypeQ pQualifier); void addOverload(const Function& pOtherFunc) const; @@ -41,7 +39,7 @@ namespace rtl { protected: Function(const Function& pOther, const detail::FunctorId& pFunctorId, - const std::string& pFunctorName, const std::string& pSignatureStr); + const std::string& pFunctorName); const std::size_t hasSignatureId(const std::size_t& pSignatureId) const; @@ -51,8 +49,8 @@ namespace rtl { GETTER(std::string, RecordName, m_record) GETTER(std::string, Namespace, m_namespace) GETTER(std::string, FunctionName, m_function) - GETTER(std::string, Signatures, m_signatures) GETTER(std::size_t, RecordTypeId, m_recordTypeId) + GETTER(std::vector, Functors, m_functorIds) const std::string getHashCode() const; diff --git a/ReflectionTemplateLib/access/inc/Method.h b/ReflectionTemplateLib/access/inc/Method.h index e74c8b06..676e83fc 100644 --- a/ReflectionTemplateLib/access/inc/Method.h +++ b/ReflectionTemplateLib/access/inc/Method.h @@ -49,8 +49,7 @@ namespace rtl { { Method(const Function& pFunction); - Method(const Function& pFunction, const detail::FunctorId& pFunctorId, - const std::string& pFunctorName, const std::string& pSignatureStr); + Method(const Function& pFunction, const detail::FunctorId& pFunctorId, const std::string& pFunctorName); template RStatus invokeCtor(_args...params) const; diff --git a/ReflectionTemplateLib/access/inc/Record.hpp b/ReflectionTemplateLib/access/inc/Record.hpp index dcc38989..3918a846 100644 --- a/ReflectionTemplateLib/access/inc/Record.hpp +++ b/ReflectionTemplateLib/access/inc/Record.hpp @@ -3,6 +3,7 @@ #include "RStatus.h" #include "Method.h" #include "Constants.h" +#include "Constants.hpp" #include "Instance.h" namespace rtl { @@ -12,12 +13,12 @@ namespace rtl { template inline const std::pair Record::instance(_ctorArgs ...params) const { - const std::string& ctor = (m_recordName + Ctor::CTOR); + const std::string& ctor = getCtorName(m_recordName); const auto& itr = m_methods.find(ctor); if (itr != m_methods.end()) { const RStatus& status = itr->second.invokeCtor(params...); if (status) { - const std::string& dctor = (m_recordName + Ctor::DCTOR); + const std::string& dctor = getDctorName(m_recordName); return std::make_pair(status, Instance(status.getReturn(), status, *getMethod(dctor))); } return std::make_pair(status, Instance()); diff --git a/ReflectionTemplateLib/access/src/CMakeLists.txt b/ReflectionTemplateLib/access/src/CMakeLists.txt index 96cae309..85be8dd9 100644 --- a/ReflectionTemplateLib/access/src/CMakeLists.txt +++ b/ReflectionTemplateLib/access/src/CMakeLists.txt @@ -1,6 +1,7 @@ # Create a variable containing the source files for your target set(LOCAL_SOURCES "${CMAKE_CURRENT_LIST_DIR}/CxxMirror.cpp" + "${CMAKE_CURRENT_LIST_DIR}/CxxMirrorToJson.cpp" "${CMAKE_CURRENT_LIST_DIR}/Function.cpp" "${CMAKE_CURRENT_LIST_DIR}/Instance.cpp" "${CMAKE_CURRENT_LIST_DIR}/Method.cpp" @@ -10,11 +11,13 @@ set(LOCAL_SOURCES SET(COMMON_HEADERS "${PROJECT_SOURCE_DIR}/common/Constants.h" + "${PROJECT_SOURCE_DIR}/common/Constants.hpp" "${PROJECT_SOURCE_DIR}/common/RTLibInterface.h" ) SET(LOCAL_HEADERS "${PROJECT_SOURCE_DIR}/access/inc/CxxMirror.h" + "${PROJECT_SOURCE_DIR}/access/inc/CxxMirrorToJson.h" "${PROJECT_SOURCE_DIR}/access/inc/Function.h" "${PROJECT_SOURCE_DIR}/access/inc/Function.hpp" "${PROJECT_SOURCE_DIR}/access/inc/Instance.h" diff --git a/ReflectionTemplateLib/access/src/CxxMirrorToJson.cpp b/ReflectionTemplateLib/access/src/CxxMirrorToJson.cpp new file mode 100644 index 00000000..cbe2cf73 --- /dev/null +++ b/ReflectionTemplateLib/access/src/CxxMirrorToJson.cpp @@ -0,0 +1,107 @@ + +#include +#include + +#include "Method.h" +#include "Record.h" +#include "Function.h" +#include "CxxMirror.h" +#include "CxxMirrorToJson.h" + +using namespace rtl::access; +using namespace rtl::detail; + +namespace +{ + const std::string toJson(const FunctorId& pFunctorId) + { + std::stringstream sout; + sout << "{\"hash_code\": \"" << std::to_string(pFunctorId.getHashCode()) << "\","; + sout << "\"signature\": \"" << pFunctorId.getSignatureStr() << "\"}"; + return sout.str(); + } + + const std::string toJson(const Function& pFunction) + { + std::stringstream sout; + const auto& functors = pFunction.getFunctors(); + const std::string& record = pFunction.getRecordName(); + const std::string& nmspace = pFunction.getNamespace(); + + sout << "{" << (record.empty() ? "\"function\"" : "\"method\"") << ": \"" << pFunction.getFunctionName() << "\","; + if (nmspace != rtl::NAMESPACE_GLOBAL) { + sout << "\"namespace\": \"" << nmspace << "\","; + } + if (!record.empty()) { + sout << "\"record\": \"" << record << "\","; + } + + int index = 0; + sout << "\"functorId\": ["; + for (const auto& funtorId : functors) { + sout << toJson(funtorId); + if (++index < functors.size()) { + sout << ", "; + } + } + sout << "]}"; + return sout.str(); + } + + + const std::string toJson(CxxMirror& pCxxMirror) + { + std::stringstream sout; + sout << "["; + bool atLeastOne = false; + const auto& nsfuncMap = pCxxMirror.getNamespaceFunctionsMap(); + for (const auto& itr : nsfuncMap) + { + for (const auto& itr0 : itr.second) + { + const std::string& functionStr = toJson(itr0.second); + sout << functionStr << ","; + atLeastOne = true; + } + } + + const auto& recfuncMap = pCxxMirror.getNamespaceRecordMap(); + for (const auto& itr : recfuncMap) + { + for (const auto& itr0 : itr.second) + { + for (const auto& itr1 : itr0.second.getMethodMap()) + { + const std::string& methodStr = toJson(itr1.second); + sout << methodStr << ","; + atLeastOne = true; + } + } + } + + std::string str = sout.str(); + if (str.back() == ',') str.pop_back(); + str.push_back(']'); + return str; + } +} + + +namespace rtl +{ + void CxxMirrorToJson::dump(CxxMirror& pCxxMirror, const std::string& pFilePathStr) + { + std::string fileStr = pFilePathStr; + std::replace(fileStr.begin(), fileStr.end(), '\\', '/'); + std::fstream fout(fileStr, std::ios::out); + if (!fout.is_open()) { + return; + } + fout << toJson(pCxxMirror); + fout.flush(); + fout.close(); + if (fout.fail() || fout.bad()) { + return; + } + } +} \ No newline at end of file diff --git a/ReflectionTemplateLib/access/src/Function.cpp b/ReflectionTemplateLib/access/src/Function.cpp index 46d8b748..fae21ad8 100644 --- a/ReflectionTemplateLib/access/src/Function.cpp +++ b/ReflectionTemplateLib/access/src/Function.cpp @@ -13,33 +13,29 @@ namespace rtl { , m_recordTypeId(detail::TypeId<>::None) , m_record("") , m_function("") - , m_signatures("") , m_namespace("") { } Function::Function(const std::string& pNamespace, const std::string& pRecord, const std::string& pFunction, - const std::string& pSignature, const detail::FunctorId& pFunctorId, - std::size_t pRecordTypeId, const TypeQ pQualifier) + const detail::FunctorId& pFunctorId, std::size_t pRecordTypeId, const TypeQ pQualifier) : m_qualifier(pQualifier) , m_recordTypeId(pRecordTypeId) , m_functorIds({ pFunctorId }) , m_record(pRecord) , m_function(pFunction) - , m_signatures(pSignature) , m_namespace(pNamespace) { } Function::Function(const Function& pOther, const detail::FunctorId& pFunctorId, - const std::string& pFunctorName, const std::string& pSignatureStr) + const std::string& pFunctorName) : m_qualifier(pOther.m_qualifier) , m_recordTypeId(pOther.m_recordTypeId) , m_functorIds({ pFunctorId }) , m_record(pOther.m_record) , m_function(pFunctorName) - , m_signatures(pSignatureStr) , m_namespace(pOther.m_namespace) { } @@ -80,7 +76,6 @@ namespace rtl { } m_functorIds.push_back(pOtherFunc.m_functorIds[0]); - m_signatures.append("\n" + pOtherFunc.m_signatures); } } } \ No newline at end of file diff --git a/ReflectionTemplateLib/access/src/Method.cpp b/ReflectionTemplateLib/access/src/Method.cpp index c958c5fc..77070b2d 100644 --- a/ReflectionTemplateLib/access/src/Method.cpp +++ b/ReflectionTemplateLib/access/src/Method.cpp @@ -1,5 +1,6 @@ #include "Method.h" +#include "Constants.hpp" namespace rtl { @@ -10,17 +11,15 @@ namespace rtl { } - Method::Method(const Function& pFunction, const detail::FunctorId& pFunctorId, - const std::string& pFunctorName, const std::string& pSignatureStr) - : Function(pFunction, pFunctorId, pFunctorName, pSignatureStr) { + Method::Method(const Function& pFunction, const detail::FunctorId& pFunctorId, const std::string& pFunctorName) + : Function(pFunction, pFunctorId, pFunctorName) { } Method Method::getDestructorMethod(const Function& pFunction, const detail::FunctorId& pFunctorId) { - const std::string dctorStr = pFunction.getRecordName() + Ctor::DCTOR; - const std::string signatureStr = pFunction.getRecordName() + "::~()"; - return Method(pFunction, pFunctorId, dctorStr, signatureStr); + const std::string dctorStr = getDctorName(pFunction.getRecordName()); + return Method(pFunction, pFunctorId, dctorStr); } } } \ No newline at end of file diff --git a/ReflectionTemplateLib/access/src/Record.cpp b/ReflectionTemplateLib/access/src/Record.cpp index 886cc538..2626fb36 100644 --- a/ReflectionTemplateLib/access/src/Record.cpp +++ b/ReflectionTemplateLib/access/src/Record.cpp @@ -4,6 +4,7 @@ #include "RStatus.h" #include "Instance.h" #include "Constants.h" +#include "Constants.hpp" #include "Function.hpp" namespace rtl { @@ -44,9 +45,9 @@ namespace rtl { return std::make_pair(RStatus(Error::EmptyInstance), Instance()); } - const std::string& dctor = (m_recordName + Ctor::DCTOR); - const std::string& copyStr = (m_recordName + Ctor::CTOR_COPY); - const std::string& constCopyStr = (m_recordName + Ctor::CTOR_CONST_COPY); + const std::string& dctor = getDctorName(m_recordName); + const std::string& copyStr = getCopyCtorName(m_recordName); + const std::string& constCopyStr = getConstCopyCtorName(m_recordName); std::optional destructor = getMethod(dctor); std::optional constCopyCtor = getMethod(constCopyStr); diff --git a/ReflectionTemplateLib/builder/CMakeLists.txt b/ReflectionTemplateLib/builder/CMakeLists.txt index 7956d660..b95cdb63 100644 --- a/ReflectionTemplateLib/builder/CMakeLists.txt +++ b/ReflectionTemplateLib/builder/CMakeLists.txt @@ -2,6 +2,7 @@ SET(COMMON_HEADERS "${PROJECT_SOURCE_DIR}/common/Constants.h" + "${PROJECT_SOURCE_DIR}/common/Constants.hpp" ) SET(LOCAL_HEADERS diff --git a/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp b/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp index dabcd08a..01d2cc36 100644 --- a/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp +++ b/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp @@ -2,6 +2,7 @@ #include "Function.h" #include "Builder.hpp" +#include "Constants.hpp" #include "ConstructorBuilder.h" namespace rtl { @@ -25,15 +26,15 @@ namespace rtl { { default: case FunctorType::Ctor: { - const auto& ctorName = (m_record + Ctor::CTOR); + const auto& ctorName = getCtorName(m_record); return Builder(m_namespace, m_record, ctorName).build<_recordType, _ctorSignature...>(); } case FunctorType::CopyCtor: { - const auto& ctorName = (m_record + Ctor::CTOR_COPY); + const auto& ctorName = getCopyCtorName(m_record); return Builder(m_namespace, m_record, ctorName).build<_recordType, _ctorSignature...>(); } case FunctorType::CopyCtorConst: { - const auto& ctorName = (m_record + Ctor::CTOR_CONST_COPY); + const auto& ctorName = getConstCopyCtorName(m_record); return Builder(m_namespace, m_record, ctorName).build<_recordType, _ctorSignature...>(); } } diff --git a/ReflectionTemplateLib/common/Constants.h b/ReflectionTemplateLib/common/Constants.h index f9eaaecd..0d7fc9c8 100644 --- a/ReflectionTemplateLib/common/Constants.h +++ b/ReflectionTemplateLib/common/Constants.h @@ -38,14 +38,6 @@ namespace rtl { ConstCopyConstructorNotFound }; - - struct Ctor { - static constexpr const char* CTOR = "::ctor()"; - static constexpr const char* DCTOR = "::~dctor()"; - static constexpr const char* CTOR_COPY = "::ctor(&)"; - static constexpr const char* CTOR_CONST_COPY = "::ctor(const&)"; - }; - constexpr const char* NAMESPACE_GLOBAL = "namespace_global"; #define GETTER(_varType, _name, _var) \ diff --git a/ReflectionTemplateLib/common/Constants.hpp b/ReflectionTemplateLib/common/Constants.hpp new file mode 100644 index 00000000..59e80b9c --- /dev/null +++ b/ReflectionTemplateLib/common/Constants.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace rtl +{ + static constexpr const std::string getCtorName(const std::string& pRecordName) { + return (pRecordName + "::~" + pRecordName + "()"); + } + + static constexpr const std::string getDctorName(const std::string& pRecordName) { + return (pRecordName + "::" + pRecordName + "()"); + } + + static constexpr const std::string getCopyCtorName(const std::string& pRecordName) { + return (pRecordName + "::" + pRecordName + "(" + pRecordName + "&)"); + } + + static constexpr const std::string getConstCopyCtorName(const std::string& pRecordName) { + return (pRecordName + "::" + pRecordName + "(const " + pRecordName + "&)"); + } +} \ No newline at end of file diff --git a/ReflectionTemplateLib/detail/inc/CxxReflection.h b/ReflectionTemplateLib/detail/inc/CxxReflection.h index 1ee6ca27..0de40d63 100644 --- a/ReflectionTemplateLib/detail/inc/CxxReflection.h +++ b/ReflectionTemplateLib/detail/inc/CxxReflection.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -12,6 +11,7 @@ namespace rtl { namespace access { class Record; + class Method; class Function; } @@ -40,6 +40,8 @@ namespace rtl { CxxReflection(const std::vector& pFunctions); + public: + constexpr const std::unordered_map& getNamespaceRecordMap() { return m_nsRecordsMap; } diff --git a/ReflectionTemplateLib/detail/inc/FunctorContainer.h b/ReflectionTemplateLib/detail/inc/FunctorContainer.h index 0c1370b3..745c0201 100644 --- a/ReflectionTemplateLib/detail/inc/FunctorContainer.h +++ b/ReflectionTemplateLib/detail/inc/FunctorContainer.h @@ -33,6 +33,12 @@ namespace rtl { return m_functors; } + template + static const std::string getSignatureStr(const bool pIsMember = false) { + const std::string& retStr = TypeId<_returnType>::toString(); + return (retStr + (pIsMember ? "::" : " ") + "(" + TypeId<_signature...>::toString() + ")"); + } + private: static const std::size_t m_containerId; diff --git a/ReflectionTemplateLib/detail/inc/FunctorId.h b/ReflectionTemplateLib/detail/inc/FunctorId.h index 49c61f31..2e2af572 100644 --- a/ReflectionTemplateLib/detail/inc/FunctorId.h +++ b/ReflectionTemplateLib/detail/inc/FunctorId.h @@ -13,6 +13,7 @@ namespace rtl const std::size_t m_returnId; const std::size_t m_recordId; const std::size_t m_containerId; + const std::string m_signature; public: @@ -20,19 +21,22 @@ namespace rtl : m_index(-1) , m_returnId(TypeId<>::None) , m_recordId(TypeId<>::None) - , m_containerId(TypeId<>::None) { + , m_containerId(TypeId<>::None) + , m_signature("") { } FunctorId(const std::size_t& pIndex, const std::size_t& pReturnId, - const std::size_t& pRecordId, const std::size_t& pContainerId) + const std::size_t& pRecordId, const std::size_t& pContainerId, const std::string& pSignature) : m_index(pIndex) , m_returnId(pReturnId) , m_recordId(pRecordId) - , m_containerId(pContainerId) { + , m_containerId(pContainerId) + , m_signature(pSignature) { } GETTER(std::size_t, Index, m_index) GETTER(std::size_t, SignatureId, m_containerId) + GETTER(std::string, SignatureStr, m_signature) std::size_t getHashCode() const; }; diff --git a/ReflectionTemplateLib/detail/inc/MethodContainer.h b/ReflectionTemplateLib/detail/inc/MethodContainer.h index 6efc980b..9b2e8df2 100644 --- a/ReflectionTemplateLib/detail/inc/MethodContainer.h +++ b/ReflectionTemplateLib/detail/inc/MethodContainer.h @@ -36,6 +36,11 @@ namespace rtl { return m_methodPtrs; } + template + static const std::string getSignatureStr() { + return (TypeId<_returnType>::toString() + " " + TypeId<_recordType>::toString() + "::(" + TypeId<_signature...>::toString() + ")"); + } + private: static const std::size_t m_containerId; @@ -88,6 +93,11 @@ namespace rtl { return m_methodPtrs; } + template + static const std::string getSignatureStr() { + return (TypeId<_returnType>::toString() + " " + TypeId<_recordType>::toString() + "::(" + TypeId<_signature...>::toString() + ") const"); + } + private: static const std::size_t m_containerId; diff --git a/ReflectionTemplateLib/detail/inc/ReflectionBuilder.hpp b/ReflectionTemplateLib/detail/inc/ReflectionBuilder.hpp index dedd2274..e3a675f3 100644 --- a/ReflectionTemplateLib/detail/inc/ReflectionBuilder.hpp +++ b/ReflectionTemplateLib/detail/inc/ReflectionBuilder.hpp @@ -20,9 +20,8 @@ namespace rtl { inline const access::Function ReflectionBuilder::buildFunctor(_returnType(*pFunctor)(_signature...)) const { const std::string& typeStr = detail::TypeId<_signature...>::toString(); - const std::string& signature = "(" + (typeStr.empty() ? "void" : typeStr) + ")"; const detail::FunctorId functorId = detail::FunctorContainer<_signature...>::addFunctor(pFunctor); - return access::Function(m_namespace, m_record, m_function, signature, functorId, TypeId<>::None, TypeQ::None); + return access::Function(m_namespace, m_record, m_function, functorId, TypeId<>::None, TypeQ::None); } @@ -30,9 +29,8 @@ namespace rtl { inline const access::Function ReflectionBuilder::buildMethodFunctor(_returnType(_recordType::* pFunctor)(_signature...)) const { const std::string& typeStr = detail::TypeId<_signature...>::toString(); - const std::string& signature = "(" + (typeStr.empty() ? "void" : typeStr) + ")"; const detail::FunctorId functorId = detail::MethodContainer::addFunctor(pFunctor); - return access::Function(m_namespace, m_record, m_function, signature, functorId, TypeId<_recordType>::get(), TypeQ::Mute); + return access::Function(m_namespace, m_record, m_function, functorId, TypeId<_recordType>::get(), TypeQ::Mute); } @@ -40,9 +38,8 @@ namespace rtl { inline const access::Function ReflectionBuilder::buildMethodFunctor(_returnType(_recordType::* pFunctor)(_signature...) const) const { const std::string& typeStr = detail::TypeId<_signature...>::toString(); - const std::string& signature = "(" + (typeStr.empty() ? "void" : typeStr) + ")"; const detail::FunctorId functorId = detail::MethodContainer::addFunctor(pFunctor); - return access::Function(m_namespace, m_record, m_function, signature, functorId, TypeId<_recordType>::get(), TypeQ::Const); + return access::Function(m_namespace, m_record, m_function, functorId, TypeId<_recordType>::get(), TypeQ::Const); } @@ -51,8 +48,7 @@ namespace rtl { { const detail::FunctorId functorId = detail::FunctorContainer<_ctorSignature...>::template addConstructor<_recordType, _ctorSignature...>(); const std::string& typeStr = detail::TypeId<_ctorSignature...>::toString(); - const std::string& signature = "(" + (typeStr.empty() ? "void" : typeStr) + ")"; - const access::Function constructor = access::Function(m_namespace, m_record, m_function, signature, functorId, TypeId<_recordType>::get(), TypeQ::None); + const access::Function constructor = access::Function(m_namespace, m_record, m_function, functorId, TypeId<_recordType>::get(), TypeQ::None); constructor.getFunctorIds().emplace_back(detail::FunctorContainer::addDestructor<_recordType>()); return constructor; } @@ -63,8 +59,7 @@ namespace rtl { { const detail::FunctorId functorId = detail::FunctorContainer::addCopyConstructor<_recordType>(); const std::string& typeStr = detail::TypeId<_ctorSignature...>::toString(); - const std::string& signature = "(" + (typeStr.empty() ? "void" : typeStr) + ")"; - const access::Function constructor = access::Function(m_namespace, m_record, m_function, signature, functorId, TypeId<_recordType>::get(), TypeQ::None); + const access::Function constructor = access::Function(m_namespace, m_record, m_function, functorId, TypeId<_recordType>::get(), TypeQ::None); constructor.getFunctorIds().emplace_back(detail::FunctorContainer::addDestructor<_recordType>()); return constructor; } @@ -75,8 +70,7 @@ namespace rtl { { const detail::FunctorId functorId = detail::FunctorContainer::addConstCopyConstructor<_recordType>(); const std::string& typeStr = detail::TypeId<_ctorSignature...>::toString(); - const std::string& signature = "(" + (typeStr.empty() ? "void" : typeStr) + ")"; - const access::Function constructor = access::Function(m_namespace, m_record, m_function, signature, functorId, TypeId<_recordType>::get(), TypeQ::None); + const access::Function constructor = access::Function(m_namespace, m_record, m_function, functorId, TypeId<_recordType>::get(), TypeQ::None); constructor.getFunctorIds().emplace_back(detail::FunctorContainer::addDestructor<_recordType>()); return constructor; } diff --git a/ReflectionTemplateLib/detail/inc/SetupConstructor.hpp b/ReflectionTemplateLib/detail/inc/SetupConstructor.hpp index ea1b69c5..459baac9 100644 --- a/ReflectionTemplateLib/detail/inc/SetupConstructor.hpp +++ b/ReflectionTemplateLib/detail/inc/SetupConstructor.hpp @@ -28,7 +28,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<>::None, TypeId<_recordType>::get(), _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<>::None, TypeId<_recordType>::get(), _derivedType::getContainerId(), + (std::string("~") + _derivedType::template getSignatureStr<_recordType>(true))); } @@ -56,7 +57,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_recordType>::get(), recordId, containerId); + return detail::FunctorId(index, TypeId<_recordType>::get(), recordId, containerId, + _derivedType::template getSignatureStr<_recordType>(true)); } @@ -81,7 +83,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_recordType>::get(), recordId, _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<_recordType>::get(), recordId, _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_recordType>(true)); } @@ -106,7 +109,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_recordType>::get(), recordId, _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<_recordType>::get(), recordId, _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_recordType>(true)); } } } \ No newline at end of file diff --git a/ReflectionTemplateLib/detail/inc/SetupFunction.hpp b/ReflectionTemplateLib/detail/inc/SetupFunction.hpp index 97b84266..28676cc5 100644 --- a/ReflectionTemplateLib/detail/inc/SetupFunction.hpp +++ b/ReflectionTemplateLib/detail/inc/SetupFunction.hpp @@ -31,7 +31,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_returnType>::get(), TypeId<>::None, _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<_returnType>::get(), TypeId<>::None, _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_returnType>()); } @@ -62,7 +63,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_returnType>::get(), TypeId<>::None, _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<_returnType>::get(), TypeId<>::None, _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_returnType>()); } } } \ No newline at end of file diff --git a/ReflectionTemplateLib/detail/inc/SetupMethod.hpp b/ReflectionTemplateLib/detail/inc/SetupMethod.hpp index aa6de622..49a2b093 100644 --- a/ReflectionTemplateLib/detail/inc/SetupMethod.hpp +++ b/ReflectionTemplateLib/detail/inc/SetupMethod.hpp @@ -34,7 +34,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_retType>::get(), TypeId<_recordType>::get(), _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<_retType>::get(), TypeId<_recordType>::get(), _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_recordType, _retType>()); } @@ -66,7 +67,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, retTypeId, TypeId<_recordType>::get(), _derivedType::getContainerId()); + return detail::FunctorId(index, retTypeId, TypeId<_recordType>::get(), _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_recordType, _retType>()); } @@ -96,7 +98,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, TypeId<_retType>::get(), TypeId<_recordType>::get(), _derivedType::getContainerId()); + return detail::FunctorId(index, TypeId<_retType>::get(), TypeId<_recordType>::get(), _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_recordType, _retType>()); } @@ -129,7 +132,8 @@ namespace rtl }; const std::size_t& index = _derivedType::pushBack(functor, getIndex, updateIndex); - return detail::FunctorId(index, retTypeId, TypeId<_recordType>::get(), _derivedType::getContainerId()); + return detail::FunctorId(index, retTypeId, TypeId<_recordType>::get(), _derivedType::getContainerId(), + _derivedType::template getSignatureStr<_recordType, _retType>()); } } } \ No newline at end of file diff --git a/ReflectionTemplateLib/detail/inc/TypeId.h b/ReflectionTemplateLib/detail/inc/TypeId.h index 0a351e14..b8092c03 100644 --- a/ReflectionTemplateLib/detail/inc/TypeId.h +++ b/ReflectionTemplateLib/detail/inc/TypeId.h @@ -23,6 +23,12 @@ namespace rtl { static const std::string toString() { + if (std::is_same<_type, void>::value) { + return std::string("void"); + } + if (std::is_same<_type, std::string>::value) { + return std::string("std::string"); + } if (!std::is_same<_type, std::nullptr_t>::value) { return std::string(typeid(_type).name()); } @@ -43,6 +49,9 @@ namespace rtl { static const std::string toString() { const std::string& tailStr = TAIL::toString(); + if (std::is_same::value) { + return std::string("std::string") + ", " + tailStr; + } return (std::string(typeid(HEAD).name()) + ", " + tailStr); } }; diff --git a/ReflectionTemplateLib/detail/src/CxxReflection.cpp b/ReflectionTemplateLib/detail/src/CxxReflection.cpp index 31504de4..f9760c55 100644 --- a/ReflectionTemplateLib/detail/src/CxxReflection.cpp +++ b/ReflectionTemplateLib/detail/src/CxxReflection.cpp @@ -2,6 +2,7 @@ #include "TypeId.h" #include "Record.h" #include "Method.h" +#include "Constants.hpp" #include "CxxReflection.h" namespace rtl { @@ -53,7 +54,7 @@ namespace rtl { auto& functorIds = pFunction.getFunctorIds(); if (functorIds.size() > 1) { - const auto& dctorName = pFunction.getRecordName() + Ctor::DCTOR; + const auto& dctorName = getDctorName(pFunction.getRecordName()); if (pMethodMap.find(dctorName) == pMethodMap.end()) { access::Method method = access::Method::getDestructorMethod(pFunction, functorIds[1]); pMethodMap.insert(std::make_pair(method.getFunctionName(), method)); From 8e531abc9a964c5ee9e0c1f7106f6da9ed638634 Mon Sep 17 00:00:00 2001 From: neeraj31285 Date: Tue, 16 Jul 2024 11:37:54 +0530 Subject: [PATCH 2/2] refactored --- ReflectionTemplateLib/access/inc/Record.hpp | 5 ++--- .../access/src/CMakeLists.txt | 1 - ReflectionTemplateLib/access/src/Method.cpp | 3 +-- ReflectionTemplateLib/access/src/Record.cpp | 7 +++--- ReflectionTemplateLib/builder/CMakeLists.txt | 1 - .../builder/inc/ConstructorBuilder.hpp | 7 +++--- ReflectionTemplateLib/common/Constants.h | 20 +++++++++++++++++ ReflectionTemplateLib/common/Constants.hpp | 22 ------------------- .../detail/src/CxxReflection.cpp | 3 +-- 9 files changed, 30 insertions(+), 39 deletions(-) delete mode 100644 ReflectionTemplateLib/common/Constants.hpp diff --git a/ReflectionTemplateLib/access/inc/Record.hpp b/ReflectionTemplateLib/access/inc/Record.hpp index 3918a846..60a20e74 100644 --- a/ReflectionTemplateLib/access/inc/Record.hpp +++ b/ReflectionTemplateLib/access/inc/Record.hpp @@ -3,7 +3,6 @@ #include "RStatus.h" #include "Method.h" #include "Constants.h" -#include "Constants.hpp" #include "Instance.h" namespace rtl { @@ -13,12 +12,12 @@ namespace rtl { template inline const std::pair Record::instance(_ctorArgs ...params) const { - const std::string& ctor = getCtorName(m_recordName); + const std::string& ctor = CtorName::ctor(m_recordName); const auto& itr = m_methods.find(ctor); if (itr != m_methods.end()) { const RStatus& status = itr->second.invokeCtor(params...); if (status) { - const std::string& dctor = getDctorName(m_recordName); + const std::string& dctor = CtorName::dctor(m_recordName); return std::make_pair(status, Instance(status.getReturn(), status, *getMethod(dctor))); } return std::make_pair(status, Instance()); diff --git a/ReflectionTemplateLib/access/src/CMakeLists.txt b/ReflectionTemplateLib/access/src/CMakeLists.txt index 85be8dd9..3421a930 100644 --- a/ReflectionTemplateLib/access/src/CMakeLists.txt +++ b/ReflectionTemplateLib/access/src/CMakeLists.txt @@ -11,7 +11,6 @@ set(LOCAL_SOURCES SET(COMMON_HEADERS "${PROJECT_SOURCE_DIR}/common/Constants.h" - "${PROJECT_SOURCE_DIR}/common/Constants.hpp" "${PROJECT_SOURCE_DIR}/common/RTLibInterface.h" ) diff --git a/ReflectionTemplateLib/access/src/Method.cpp b/ReflectionTemplateLib/access/src/Method.cpp index 77070b2d..28d8aaa1 100644 --- a/ReflectionTemplateLib/access/src/Method.cpp +++ b/ReflectionTemplateLib/access/src/Method.cpp @@ -1,6 +1,5 @@ #include "Method.h" -#include "Constants.hpp" namespace rtl { @@ -18,7 +17,7 @@ namespace rtl { Method Method::getDestructorMethod(const Function& pFunction, const detail::FunctorId& pFunctorId) { - const std::string dctorStr = getDctorName(pFunction.getRecordName()); + const std::string dctorStr = CtorName::dctor(pFunction.getRecordName()); return Method(pFunction, pFunctorId, dctorStr); } } diff --git a/ReflectionTemplateLib/access/src/Record.cpp b/ReflectionTemplateLib/access/src/Record.cpp index 2626fb36..0c773576 100644 --- a/ReflectionTemplateLib/access/src/Record.cpp +++ b/ReflectionTemplateLib/access/src/Record.cpp @@ -4,7 +4,6 @@ #include "RStatus.h" #include "Instance.h" #include "Constants.h" -#include "Constants.hpp" #include "Function.hpp" namespace rtl { @@ -45,9 +44,9 @@ namespace rtl { return std::make_pair(RStatus(Error::EmptyInstance), Instance()); } - const std::string& dctor = getDctorName(m_recordName); - const std::string& copyStr = getCopyCtorName(m_recordName); - const std::string& constCopyStr = getConstCopyCtorName(m_recordName); + const std::string& dctor = CtorName::dctor(m_recordName); + const std::string& copyStr = CtorName::copy(m_recordName); + const std::string& constCopyStr = CtorName::constCopy(m_recordName); std::optional destructor = getMethod(dctor); std::optional constCopyCtor = getMethod(constCopyStr); diff --git a/ReflectionTemplateLib/builder/CMakeLists.txt b/ReflectionTemplateLib/builder/CMakeLists.txt index b95cdb63..7956d660 100644 --- a/ReflectionTemplateLib/builder/CMakeLists.txt +++ b/ReflectionTemplateLib/builder/CMakeLists.txt @@ -2,7 +2,6 @@ SET(COMMON_HEADERS "${PROJECT_SOURCE_DIR}/common/Constants.h" - "${PROJECT_SOURCE_DIR}/common/Constants.hpp" ) SET(LOCAL_HEADERS diff --git a/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp b/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp index 01d2cc36..5f8047b9 100644 --- a/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp +++ b/ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp @@ -2,7 +2,6 @@ #include "Function.h" #include "Builder.hpp" -#include "Constants.hpp" #include "ConstructorBuilder.h" namespace rtl { @@ -26,15 +25,15 @@ namespace rtl { { default: case FunctorType::Ctor: { - const auto& ctorName = getCtorName(m_record); + const auto& ctorName = CtorName::ctor(m_record); return Builder(m_namespace, m_record, ctorName).build<_recordType, _ctorSignature...>(); } case FunctorType::CopyCtor: { - const auto& ctorName = getCopyCtorName(m_record); + const auto& ctorName = CtorName::copy(m_record); return Builder(m_namespace, m_record, ctorName).build<_recordType, _ctorSignature...>(); } case FunctorType::CopyCtorConst: { - const auto& ctorName = getConstCopyCtorName(m_record); + const auto& ctorName = CtorName::constCopy(m_record); return Builder(m_namespace, m_record, ctorName).build<_recordType, _ctorSignature...>(); } } diff --git a/ReflectionTemplateLib/common/Constants.h b/ReflectionTemplateLib/common/Constants.h index 0d7fc9c8..9594e757 100644 --- a/ReflectionTemplateLib/common/Constants.h +++ b/ReflectionTemplateLib/common/Constants.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace rtl { @@ -61,4 +62,23 @@ namespace rtl { template using enable_if_not_same = typename std::enable_if< !std::is_same<_type, _typeB>::value >::type; + + struct CtorName + { + static const std::string ctor(const std::string& pRecordName) { + return (pRecordName + "::" + pRecordName + "()"); + } + + static const std::string dctor(const std::string& pRecordName) { + return (pRecordName + "::~" + pRecordName + "()"); + } + + static const std::string copy(const std::string& pRecordName) { + return (pRecordName + "::" + pRecordName + "(" + pRecordName + "&)"); + } + + static const std::string constCopy(const std::string& pRecordName) { + return (pRecordName + "::" + pRecordName + "(const " + pRecordName + "&)"); + } + }; } \ No newline at end of file diff --git a/ReflectionTemplateLib/common/Constants.hpp b/ReflectionTemplateLib/common/Constants.hpp deleted file mode 100644 index 59e80b9c..00000000 --- a/ReflectionTemplateLib/common/Constants.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include - -namespace rtl -{ - static constexpr const std::string getCtorName(const std::string& pRecordName) { - return (pRecordName + "::~" + pRecordName + "()"); - } - - static constexpr const std::string getDctorName(const std::string& pRecordName) { - return (pRecordName + "::" + pRecordName + "()"); - } - - static constexpr const std::string getCopyCtorName(const std::string& pRecordName) { - return (pRecordName + "::" + pRecordName + "(" + pRecordName + "&)"); - } - - static constexpr const std::string getConstCopyCtorName(const std::string& pRecordName) { - return (pRecordName + "::" + pRecordName + "(const " + pRecordName + "&)"); - } -} \ No newline at end of file diff --git a/ReflectionTemplateLib/detail/src/CxxReflection.cpp b/ReflectionTemplateLib/detail/src/CxxReflection.cpp index f9760c55..d6092093 100644 --- a/ReflectionTemplateLib/detail/src/CxxReflection.cpp +++ b/ReflectionTemplateLib/detail/src/CxxReflection.cpp @@ -2,7 +2,6 @@ #include "TypeId.h" #include "Record.h" #include "Method.h" -#include "Constants.hpp" #include "CxxReflection.h" namespace rtl { @@ -54,7 +53,7 @@ namespace rtl { auto& functorIds = pFunction.getFunctorIds(); if (functorIds.size() > 1) { - const auto& dctorName = getDctorName(pFunction.getRecordName()); + const auto& dctorName = CtorName::dctor(pFunction.getRecordName()); if (pMethodMap.find(dctorName) == pMethodMap.end()) { access::Method method = access::Method::getDestructorMethod(pFunction, functorIds[1]); pMethodMap.insert(std::make_pair(method.getFunctionName(), method));