diff --git a/CMakeLists.txt b/CMakeLists.txt index ae663328..0500cf1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,7 @@ project(CxxReflectionProject) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") # Add the subdirectories -add_subdirectory(CxxTestDesignPatternsUsingRTL) -add_subdirectory(CxxRTLTypeRegistration) +add_subdirectory(CxxTestRegistration) add_subdirectory(RTLTestRunApp) add_subdirectory(RTLBenchmarkApp) add_subdirectory(CxxTestProps) diff --git a/CxxTestDesignPatternsUsingRTL/CMakeLists.txt b/CxxTestDesignPatternsUsingRTL/CMakeLists.txt deleted file mode 100644 index b33a244a..00000000 --- a/CxxTestDesignPatternsUsingRTL/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Set the minimum required CMake version -cmake_minimum_required(VERSION 3.20) - -add_subdirectory(CxxTestProxyDesignPattern) -add_subdirectory(CxxTestSingletonReflectedAccess) \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/CMakeLists.txt b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/CMakeLists.txt deleted file mode 100644 index 79fd2f84..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# CMakeLists.txt for ProxyDesignPattern - -# Set the minimum required CMake version -cmake_minimum_required(VERSION 3.20) - -# Set the project name -project(CxxTestProxyDesignPattern) - -set(CMAKE_CXX_STANDARD 20) - -# Set the build type to Debug -#set(CMAKE_BUILD_TYPE Debug) - -# Enable debug symbols -#set(CMAKE_CXX_FLAGS_DEBUG "-g") - -set(CXX_EXE_NAME CxxTestProxyDesignPattern) -add_executable(${CXX_EXE_NAME} "") - - -INCLUDE_DIRECTORIES(inc) -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/common") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/detail/inc") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/access/inc") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/builder/inc") - -TARGET_LINK_LIBRARIES(${CXX_EXE_NAME} ReflectionTemplateLib) - -# Add the source directory -INCLUDE(src/CMakeLists.txt) \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Original.h b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Original.h deleted file mode 100644 index 8ad9a6ee..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Original.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include - -namespace proxy_test { - - class Original - { - std::string m_nodeName; ///< The name of the node. - const std::string m_className; ///< The name of the class. - - static unsigned int m_instanceCount; ///< The count of instances created. - - public: - - /** - * @brief Constructs a new Original object. - */ - Original(); - - /** - * @brief Destroys the Original object. - */ - ~Original(); - - /** - * @brief Gets the class name. - * @return The class name as a string. - */ - std::string getClassName(); - - /** - * @brief Gets the square root of the given number. - * @param pNum The number to get the square root of. - * @return The square root of the given number. - */ - const double getSquareRoot(const double pNum); - - /** - * @brief Sets the node name. - * @param pName The name to set for the node. - */ - void setNodeName(std::string pName); - - /** - * @brief Gets the node name. - * @return The node name as a constant reference to a string. - */ - const std::string& getNodeName(); - - /** - * @brief Gets the instance count. - * @return The instance count as a constant reference to an integer. - */ - static const unsigned int& getInstanceCount(); - }; -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/OriginalReflection.h b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/OriginalReflection.h deleted file mode 100644 index d12605b4..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/OriginalReflection.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "RTLibInterface.h" - -namespace proxy_test { - - /** - * @brief The OriginalReflection struct provides reflection capabilities for the "Original" class. - * - * This struct is designed as a monostate class, meaning it provides shared functionality - * without requiring instantiation. It uses the reflection system to dynamically register - * and retrieve metadata for the "Original" class, including its methods and constructor. - */ - struct OriginalReflection - { - /** - * @brief Deleted default constructor to prevent instantiation. - * - * The OriginalReflection struct is designed to be used statically, so no instances - * of this struct should be created. - */ - OriginalReflection() = delete; - - /** - * @brief Deleted copy constructor to prevent copying. - * - * Ensures that the struct cannot be copied, maintaining its monostate design. - */ - OriginalReflection(const OriginalReflection&) = delete; - - /** - * @brief Deleted copy assignment operator to prevent assignment. - * - * Ensures that the struct cannot be assigned, maintaining its monostate design. - */ - OriginalReflection& operator=(const OriginalReflection&) = delete; - - /** - * @brief Retrieves the reflection data for the "Original" class. - * - * This method uses the reflection system to dynamically register and retrieve - * metadata for the "Original" class, including its constructor, instance methods, - * and static methods. The reflection data is stored as a static optional object - * to ensure it is initialized only once and reused across multiple calls. - * - * @return A constant reference to an optional containing the reflection data - * for the "Original" class. If the reflection data is unavailable, the optional - * will be empty. - */ - static const std::optional& getClass(); - }; -} diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.h b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.h deleted file mode 100644 index 416894b7..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include -#include "OriginalReflection.h" - -namespace proxy_test { - - /** - * @brief The Proxy class provides a mechanism to forward calls to an instance of the "Original" class. - */ - class Proxy - { - rtl::RObject m_originalObj; //Reflected type instance of the "Original" class. - - public: - - /** - * @brief Constructs a new Proxy object. - * - * Initializes the m_originalObj with an instance of the "Original" class. - */ - Proxy(); - - /** - * @brief Forwards a call to a method of the "Original" class instance. - * - * @tparam _args The types of the arguments to be forwarded. - * @param pFunctionName The name of the function to call. - * @param params The parameters to pass to the function. - * @return The result of the function call as a std::any object. - */ - template - rtl::Return forwardCall(const std::string& pFunctionName, _args&& ...params); - - /** - * @brief Forwards a call to a static method of the "Original" class. - * - * @tparam _args The types of the arguments to be forwarded. - * @param pFunctionName The name of the static function to call. - * @param params The parameters to pass to the function. - * @return The result of the function call as a std::any object. - */ - template - static rtl::Return forwardStaticCall(const std::string& pFunctionName, _args&& ...params); - }; -} diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.hpp b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.hpp deleted file mode 100644 index 3744d103..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/inc/Proxy.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once -#include "Proxy.h" - -namespace proxy_test -{ - /** - * @brief Forwards a call to a method of the Original class instance. - * - * This method uses reflection to dynamically invoke a method on the Original class instance. - * It checks if the method exists and if the signature matches the provided arguments. - * - * @tparam _args The types of the arguments to be forwarded. - * @param pFunctionName The name of the function to call. - * @param params The parameters to pass to the function. - * @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. - */ - template - inline rtl::Return Proxy::forwardCall(const std::string& pFunctionName, _args&& ...params) - { - const auto orgMethod = OriginalReflection::getClass()->getMethod(pFunctionName); - if (!orgMethod.has_value()) { - return { rtl::error::FunctionNotRegistered, rtl::RObject{ } }; - } - if (orgMethod->hasSignature<_args...>()) { - return orgMethod->bind(m_originalObj).call(std::forward<_args>(params)...); - } - return { rtl::error::SignatureMismatch, rtl::RObject{ } }; - } - - - /** - * @brief Forwards a call to a static method of the Original class. - * - * This method uses reflection to dynamically invoke a static method on the Original class. - * It checks if the method exists and if the signature matches the provided arguments. - * - * @tparam _args The types of the arguments to be forwarded. - * @param pFunctionName The name of the static function to call. - * @param params The parameters to pass to the function. - * @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. - */ - template - inline rtl::Return Proxy::forwardStaticCall(const std::string& pFunctionName, _args&& ...params) - { - const auto orgMethod = OriginalReflection::getClass()->getMethod(pFunctionName); - if (!orgMethod.has_value()) { - return { rtl::error::FunctionNotRegistered, rtl::RObject{ } }; - } - if (orgMethod->hasSignature<_args...>()) { - return orgMethod->bind().call(std::forward<_args>(params)...); - } - return { rtl::error::SignatureMismatch, rtl::RObject{ } }; - } -} diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/CMakeLists.txt b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/CMakeLists.txt deleted file mode 100644 index 20abf8da..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# CMakeLists.txt for CxxTypeRegistration -cmake_minimum_required(VERSION 3.20) - -project(CxxTestProxyDesignPattern) - -# Create a variable containing the source files for your target -set(LOCAL_SOURCES - "${CMAKE_CURRENT_LIST_DIR}/main.cpp" - "${CMAKE_CURRENT_LIST_DIR}/Original.cpp" - "${CMAKE_CURRENT_LIST_DIR}/OriginalReflection.cpp" - "${CMAKE_CURRENT_LIST_DIR}/Proxy.cpp" -) - -SET(LOCAL_HEADERS - "${PROJECT_SOURCE_DIR}/inc/Original.h" - "${PROJECT_SOURCE_DIR}/inc/OriginalReflection.h" - "${PROJECT_SOURCE_DIR}/inc/Proxy.h" - "${PROJECT_SOURCE_DIR}/inc/Proxy.hpp" -) - -# Add any additional source files if needed -target_sources(CxxTestProxyDesignPattern - PRIVATE - "${LOCAL_SOURCES}" - "${LOCAL_HEADERS}" -) \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/Original.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/Original.cpp deleted file mode 100644 index 09e2121d..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/Original.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include "Original.h" - -namespace proxy_test { - - unsigned int Original::m_instanceCount = 0; - - /** - * @brief Constructs a new Original object. - * - * Initializes the node name to "defaultNodeName" and the class name to "Original". - * Increments the instance count and prints a message indicating the constructor call. - */ - Original::Original() - : m_nodeName("defaultNodeName") - , m_className("Original") - { - m_instanceCount++; - std::cout << "\"Original\" constructor called, instance count: " << m_instanceCount << "\n"; - } - - /** - * @brief Destroys the Original object. - * - * Decrements the instance count and prints a message indicating the destructor call. - */ - Original::~Original() - { - m_instanceCount--; - std::cout << "\"Original\" destructor called, instance count: " << m_instanceCount << "\n"; - } - - /** - * @brief Gets the instance count. - * @return The instance count as a constant reference to an integer. - */ - const unsigned int& Original::getInstanceCount() - { - return m_instanceCount; - } - - /** - * @brief Gets the class name. - * @return The class name as a string. - */ - std::string Original::getClassName() - { - return m_className; - } - - /** - * @brief Gets the square root of the given number. - * @param pNum The number to get the square root of. - * @return The square root of the given number. - */ - const double Original::getSquareRoot(const double pNum) - { - return std::sqrt(pNum); - } - - /** - * @brief Sets the node name. - * @param pName The name to set for the node. - */ - void Original::setNodeName(std::string pName) - { - m_nodeName = pName; - } - - /** - * @brief Gets the node name. - * @return The node name as a constant reference to a string. - */ - const std::string& Original::getNodeName() - { - return m_nodeName; - } -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/OriginalReflection.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/OriginalReflection.cpp deleted file mode 100644 index 07c4cb8b..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/OriginalReflection.cpp +++ /dev/null @@ -1,46 +0,0 @@ - -#include "OriginalReflection.h" -#include "Original.h" - - -namespace proxy_test -{ - /** - * @brief Retrieves the reflection data for the "Original" class. - * - * This method uses the CxxMirror reflection system to dynamically register the "Original" class, - * including its constructor, instance methods, and static methods. The reflection data is stored - * as a static optional object to ensure it is initialized only once and reused across multiple calls. - * - * @return const std::optional& A reference to the optional reflection data - * for the "Original" class. If the reflection data is unavailable, the optional will be empty. - */ - const std::optional& OriginalReflection::getClass() - { - // Static reflection data for the "Original" class - static std::optional reflectedClass = rtl::CxxMirror( { - - // Register the default constructor of the "Original" class - rtl::type().record("Original").build(), - - // Register the instance method: getClassName - rtl::type().member().method("getClassName").build(&Original::getClassName), - - // Register the instance method: getSquareRoot - rtl::type().member().method("getSquareRoot").build(&Original::getSquareRoot), - - // Register the instance method: setNodeName - rtl::type().member().method("setNodeName").build(&Original::setNodeName), - - // Register the instance method: getNodeName - rtl::type().member().method("getNodeName").build(&Original::getNodeName), - - // Register the static method: getInstanceCount - rtl::type().member().methodStatic("getInstanceCount").build(&Original::getInstanceCount) - - }).getRecord("Original"); - - // Return the reflection data for the "Original" class - return reflectedClass; - } -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/Proxy.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/Proxy.cpp deleted file mode 100644 index 0e026ea0..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/Proxy.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -#include - -#include "Proxy.h" -#include "OriginalReflection.h" - -namespace proxy_test -{ - /** - * @brief Constructs a new Proxy object. - * - * Initializes the m_originalObj with an instance of the "Original" class. - * If the instance creation is successful, m_originalObj is set to the created instance. - */ - Proxy::Proxy() - : m_originalObj([&]() { - auto [err, robj] = OriginalReflection::getClass()->create(); - return (err == rtl::error::None ? std::move(robj) : rtl::RObject{ }); - }()) - { - assert(!m_originalObj.isEmpty() && "Reflected instance creation failed."); - } -} diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/main.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/main.cpp deleted file mode 100644 index bf1bb210..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestProxyDesignPattern/src/main.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include "Proxy.hpp" - -using namespace proxy_test; - -int main() { - - // Call a static method of "Original" dynamically using the Proxy class - auto [ierr, irobj] = Proxy::forwardStaticCall("getInstanceCount"); - if (ierr != rtl::error::None || irobj.isEmpty() || !irobj.canViewAs()) { - std::cout << "Proxy call to 'getInstanceCount' failed! (error: " << rtl::to_string(ierr) << ")" << std::endl; - return -1; - } - - const auto& icount = irobj.view()->get(); - std::cout << "proxy static-call, getInstanceCount() return: " << icount << "\n"; - - { - Proxy proxyObj; - - // Call an instance method of "Original" dynamically to get the class name - auto [err0, robj0] = proxyObj.forwardCall("getClassName"); - if (err0 != rtl::error::None || robj0.isEmpty() || !robj0.canViewAs()) { - std::cout << "Proxy call to 'getClassName' failed! (error: " << rtl::to_string(err0) << ")" << std::endl; - return -1; - } - const auto& name0 = robj0.view()->get(); - std::cout << "proxy call, getClassName() return: \"" << name0 << "\"\n"; - - - // Call an instance method of "Original" dynamically to get the square root of a number - auto [err1, robj1] = proxyObj.forwardCall("getSquareRoot", double(10000)); - if (err1 != rtl::error::None || robj1.isEmpty() || !robj1.canViewAs()) { - std::cout << "Proxy call to 'getSquareRoot' failed! (error: " << rtl::to_string(err1) << ")" << std::endl; - return -1; - } - const auto& sqroot = robj1.view()->get(); - std::cout << "proxy call, getSquareRoot() return: " << sqroot << "\n"; - - // Call an instance method of "Original" dynamically to set the node name - auto [err2, robj2] = proxyObj.forwardCall("setNodeName", std::string("testNode")); - if (err2 != rtl::error::None) { - std::cout << "Proxy call to 'setNodeName' failed! (error: " << rtl::to_string(err2) << ")" << std::endl; - return -1; - } - std::cout << "proxy call, setNodeName() called with string \"testNode\"\n"; - - // Call an instance method of "Original" dynamically to get the node name - auto [err3, robj3] = proxyObj.forwardCall("getNodeName"); - if (err3 != rtl::error::None || robj3.isEmpty() || !robj3.canViewAs()) { - std::cout << "Proxy call to 'getNodeName' failed! (error: " << rtl::to_string(err3) << ")" << std::endl; - return -1; - } - const auto& name1 = robj3.view()->get(); - std::cout << "proxy call, getNodeName() return: \"" << name1 << "\"\n"; - } - - // Call the static method of "Original" again to get the updated instance count - const auto [oerr, orobj] = Proxy::forwardStaticCall("getInstanceCount"); - if (oerr != rtl::error::None || orobj.isEmpty() || !orobj.canViewAs()) { - std::cout << "Proxy call to 'getInstanceCount' failed! (error: " << rtl::to_string(oerr) << ")" << std::endl; - return -1; - } - const auto& ocount = orobj.view()->get(); - if (ocount != 0) { - std::cout << "proxy static-call, getInstanceCount() return: " << ocount << ".\nReflected instance not destroyed, memory leak. FAILURE!!\n"; - } - else { - std::cout << "proxy static-call, getInstanceCount() return: " << ocount << "\n"; - } - return 0; -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/CMakeLists.txt b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/CMakeLists.txt deleted file mode 100644 index 6afc4a02..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# CMakeLists.txt for SingletonReflectedAccess - -# Set the minimum required CMake version -cmake_minimum_required(VERSION 3.20) - -# Set the project name -project(CxxTestSingletonReflectedAccess) - -set(CMAKE_CXX_STANDARD 20) - -# Set the build type to Debug -#set(CMAKE_BUILD_TYPE Debug) - -# Enable debug symbols -#set(CMAKE_CXX_FLAGS_DEBUG "-g") - -set(CXX_EXE_NAME CxxTestSingletonReflectedAccess) -add_executable(${CXX_EXE_NAME} "") - - -INCLUDE_DIRECTORIES(inc) -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/common") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/detail/inc") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/access/inc") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/builder/inc") - -TARGET_LINK_LIBRARIES(${CXX_EXE_NAME} ReflectionTemplateLib) - -# Add the source directory -INCLUDE(src/CMakeLists.txt) \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/inc/Singleton.h b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/inc/Singleton.h deleted file mode 100644 index a61b4dd2..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/inc/Singleton.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -constexpr const char* HELLO_STR = "Hello from Singleton!"; - -class Singleton -{ - // Private constructor to prevent external instantiation - Singleton(); - - ~Singleton(); - -public: - - // Delete copy constructor and assignment operator - Singleton(const Singleton&) = delete; - Singleton& operator=(const Singleton&) = delete; - - Singleton(Singleton&&) = delete; - Singleton& operator=(Singleton&&) = delete; - - // Static method to access the single instance - static const Singleton& getInstance(); - - // Example method - std::string getHelloString() const; -}; \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/inc/SingletonReflection.h b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/inc/SingletonReflection.h deleted file mode 100644 index 08351944..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/inc/SingletonReflection.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "RTLibInterface.h" - -namespace singleton_test { - - /** - * @brief The OriginalReflection struct provides reflection capabilities for the "Original" class. - * - * This struct is designed as a monostate class, meaning it provides shared functionality - * without requiring instantiation. It uses the reflection system to dynamically register - * and retrieve metadata for the "Original" class, including its methods and constructor. - */ - struct Reflection - { - Reflection() = delete; - - Reflection(const Reflection&) = delete; - - Reflection& operator=(const Reflection&) = delete; - - static const std::optional& getSingletonClass(); - }; -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/CMakeLists.txt b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/CMakeLists.txt deleted file mode 100644 index 7c87381e..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# CMakeLists.txt for CxxTypeRegistration -cmake_minimum_required(VERSION 3.20) - -project(CxxTestSingletonReflectedAccess) - -# Create a variable containing the source files for your target -set(LOCAL_SOURCES - "${CMAKE_CURRENT_LIST_DIR}/main.cpp" - "${CMAKE_CURRENT_LIST_DIR}/Singleton.cpp" - "${CMAKE_CURRENT_LIST_DIR}/SingletonReflection.cpp" -) - -SET(LOCAL_HEADERS - "${PROJECT_SOURCE_DIR}/inc/Singleton.h" - "${PROJECT_SOURCE_DIR}/inc/SingletonReflection.h" -) - -# Add any additional source files if needed -target_sources(CxxTestSingletonReflectedAccess - PRIVATE - "${LOCAL_SOURCES}" - "${LOCAL_HEADERS}" -) \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/Singleton.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/Singleton.cpp deleted file mode 100644 index 919cd5f8..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/Singleton.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include "Singleton.h" - -Singleton::Singleton() -{ - -} - -Singleton::~Singleton() -{ - -} - -const Singleton& Singleton::getInstance() -{ - static Singleton instance; - return instance; -} - - -std::string Singleton::getHelloString() const -{ - return HELLO_STR; -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/SingletonReflection.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/SingletonReflection.cpp deleted file mode 100644 index 2957d234..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/SingletonReflection.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -#include "Singleton.h" -#include "SingletonReflection.h" - -namespace singleton_test -{ - const std::optional& Reflection::getSingletonClass() - { - static std::optional reflectedClass = rtl::CxxMirror( - { - rtl::type().record("Singleton").build(), - - rtl::type().member().methodStatic("getInstance").build(&Singleton::getInstance), - - rtl::type().member().methodConst("getHelloString").build(&Singleton::getHelloString) - - }).getRecord("Singleton"); - - return reflectedClass; - } -} \ No newline at end of file diff --git a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/main.cpp b/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/main.cpp deleted file mode 100644 index 332b973f..00000000 --- a/CxxTestDesignPatternsUsingRTL/CxxTestSingletonReflectedAccess/src/main.cpp +++ /dev/null @@ -1,47 +0,0 @@ - -#include -#include "SingletonReflection.h" - -using namespace singleton_test; - -int main() -{ - std::cout << "Singleton Instance reflected access test." << std::endl; - { - const auto& getInstance = Reflection::getSingletonClass()->getMethod("getInstance"); - - if (!getInstance.has_value()) { - std::cout << "Singleton::getInstance() not found! Test Failed." << std::endl; - return -1; - } - - auto [err, robj] = getInstance->bind().call(); - - if (err != rtl::error::None) { - std::cout << "Singleton::getInstance() reflected call failed! Error: " << rtl::to_string(err) << std::endl; - return -1; - } - - const auto& getHelloString = Reflection::getSingletonClass()->getMethod("getHelloString"); - - if (!getHelloString.has_value()) { - std::cout << "Singleton::getHelloString() not found! Test Failed." << std::endl; - return -1; - } - - auto [err0, retVal] = getHelloString->bind(robj).call(); - - if (err0 != rtl::error::None || !retVal.canViewAs()) { - std::cout << "Singleton::getHelloString() reflected call failed! Error: " << rtl::to_string(err) << std::endl; - return -1; - } - - const auto& helloStr = retVal.view()->get(); - - std::cout << "Singleton::getHelloString(), reflected call returned: " << helloStr << std::endl; - } - - std::cout << "Singleton Instance reflected access test. PASSED." << std::endl; - - return 0; -} \ No newline at end of file diff --git a/CxxRTLTypeRegistration/CMakeLists.txt b/CxxTestRegistration/CMakeLists.txt similarity index 91% rename from CxxRTLTypeRegistration/CMakeLists.txt rename to CxxTestRegistration/CMakeLists.txt index 0aaeb81e..96b0a6a3 100644 --- a/CxxRTLTypeRegistration/CMakeLists.txt +++ b/CxxTestRegistration/CMakeLists.txt @@ -4,11 +4,11 @@ cmake_minimum_required(VERSION 3.20) # Set the project name -project(CxxRTLTypeRegistration) +project(CxxTestRegistration) set(CMAKE_CXX_STANDARD 20) -SET(CXX_LIB_NAME CxxRTLTypeRegistration) +SET(CXX_LIB_NAME CxxTestRegistration) ADD_LIBRARY(${PROJECT_NAME} STATIC "") diff --git a/CxxRTLTypeRegistration/inc/TestMirrorProvider.h b/CxxTestRegistration/inc/TestMirrorProvider.h similarity index 100% rename from CxxRTLTypeRegistration/inc/TestMirrorProvider.h rename to CxxTestRegistration/inc/TestMirrorProvider.h diff --git a/CxxRTLTypeRegistration/src/CMakeLists.txt b/CxxTestRegistration/src/CMakeLists.txt similarity index 90% rename from CxxRTLTypeRegistration/src/CMakeLists.txt rename to CxxTestRegistration/src/CMakeLists.txt index 51669850..4592f47c 100644 --- a/CxxRTLTypeRegistration/src/CMakeLists.txt +++ b/CxxTestRegistration/src/CMakeLists.txt @@ -1,7 +1,7 @@ # CMakeLists.txt for ReflectionTypeRegistration cmake_minimum_required(VERSION 3.20) -project(CxxRTLTypeRegistration) +project(CxxTestRegistration) # Create a variable containing the source files for your target set(LOCAL_SOURCES @@ -18,7 +18,7 @@ SET(LOCAL_HEADERS ) # Add any additional source files if needed -target_sources(CxxRTLTypeRegistration +target_sources(CxxTestRegistration PRIVATE "${LOCAL_SOURCES}" "${LOCAL_HEADERS}" diff --git a/CxxRTLTypeRegistration/src/TestMirrorProvider.cpp b/CxxTestRegistration/src/TestMirrorProvider.cpp similarity index 89% rename from CxxRTLTypeRegistration/src/TestMirrorProvider.cpp rename to CxxTestRegistration/src/TestMirrorProvider.cpp index dd2ac277..db44c78e 100644 --- a/CxxRTLTypeRegistration/src/TestMirrorProvider.cpp +++ b/CxxTestRegistration/src/TestMirrorProvider.cpp @@ -205,41 +205,41 @@ namespace test_mirror /* GCC fails to automatically identify the correct overloaded functor to pick. (non-const-lvalue-ref & rvalue as argument) we need to explicitly cast the functor like, static_cast(&Animal::setAnimalName). */ rtl::type().member() - .method(animal::str_setAnimalName) - .build(static_cast(&Animal::setAnimalName)), //overloaded method, taking non-const lvalue reference as argument. + .method(animal::str_setAnimalName) + .build(static_cast(&Animal::setAnimalName)), //overloaded method, taking non-const lvalue reference as argument. rtl::type().member() - .method(animal::str_setAnimalName) - .build(static_cast(&Animal::setAnimalName)), //overloaded method, taking rvalue reference as argument. + .method(animal::str_setAnimalName) + .build(static_cast(&Animal::setAnimalName)), //overloaded method, taking rvalue reference as argument. rtl::type().member() - .methodStatic(animal::str_updateZooKeeper) - .build(static_cast(&Animal::updateZooKeeper)), //static method, taking non-const lvalue reference as argument. + .methodStatic(animal::str_updateZooKeeper) + .build(static_cast(&Animal::updateZooKeeper)), //static method, taking non-const lvalue reference as argument. rtl::type().member() - .methodStatic(animal::str_updateZooKeeper) - .build(static_cast(&Animal::updateZooKeeper)), //static method, taking rvalue reference as argument. + .methodStatic(animal::str_updateZooKeeper) + .build(static_cast(&Animal::updateZooKeeper)), //static method, taking rvalue reference as argument. #else rtl::type().member() - .method(animal::str_setAnimalName) - .build(&Animal::setAnimalName), //overloaded method, taking non-const lvalue reference as argument. + .method(animal::str_setAnimalName) + .build(&Animal::setAnimalName), //overloaded method, taking non-const lvalue reference as argument. rtl::type().member() - .method(animal::str_setAnimalName) - .build(&Animal::setAnimalName), //overloaded method, taking rvalue reference as argument. + .method(animal::str_setAnimalName) + .build(&Animal::setAnimalName), //overloaded method, taking rvalue reference as argument. rtl::type().member() - .methodStatic(animal::str_updateZooKeeper) - .build(&Animal::updateZooKeeper), //static method, taking non-const lvalue reference as argument. + .methodStatic(animal::str_updateZooKeeper) + .build(&Animal::updateZooKeeper), //static method, taking non-const lvalue reference as argument. rtl::type().member() - .methodStatic(animal::str_updateZooKeeper) - .build(&Animal::updateZooKeeper), //static method, taking rvalue reference as argument. + .methodStatic(animal::str_updateZooKeeper) + .build(&Animal::updateZooKeeper), //static method, taking rvalue reference as argument. #endif }); - static const auto _ = [&]() + static const auto _= [&]() { const std::string pathStr = std::filesystem::current_path().string() + "/MyReflection.json"; std::cout << "\n[ OUTPUT] test_mirror::cxx::mirror() ==> dumping 'CxxMirror' as JSON." diff --git a/README.md b/README.md index 24e877d4..65f79607 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ RTL is implemented as a *static library* that organizes function pointers into ` * ***Tooling-Friendly Architecture*** – Reflection data is encapsulated in a single immutable, lazily-initialized object that can be shared with tools and frameworks without compile-time type knowledge — ideal for serializers, debuggers, test frameworks, scripting engines, and editors. -[![Design Features](https://img.shields.io/badge/Doc-Design%20Features-blue)](./Design-Docs/DESIGN_PRINCIPLES_AND_FEATURES.md) -[![RTL Syntax & Semantics](https://img.shields.io/badge/Doc-Syntax_&_Semantics-blueviolet)](./Design-Docs/RTL_SYNTAX_AND_SEMANTICS.md) +[![Design Features](https://img.shields.io/badge/Doc-Design%20Features-blue)](./text-design-docs/DESIGN_PRINCIPLES_AND_FEATURES.md) +[![RTL Syntax & Semantics](https://img.shields.io/badge/Doc-Syntax_&_Semantics-blueviolet)](./text-design-docs/RTL_SYNTAX_AND_SEMANTICS.md) ## A Quick Preview: Reflection That Looks and Feels Like C++ @@ -157,7 +157,7 @@ cmake --build . ``` Run the **CxxRTLTestApplication** binary generated in the `../bin` folder. *(Tested MSVC-19, GCC-14 & Clang-19)* -* See `CxxRTLTypeRegistration/src/MyReflectionTests/` for introductory type registration & reflective programming examples. +* See `CxxTestRegistration/src/MyReflectionTests/` for introductory type registration & reflective programming examples. * See `CxxRTLTestApplication/src` for detailed test cases. ## Contributions diff --git a/RTLBenchmarkApp/src/ReflectedCall.cpp b/RTLBenchmarkApp/src/ReflectedCall.cpp index 12b1112f..325c72ea 100644 --- a/RTLBenchmarkApp/src/ReflectedCall.cpp +++ b/RTLBenchmarkApp/src/ReflectedCall.cpp @@ -21,9 +21,10 @@ namespace static rtl::RObject nodeObj = []() { auto Node = cxx::mirror().getRecord("Node").value(); - - rtl::RObject robj = Node.create().rObject; - + auto [err, robj] = Node.create(); + if (nodeObj.isEmpty()) { + std::cout << "[0] nodeObj empty! \n"; + } return std::move(robj); }(); } @@ -36,17 +37,17 @@ namespace auto err = SendMessage(bm::g_longStr).err; if (err != rtl::error::None) { - std::cout << "[0] error: "<< rtl::to_string(err)<<"\n"; + std::cout << "[1] error: "<< rtl::to_string(err)<<"\n"; } return 0; }; static auto _test1 = []() { - auto err = NodeSendMessage(nodeObj)(bm::g_longStr).err; + auto err = NodeSendMessage.bind(nodeObj).call(bm::g_longStr).err; if (err != rtl::error::None) { - std::cout << "[1] error: " << rtl::to_string(err) << "\n"; + std::cout << "[2] error: " << rtl::to_string(err) << "\n"; } return 0; }; @@ -56,7 +57,7 @@ namespace auto err = GetMessage(bm::g_longStr).err; if (err != rtl::error::None) { - std::cout << "[2] error: " << rtl::to_string(err) << "\n"; + std::cout << "[3] error: " << rtl::to_string(err) << "\n"; } return 0; }; @@ -66,7 +67,7 @@ namespace auto err = NodeGetMessage(nodeObj)(bm::g_longStr).err; if (err != rtl::error::None) { - std::cout << "[3] error: " << rtl::to_string(err) << "\n"; + std::cout << "[4] error: " << rtl::to_string(err) << "\n"; } return 0; }; @@ -74,7 +75,7 @@ namespace -void ReflectedCall::noReturn(benchmark::State& state) +void ReflectedCall::set(benchmark::State& state) { static auto _=_test0(); for (auto _: state) { @@ -85,7 +86,7 @@ void ReflectedCall::noReturn(benchmark::State& state) } -void ReflectedCall::withReturn(benchmark::State& state) +void ReflectedCall::get(benchmark::State& state) { static auto _=_test2(); for (auto _: state) @@ -96,7 +97,7 @@ void ReflectedCall::withReturn(benchmark::State& state) } -void ReflectedMethodCall::noReturn(benchmark::State& state) +void ReflectedMethodCall::set(benchmark::State& state) { static auto _=_test1(); for (auto _: state) @@ -107,7 +108,7 @@ void ReflectedMethodCall::noReturn(benchmark::State& state) } -void ReflectedMethodCall::withReturn(benchmark::State& state) +void ReflectedMethodCall::get(benchmark::State& state) { static auto _=_test3(); for (auto _: state) diff --git a/RTLBenchmarkApp/src/ReflectedCall.h b/RTLBenchmarkApp/src/ReflectedCall.h index 47ea0fb0..59416ca2 100644 --- a/RTLBenchmarkApp/src/ReflectedCall.h +++ b/RTLBenchmarkApp/src/ReflectedCall.h @@ -4,15 +4,15 @@ struct ReflectedCall { - static void noReturn(benchmark::State& state); + static void set(benchmark::State& state); - static void withReturn(benchmark::State& state); + static void get(benchmark::State& state); }; struct ReflectedMethodCall { - static void noReturn(benchmark::State& state); + static void set(benchmark::State& state); - static void withReturn(benchmark::State& state); + static void get(benchmark::State& state); }; \ No newline at end of file diff --git a/RTLBenchmarkApp/src/StandardCall.cpp b/RTLBenchmarkApp/src/StandardCall.cpp index 38ea32a1..39dda878 100644 --- a/RTLBenchmarkApp/src/StandardCall.cpp +++ b/RTLBenchmarkApp/src/StandardCall.cpp @@ -39,7 +39,7 @@ namespace bm } -void DirectCall::noReturn(benchmark::State& state) +void NativeCall::set(benchmark::State& state) { for (auto _: state) { @@ -49,7 +49,7 @@ void DirectCall::noReturn(benchmark::State& state) } -void DirectCall::withReturn(benchmark::State& state) +void NativeCall::get(benchmark::State& state) { static auto _=_put_line(); for (auto _: state) @@ -59,7 +59,7 @@ void DirectCall::withReturn(benchmark::State& state) } -void StdFuncCall::noReturn(benchmark::State& state) +void StdFuncCall::set(benchmark::State& state) { static auto _=_new_line(); for (auto _: state) @@ -70,7 +70,7 @@ void StdFuncCall::noReturn(benchmark::State& state) } -void StdFuncMethodCall::noReturn(benchmark::State& state) +void StdFuncMethodCall::set(benchmark::State& state) { static auto _=_new_line(); for (auto _: state) @@ -81,7 +81,7 @@ void StdFuncMethodCall::noReturn(benchmark::State& state) } -void StdFuncCall::withReturn(benchmark::State& state) +void StdFuncCall::get(benchmark::State& state) { static auto _=_new_line(); for (auto _: state) @@ -91,7 +91,7 @@ void StdFuncCall::withReturn(benchmark::State& state) } -void StdFuncMethodCall::withReturn(benchmark::State& state) +void StdFuncMethodCall::get(benchmark::State& state) { static auto _=_new_line(); for (auto _: state) diff --git a/RTLBenchmarkApp/src/StandardCall.h b/RTLBenchmarkApp/src/StandardCall.h index fca68298..da2e4a45 100644 --- a/RTLBenchmarkApp/src/StandardCall.h +++ b/RTLBenchmarkApp/src/StandardCall.h @@ -2,25 +2,25 @@ #include -struct DirectCall +struct NativeCall { - static void noReturn(benchmark::State& state); + static void set(benchmark::State& state); - static void withReturn(benchmark::State& state); + static void get(benchmark::State& state); }; struct StdFuncCall { - static void noReturn(benchmark::State& state); + static void set(benchmark::State& state); - static void withReturn(benchmark::State& state); + static void get(benchmark::State& state); }; struct StdFuncMethodCall { - static void noReturn(benchmark::State& state); + static void set(benchmark::State& state); - static void withReturn(benchmark::State& state); + static void get(benchmark::State& state); }; \ No newline at end of file diff --git a/RTLBenchmarkApp/src/main.cpp b/RTLBenchmarkApp/src/main.cpp index adac408a..bcefd8d1 100644 --- a/RTLBenchmarkApp/src/main.cpp +++ b/RTLBenchmarkApp/src/main.cpp @@ -6,21 +6,21 @@ #include "StandardCall.h" #include "ReflectedCall.h" -BENCHMARK(DirectCall::noReturn); +BENCHMARK(NativeCall::set); -BENCHMARK(StdFuncCall::noReturn); -BENCHMARK(ReflectedCall::noReturn); +BENCHMARK(StdFuncCall::set); +BENCHMARK(ReflectedCall::set); -BENCHMARK(StdFuncMethodCall::noReturn); -BENCHMARK(ReflectedMethodCall::noReturn); +BENCHMARK(StdFuncMethodCall::set); +BENCHMARK(ReflectedMethodCall::set); -BENCHMARK(DirectCall::withReturn); +BENCHMARK(NativeCall::get); -BENCHMARK(StdFuncCall::withReturn); -BENCHMARK(ReflectedCall::withReturn); +BENCHMARK(StdFuncCall::get); +BENCHMARK(ReflectedCall::get); -BENCHMARK(StdFuncMethodCall::withReturn); -BENCHMARK(ReflectedMethodCall::withReturn); +BENCHMARK(StdFuncMethodCall::get); +BENCHMARK(ReflectedMethodCall::get); namespace bm { diff --git a/RTLTestRunApp/CMakeLists.txt b/RTLTestRunApp/CMakeLists.txt index f22d810b..3b2177eb 100644 --- a/RTLTestRunApp/CMakeLists.txt +++ b/RTLTestRunApp/CMakeLists.txt @@ -30,7 +30,7 @@ FetchContent_MakeAvailable(googletest) set(RTL_INCLUDE_DIRS inc "${CMAKE_SOURCE_DIR}/CxxTestUtils/inc" - "${CMAKE_SOURCE_DIR}/CxxRTLTypeRegistration/inc" + "${CMAKE_SOURCE_DIR}/CxxTestRegistration/inc" "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/common" "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/detail/inc" "${CMAKE_SOURCE_DIR}/ReflectionTemplateLib/access/inc" @@ -52,7 +52,7 @@ target_link_libraries(${CXX_EXE_NAME} PRIVATE CxxTestUtils ReflectionTemplateLib - CxxRTLTypeRegistration + CxxTestRegistration GTest::gtest_main ) diff --git a/RTLTestRunApp/src/CMakeLists.txt b/RTLTestRunApp/src/CMakeLists.txt index 0684ee2c..e5d3fc3f 100644 --- a/RTLTestRunApp/src/CMakeLists.txt +++ b/RTLTestRunApp/src/CMakeLists.txt @@ -32,7 +32,7 @@ set(LOCAL_ROBJECT set(LOCAL_MY_REFLECTION "${CMAKE_CURRENT_LIST_DIR}/MyReflectionTests/MyReflectingType.h" "${CMAKE_CURRENT_LIST_DIR}/MyReflectionTests/MyReflectionTests.cpp" - "${CMAKE_CURRENT_LIST_DIR}/MyReflectionTests/MyCxxMirrorProvider.cpp" + "${CMAKE_CURRENT_LIST_DIR}/MyReflectionTests/MyCxxTestRegistration.cpp" ) diff --git a/RTLTestRunApp/src/FunctionalityTests/NameSpaceGlobalsTests.cpp b/RTLTestRunApp/src/FunctionalityTests/NameSpaceGlobalsTests.cpp index e6ff2411..705e5beb 100644 --- a/RTLTestRunApp/src/FunctionalityTests/NameSpaceGlobalsTests.cpp +++ b/RTLTestRunApp/src/FunctionalityTests/NameSpaceGlobalsTests.cpp @@ -59,7 +59,9 @@ namespace rtl_tests { //Now for cases, if you want to handle it type-erased and pass around. RObject reflChar = rtl::reflect('Q'); - error reterr = cxx::mirror().enableCloning(reflChar); + + error reterr = cxx::mirror().setupCloning(reflChar); + ASSERT_TRUE(reterr == error::None); { //Internally calls the copy constructor. diff --git a/RTLTestRunApp/src/FunctionalityTests/ReflectionOpErrorCodeTests.cpp b/RTLTestRunApp/src/FunctionalityTests/ReflectionOpErrorCodeTests.cpp index 0f6ed8c6..0fbbd762 100644 --- a/RTLTestRunApp/src/FunctionalityTests/ReflectionOpErrorCodeTests.cpp +++ b/RTLTestRunApp/src/FunctionalityTests/ReflectionOpErrorCodeTests.cpp @@ -70,7 +70,7 @@ namespace rtl_tests char ch = 'R'; RObject rCh = rtl::reflect(ch); - error reterr = cxx::mirror().enableCloning(rCh); + error reterr = cxx::mirror().setupCloning(rCh); ASSERT_TRUE(reterr == error::None); EXPECT_FALSE(rCh.isAllocatedByRtl()); @@ -114,7 +114,7 @@ namespace rtl_tests EXPECT_FALSE(rChptr.isAllocatedByRtl()); ASSERT_TRUE(rtl::getRtlManagedHeapInstanceCount() == 1); - error reterr = cxx::mirror().enableCloning(rChptr); + error reterr = cxx::mirror().setupCloning(rChptr); ASSERT_TRUE(reterr == error::None); EXPECT_TRUE(rChptr.canViewAs()); @@ -200,7 +200,7 @@ namespace rtl_tests EXPECT_TRUE(err2 == error::CloningDisabled); ASSERT_TRUE(eventCp0.isEmpty()); - error reterr = cxx::mirror().enableCloning(event); + error reterr = cxx::mirror().setupCloning(event); ASSERT_TRUE(reterr == error::None); // Try to call copy-constructor of class Event. diff --git a/RTLTestRunApp/src/FunctionalityTests/ReturnValueReflectionTest.cpp b/RTLTestRunApp/src/FunctionalityTests/ReturnValueReflectionTest.cpp index 80b87ff5..61bc03ed 100644 --- a/RTLTestRunApp/src/FunctionalityTests/ReturnValueReflectionTest.cpp +++ b/RTLTestRunApp/src/FunctionalityTests/ReturnValueReflectionTest.cpp @@ -51,7 +51,7 @@ namespace rtl_tests EXPECT_TRUE(err == rtl::error::CloningDisabled); } - rtl::error reterr = cxx::mirror().enableCloning(event); + rtl::error reterr = cxx::mirror().setupCloning(event); ASSERT_TRUE(reterr == rtl::error::None); { diff --git a/RTLTestRunApp/src/RObjectTests/RObjectReflecting_stdSharedPtr.cpp b/RTLTestRunApp/src/RObjectTests/RObjectReflecting_stdSharedPtr.cpp index f395856c..30d463fa 100644 --- a/RTLTestRunApp/src/RObjectTests/RObjectReflecting_stdSharedPtr.cpp +++ b/RTLTestRunApp/src/RObjectTests/RObjectReflecting_stdSharedPtr.cpp @@ -119,7 +119,7 @@ namespace rtl::unit_test constexpr const int NUM = -20438; RObject robj = reflect(std::make_shared(NUM)); - error reterr = cxx_mirror().enableCloning(robj); + error reterr = cxx_mirror().setupCloning(robj); ASSERT_TRUE(reterr == error::None); ASSERT_FALSE(robj.isEmpty()); @@ -214,7 +214,7 @@ namespace rtl::unit_test RObject robj = reflect(std::make_shared(NUM)); ASSERT_FALSE(robj.isEmpty()); - error reterr = cxx_mirror().enableCloning(robj); + error reterr = cxx_mirror().setupCloning(robj); ASSERT_TRUE(reterr == error::None); // --- Step 1: Clone by default (entity::Auto semantics) --- @@ -271,7 +271,7 @@ namespace rtl::unit_test ASSERT_FALSE(robj.isEmpty()); ASSERT_TRUE(Node::instanceCount() == 1); - error reterr = cxx_mirror().enableCloning(robj); + error reterr = cxx_mirror().setupCloning(robj); ASSERT_TRUE(reterr == error::None); // --- Step 2: Clone by default (entity::Auto semantics) --- @@ -354,7 +354,7 @@ namespace rtl::unit_test constexpr const int NUM = 241054; RObject robj = reflect(std::make_shared(NUM)); - error reterr = cxx_mirror().enableCloning(robj); + error reterr = cxx_mirror().setupCloning(robj); ASSERT_TRUE(reterr == error::None); ASSERT_FALSE(robj.isEmpty()); @@ -599,7 +599,7 @@ namespace rtl::unit_test constexpr const int NUM = 10742; RObject robj = reflect(std::make_shared(NUM)); - error reterr = cxx_mirror().enableCloning(robj); + error reterr = cxx_mirror().setupCloning(robj); ASSERT_TRUE(reterr == error::None); ASSERT_FALSE(robj.isEmpty()); diff --git a/ReflectionTemplateLib/access/inc/CxxMirror.h b/ReflectionTemplateLib/access/inc/CxxMirror.h index 63c3e180..82522e46 100644 --- a/ReflectionTemplateLib/access/inc/CxxMirror.h +++ b/ReflectionTemplateLib/access/inc/CxxMirror.h @@ -50,7 +50,7 @@ namespace rtl // Constructs CxxMirror using a set of Function objects. All other constructors are disabled. explicit CxxMirror(const std::vector& pFunctions); - error enableCloning(const RObject& pTarget) const; + error setupCloning(const RObject& pTarget) const; // Returns a Record containing function hash-keys for the given record ID. std::optional getRecord(const std::size_t pRecordId) const; diff --git a/ReflectionTemplateLib/access/inc/Method.h b/ReflectionTemplateLib/access/inc/Method.h index 3609d2b8..a57bcbf5 100644 --- a/ReflectionTemplateLib/access/inc/Method.h +++ b/ReflectionTemplateLib/access/inc/Method.h @@ -41,7 +41,7 @@ namespace rtl { //invokes the constructor associated with this 'Method' template - Return invokeCtor(alloc&& pAllocType, std::size_t&& pClonerIndex, _args&&...params) const; + Return invokeCtor(alloc pAllocType, std::size_t pClonerIndex, _args&&...params) const; public: diff --git a/ReflectionTemplateLib/access/inc/Method.hpp b/ReflectionTemplateLib/access/inc/Method.hpp index dd073743..eed7f822 100644 --- a/ReflectionTemplateLib/access/inc/Method.hpp +++ b/ReflectionTemplateLib/access/inc/Method.hpp @@ -34,11 +34,15 @@ namespace rtl @return: RStatus * calls the constructor with given arguments. */ template - inline Return Method::invokeCtor(alloc&& pAllocType, std::size_t&& pClonerIndex, _args&& ...params) const + inline Return Method::invokeCtor(alloc pAllocType, std::size_t pClonerIndex, _args&& ...params) const { - return Function::bind().call( std::forward(pAllocType), - std::forward(pClonerIndex), - std::forward<_args>(params)...); + using Container = detail::FunctorContainer...>; + + std::size_t index = hasSignatureId(Container::getContainerId()); + if (index != rtl::index_none) [[likely]] { + return Container::template forwardCall<_args...>(index, pAllocType, pClonerIndex, std::forward<_args>(params)...); + } + return { error::SignatureMismatch, RObject{} }; } diff --git a/ReflectionTemplateLib/access/inc/RObject.h b/ReflectionTemplateLib/access/inc/RObject.h index fd711e56..86ded7c0 100644 --- a/ReflectionTemplateLib/access/inc/RObject.h +++ b/ReflectionTemplateLib/access/inc/RObject.h @@ -71,6 +71,7 @@ namespace rtl GETTER_BOOL(OnHeap, (m_objectId.m_allocatedOn == alloc::Heap)) GETTER_BOOL(AllocatedByRtl, (m_objectId.m_allocatedOn == alloc::Heap)) GETTER(std::size_t, TypeId, m_objectId.m_typeId) + GETTER_CREF(std::optional, Any, m_object) /* Reflection Const Semantics: * - All reflected objects default to mutable internally; API enforces logical constness. diff --git a/ReflectionTemplateLib/access/inc/RObject.hpp b/ReflectionTemplateLib/access/inc/RObject.hpp index fc7d7595..792dfcfd 100644 --- a/ReflectionTemplateLib/access/inc/RObject.hpp +++ b/ReflectionTemplateLib/access/inc/RObject.hpp @@ -107,7 +107,7 @@ namespace rtl const std::any& viewObj = convert(m_object.value(), m_objectId.m_containsAs, newKind); const T* viewRef = detail::RObjExtractor::getPointer(viewObj, newKind); - if (viewRef != nullptr && newKind == detail::EntityKind::Ref) { + if (viewRef != nullptr && newKind == detail::EntityKind::Ptr) { return std::optional>(std::in_place, *viewRef); } else if (viewRef != nullptr && newKind == detail::EntityKind::Value) { diff --git a/ReflectionTemplateLib/access/inc/Record.h b/ReflectionTemplateLib/access/inc/Record.h index 4d70cb18..6a608de8 100644 --- a/ReflectionTemplateLib/access/inc/Record.h +++ b/ReflectionTemplateLib/access/inc/Record.h @@ -95,9 +95,7 @@ namespace rtl { static_assert(_alloc != rtl::alloc::None, "Instance cannot be created with 'rtl::alloc::None' option."); const auto& method = m_methods.at(detail::ctor_name(m_recordName)); std::size_t copyCtorIndex = method.getFunctorIds()[detail::Index::CopyCtor].getIndex(); - return method.invokeCtor( _alloc, - std::move(copyCtorIndex), - std::forward<_ctorArgs>(params)...); + return method.invokeCtor(_alloc, copyCtorIndex, std::forward<_ctorArgs>(params)...); } //only class which can create objects of this class & manipulates 'm_methods'. diff --git a/ReflectionTemplateLib/access/src/CxxMirror.cpp b/ReflectionTemplateLib/access/src/CxxMirror.cpp index 16c5f6e4..b0167bf2 100644 --- a/ReflectionTemplateLib/access/src/CxxMirror.cpp +++ b/ReflectionTemplateLib/access/src/CxxMirror.cpp @@ -15,7 +15,7 @@ namespace rtl { - namespace detail + namespace detail { std::size_t generate_unique_id() { @@ -25,14 +25,15 @@ namespace rtl } } - error CxxMirror::enableCloning(const RObject& pTarget) const + error CxxMirror::setupCloning(const RObject& pTarget) const { const auto& itr = getRecordIdMap().find(pTarget.getTypeId()); if (itr != getRecordIdMap().end()) { const Record& record = itr->second; Method ctors = record.getMethod(detail::ctor_name(record.getRecordName())).value(); - const_cast(pTarget).m_objectId.m_clonerIndex = ctors.getFunctors()[detail::Index::CopyCtor].getIndex(); + std::size_t copyCtorIndex = ctors.getFunctors()[detail::Index::CopyCtor].getIndex(); + const_cast(pTarget).m_objectId.m_clonerIndex = copyCtorIndex; return error::None; } return error::CloningDisabled; diff --git a/ReflectionTemplateLib/common/Constants.h b/ReflectionTemplateLib/common/Constants.h index e8ff6746..d595fdc0 100644 --- a/ReflectionTemplateLib/common/Constants.h +++ b/ReflectionTemplateLib/common/Constants.h @@ -105,7 +105,7 @@ namespace rtl::detail enum class EntityKind { None = 0, - Ref, + Ptr, Value, Wrapper }; diff --git a/ReflectionTemplateLib/detail/inc/MethodInvoker.hpp b/ReflectionTemplateLib/detail/inc/MethodInvoker.hpp index c3e8155a..fb06f8cd 100644 --- a/ReflectionTemplateLib/detail/inc/MethodInvoker.hpp +++ b/ReflectionTemplateLib/detail/inc/MethodInvoker.hpp @@ -67,7 +67,7 @@ namespace rtl::detail { return containerConst::template forwardCall<_args...>(pTarget, constMethodIndex, std::forward<_args>(params)...); } - else + else [[unlikely]] { using containerNonConst = detail::MethodContainer; std::size_t nonConstMethodIndex = pMethod.hasSignatureId(containerNonConst::getContainerId()); diff --git a/ReflectionTemplateLib/detail/inc/RObjExtracter.h b/ReflectionTemplateLib/detail/inc/RObjExtracter.h index 0a959376..8f1c11ef 100644 --- a/ReflectionTemplateLib/detail/inc/RObjExtracter.h +++ b/ReflectionTemplateLib/detail/inc/RObjExtracter.h @@ -26,12 +26,11 @@ namespace rtl::detail { switch (pEntityKind) { - case EntityKind::Ref: { - return std::any_cast(pObject); + case EntityKind::Ptr: { + return *(std::any_cast(&pObject)); } case EntityKind::Value: { - const T& valueRef = std::any_cast(pObject); - return static_cast(&valueRef); + return std::any_cast(&pObject); } default: return nullptr; } @@ -44,15 +43,14 @@ namespace rtl::detail { switch (m_rObj->m_objectId.m_containsAs) { - case EntityKind::Ref: { - return std::any_cast(m_rObj->m_object.value()); + case EntityKind::Ptr: { + return *(std::any_cast(&(m_rObj->m_object.value()))); } case EntityKind::Wrapper: { return getFromWrapper(); } case EntityKind::Value: { - const T& valueRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(&valueRef); + return std::any_cast(&(m_rObj->m_object.value())); } default: return nullptr; } @@ -71,15 +69,13 @@ namespace rtl::detail if (m_rObj->m_objectId.m_isWrappingConst) { using U = detail::RObjectUPtr; - const U& uptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(&uptrRef); + return std::any_cast(&(m_rObj->m_object.value())); } } else { using U = detail::RObjectUPtr<_T>; - const U& uptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(&uptrRef); + return std::any_cast(&(m_rObj->m_object.value())); } } return nullptr; @@ -96,15 +92,13 @@ namespace rtl::detail { if (m_rObj->m_objectId.m_isWrappingConst) { using U = std::shared_ptr; - const U& sptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(&sptrRef); + return std::any_cast(&(m_rObj->m_object.value())); } } else { using U = std::shared_ptr<_T>; - const U& sptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(&sptrRef); + return std::any_cast(&(m_rObj->m_object.value())); } } return nullptr; @@ -120,26 +114,34 @@ namespace rtl::detail { if (m_rObj->m_objectId.m_isWrappingConst) { using U = detail::RObjectUPtr; - const U& uptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(uptrRef.get()); + const U* uptr = std::any_cast(&(m_rObj->m_object.value())); + if (uptr != nullptr) { + return uptr->get(); + } } else { using U = detail::RObjectUPtr; - const U& uptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(uptrRef.get()); + const U* uptr = std::any_cast(&(m_rObj->m_object.value())); + if (uptr != nullptr) { + return uptr->get(); + } } } if (m_rObj->m_objectId.m_wrapperType == detail::Wrapper::Shared) { if (m_rObj->m_objectId.m_isWrappingConst) { using U = std::shared_ptr; - const auto& sptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(sptrRef.get()); + const U* sptr = std::any_cast(&(m_rObj->m_object.value())); + if (sptr != nullptr) { + return sptr->get(); + } } else { using U = std::shared_ptr; - const auto& sptrRef = std::any_cast(m_rObj->m_object.value()); - return static_cast(sptrRef.get()); + const U* sptr = std::any_cast(&(m_rObj->m_object.value())); + if (sptr != nullptr) { + return sptr->get(); + } } } } diff --git a/ReflectionTemplateLib/detail/inc/RObjectId.h b/ReflectionTemplateLib/detail/inc/RObjectId.h index a8a65978..5455ca9f 100644 --- a/ReflectionTemplateLib/detail/inc/RObjectId.h +++ b/ReflectionTemplateLib/detail/inc/RObjectId.h @@ -49,7 +49,7 @@ namespace rtl::detail return EntityKind::Wrapper; } else if constexpr (isRawPtr && !isWrapper) { - return EntityKind::Ref; + return EntityKind::Ptr; } else if constexpr (!isWrapper && !isRawPtr) { return EntityKind::Value; diff --git a/ReflectionTemplateLib/detail/inc/ReflectCast.hpp b/ReflectionTemplateLib/detail/inc/ReflectCast.hpp index a7dcc7f4..85b405aa 100644 --- a/ReflectionTemplateLib/detail/inc/ReflectCast.hpp +++ b/ReflectionTemplateLib/detail/inc/ReflectCast.hpp @@ -27,7 +27,7 @@ namespace rtl::detail { try { - bool isPointer = (pSrcEntityKind == EntityKind::Ref); + bool isPointer = (pSrcEntityKind == EntityKind::Ptr); const _fromType& srcRef = (isPointer ? *(std::any_cast(pSrc)) : std::any_cast(pSrc)); if constexpr (std::is_convertible_v<_fromType*, _toType*>) diff --git a/ReflectionTemplateLib/detail/inc/SetupFunction.hpp b/ReflectionTemplateLib/detail/inc/SetupFunction.hpp index c044e666..07b9931d 100644 --- a/ReflectionTemplateLib/detail/inc/SetupFunction.hpp +++ b/ReflectionTemplateLib/detail/inc/SetupFunction.hpp @@ -23,7 +23,7 @@ namespace rtl inline SetupFunction<_derivedType>::FunctionLambda<_signature...> SetupFunction<_derivedType>::getCaller(void(*pFunctor)(_signature...)) { - return [=](_signature&&... params) -> Return + return [pFunctor](_signature&&... params) -> Return { pFunctor(std::forward<_signature>(params)...); return { error::None, RObject{} }; @@ -38,7 +38,7 @@ namespace rtl { /* a variable arguments lambda, which finally calls the 'pFunctor' with 'params...'. this is stored in _derivedType's (FunctorContainer) vector holding lambda's. - */ return [=](_signature&&...params)-> Return + */ return [pFunctor](_signature&&...params)-> Return { constexpr bool isConstCastSafe = (!traits::is_const_v<_returnType>); diff --git a/ReflectionTemplateLib/detail/inc/SetupMethod.h b/ReflectionTemplateLib/detail/inc/SetupMethod.h index 2aea8dfe..ee521194 100644 --- a/ReflectionTemplateLib/detail/inc/SetupMethod.h +++ b/ReflectionTemplateLib/detail/inc/SetupMethod.h @@ -42,11 +42,11 @@ namespace rtl { template static MethodLambda<_signature...> getMethodCaller(_returnType(_recordType::* pFunctor)(_signature...) const); - template - static MethodLambda<_signature...> getVoidMethodCaller(_returnType(_recordType::* pFunctor)(_signature...)); + template + static MethodLambda<_signature...> getMethodCaller(void(_recordType::* pFunctor)(_signature...)); - template - static MethodLambda<_signature...> getVoidMethodCaller(_returnType(_recordType::* pFunctor)(_signature...) const); + template + static MethodLambda<_signature...> getMethodCaller(void(_recordType::* pFunctor)(_signature...) const); protected: diff --git a/ReflectionTemplateLib/detail/inc/SetupMethod.hpp b/ReflectionTemplateLib/detail/inc/SetupMethod.hpp index 24216920..78979dae 100644 --- a/ReflectionTemplateLib/detail/inc/SetupMethod.hpp +++ b/ReflectionTemplateLib/detail/inc/SetupMethod.hpp @@ -22,13 +22,13 @@ namespace rtl { template - template + template inline SetupMethod<_derivedType>::MethodLambda<_signature...> - SetupMethod<_derivedType>::getVoidMethodCaller(_returnType(_recordType::* pFunctor)(_signature...)) + SetupMethod<_derivedType>::getMethodCaller(void(_recordType::* pFunctor)(_signature...)) { /* a variable arguments lambda, which finally calls the 'pFunctor' with 'params...'. this is stored in _derivedType's (MethodContainer) vector holding lambda's. - */ return [=](const RObject& pTargetObj, _signature&&...params)-> Return + */ return [pFunctor](const RObject& pTargetObj, _signature&&...params)-> Return { if (!pTargetObj.isConstCastSafe()) [[unlikely]] { return { error::IllegalConstCast, RObject{} }; @@ -48,7 +48,7 @@ namespace rtl { /* a variable arguments lambda, which finally calls the 'pFunctor' with 'params...'. this is stored in _derivedType's (MethodContainer) vector holding lambda's. - */ return [=](const RObject& pTargetObj, _signature&&...params)-> Return + */ return [pFunctor](const RObject& pTargetObj, _signature&&...params)-> Return { if (!pTargetObj.isConstCastSafe()) [[unlikely]] { return { error::IllegalConstCast, RObject{} }; @@ -84,13 +84,13 @@ namespace rtl template - template + template inline SetupMethod<_derivedType>::MethodLambda<_signature...> - SetupMethod<_derivedType>::getVoidMethodCaller(_returnType(_recordType::* pFunctor)(_signature...) const) + SetupMethod<_derivedType>::getMethodCaller(void(_recordType::* pFunctor)(_signature...) const) { /* a variable arguments lambda, which finally calls the 'pFunctor' with 'params...'. this is stored in _derivedType's (MethodContainer) vector holding lambda's. - */ return [=](const RObject& pTargetObj, _signature&&...params)-> Return + */ return [pFunctor](const RObject& pTargetObj, _signature&&...params)-> Return { const _recordType& target = pTargetObj.view<_recordType>()->get(); (target.*pFunctor)(std::forward<_signature>(params)...); @@ -106,7 +106,7 @@ namespace rtl { /* a variable arguments lambda, which finally calls the 'pFunctor' with 'params...'. this is stored in _derivedType's (MethodContainer) vector holding lambda's. - */ return [=](const RObject& pTargetObj, _signature&&...params)-> Return + */ return [pFunctor](const RObject& pTargetObj, _signature&&...params)-> Return { constexpr bool isConstCastSafe = (!traits::is_const_v<_returnType>); //'target' is const and 'pFunctor' is const-member-function. @@ -179,7 +179,7 @@ namespace rtl if constexpr (std::is_same_v<_returnType, void>) { - const std::size_t index = _derivedType::pushBack(getVoidMethodCaller(pFunctor), getIndex, updateIndex); + const std::size_t index = _derivedType::pushBack(getMethodCaller(pFunctor), getIndex, updateIndex); //construct the hash-key 'FunctorId' and return. return detail::FunctorId{ index, retTypeId, TypeId<_recordType>::get(), _derivedType::getContainerId(), @@ -239,7 +239,7 @@ namespace rtl if constexpr (std::is_same_v<_returnType, void>) { - const std::size_t index = _derivedType::pushBack(getVoidMethodCaller(pFunctor), getIndex, updateIndex); + const std::size_t index = _derivedType::pushBack(getMethodCaller(pFunctor), getIndex, updateIndex); //construct the hash-key 'FunctorId' and return. return detail::FunctorId { index, retTypeId, TypeId<_recordType>::get(), _derivedType::getContainerId(), diff --git a/ReflectionTemplateLib/detail/src/RObjectConverters_string.cpp b/ReflectionTemplateLib/detail/src/RObjectConverters_string.cpp index 37d25978..8e8363a3 100644 --- a/ReflectionTemplateLib/detail/src/RObjectConverters_string.cpp +++ b/ReflectionTemplateLib/detail/src/RObjectConverters_string.cpp @@ -22,8 +22,8 @@ namespace rtl::detail { const auto& conversion = [](const std::any& pSrc, const EntityKind& pSrcEntityKind, EntityKind& pNewEntityKind)-> std::any { - pNewEntityKind = EntityKind::Ref; - const auto& isPtr = (pSrcEntityKind == EntityKind::Ref); + pNewEntityKind = EntityKind::Ptr; + const auto& isPtr = (pSrcEntityKind == EntityKind::Ptr); const auto& srcObj = (isPtr ? *std::any_cast(pSrc) : std::any_cast(pSrc)); return std::any(srcObj.c_str()); }; @@ -37,8 +37,8 @@ namespace rtl::detail { const auto& conversion = [](const std::any& pSrc, const EntityKind& pSrcEntityKind, EntityKind& pNewEntityKind)-> std::any { - pNewEntityKind = EntityKind::Ref; - const auto& isPtr = (pSrcEntityKind == EntityKind::Ref); + pNewEntityKind = EntityKind::Ptr; + const auto& isPtr = (pSrcEntityKind == EntityKind::Ptr); const auto& srcObj = (isPtr ? *std::any_cast(pSrc) : std::any_cast(pSrc)); return std::any(srcObj.data()); }; @@ -54,7 +54,7 @@ namespace rtl::detail const auto& conversion = [](const std::any& pSrc, const EntityKind& pSrcEntityKind, EntityKind& pNewEntityKind)-> std::any { pNewEntityKind = EntityKind::Value; - const auto& isPtr = (pSrcEntityKind == EntityKind::Ref); + const auto& isPtr = (pSrcEntityKind == EntityKind::Ptr); const auto& srcObj = (isPtr ? *std::any_cast(pSrc) : std::any_cast(pSrc)); return std::any(_toType(srcObj)); }; diff --git a/Design-Docs/DESIGN_PRINCIPLES_AND_FEATURES.md b/text-design-docs/DESIGN_PRINCIPLES_AND_FEATURES.md similarity index 100% rename from Design-Docs/DESIGN_PRINCIPLES_AND_FEATURES.md rename to text-design-docs/DESIGN_PRINCIPLES_AND_FEATURES.md diff --git a/Design-Docs/RTL_SYNTAX_AND_SEMANTICS.md b/text-design-docs/RTL_SYNTAX_AND_SEMANTICS.md similarity index 100% rename from Design-Docs/RTL_SYNTAX_AND_SEMANTICS.md rename to text-design-docs/RTL_SYNTAX_AND_SEMANTICS.md diff --git a/Design-Docs/WHY_CPP_REFLECTION_MATTERS.md b/text-design-docs/WHY_CPP_REFLECTION_MATTERS.md similarity index 100% rename from Design-Docs/WHY_CPP_REFLECTION_MATTERS.md rename to text-design-docs/WHY_CPP_REFLECTION_MATTERS.md