diff --git a/PolyEngine/CMakeListsCommon.cmake b/PolyEngine/CMakeListsCommon.cmake index 5bbb5e0b..eacf2855 100644 --- a/PolyEngine/CMakeListsCommon.cmake +++ b/PolyEngine/CMakeListsCommon.cmake @@ -179,7 +179,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(Clang|^GNU$)") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess") endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument -Wno-missing-braces") endif() # Shared compile flags @@ -362,4 +362,4 @@ add_subdirectory(${ENGINE_ROOT_DIR}/API ${COMMON_BUILD_DIR}/API) add_subdirectory(${ENGINE_ROOT_DIR}/Engine ${COMMON_BUILD_DIR}/Engine) add_subdirectory(${ENGINE_ROOT_DIR}/RenderingDevice/OpenGL ${COMMON_BUILD_DIR}/RenderingDevice/OpenGL) add_subdirectory(${ENGINE_ROOT_DIR}/Editor ${COMMON_BUILD_DIR}/Editor) -add_subdirectory(${ENGINE_ROOT_DIR}/Standalone ${COMMON_BUILD_DIR}/Standalone) \ No newline at end of file +add_subdirectory(${ENGINE_ROOT_DIR}/Standalone ${COMMON_BUILD_DIR}/Standalone) diff --git a/PolyEngine/Core/Src/pe/core/rtti/RTTI2.cpp b/PolyEngine/Core/Src/pe/core/rtti/RTTI2.cpp index adb0ea95..0686e01a 100644 --- a/PolyEngine/Core/Src/pe/core/rtti/RTTI2.cpp +++ b/PolyEngine/Core/Src/pe/core/rtti/RTTI2.cpp @@ -4,10 +4,10 @@ namespace pe::core::rtti { namespace RTTI2 { - TypeManager& get() + TypeManager& TypeManager::get() { static TypeManager instance{}; return instance; } } -} \ No newline at end of file +} diff --git a/PolyEngine/Core/Src/pe/core/rtti/RTTI2.hpp b/PolyEngine/Core/Src/pe/core/rtti/RTTI2.hpp index 0e4c590a..8f608bd9 100644 --- a/PolyEngine/Core/Src/pe/core/rtti/RTTI2.hpp +++ b/PolyEngine/Core/Src/pe/core/rtti/RTTI2.hpp @@ -17,19 +17,19 @@ namespace pe::core::rtti namespace impl { + template + void runListImpl(F f, X x) { f(x); } + template - void runList(F f, X x, XS... xs) + void runListImpl(F f, X x, XS... xs) { f(x); - runList(f, xs...); + runListImpl(f, xs...); } - - template - void runList(F f, X x) { f(x); } } constexpr auto runList = [](auto list, auto f) { - list([f](auto... xs){ impl::runList(f, xs...); }); + list([f](auto... xs){ impl::runListImpl(f, xs...); }); }; namespace RTTI2 diff --git a/PolyEngine/Tests/CoreTests/Src/RTTI2Test.cpp b/PolyEngine/Tests/CoreTests/Src/RTTI2Test.cpp new file mode 100644 index 00000000..e7ee9277 --- /dev/null +++ b/PolyEngine/Tests/CoreTests/Src/RTTI2Test.cpp @@ -0,0 +1,76 @@ +//#include +#include +#include + +namespace rtti2 = pe::core::rtti::RTTI2; + +struct TestAttr {} constexpr testAttr; + +struct TestClass : public virtual rtti2::RTTIBase { + TestClass() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType()) {} +}; +template <> struct rtti2::RTTIinfo { + constexpr static auto info = List(testAttr, testAttr, rtti2::ClassName{ "testname" }); +}; + +TEST_CASE("rtti2 simple attribute", "[rtti2]") { + TestClass tc{}; + CHECK(tc.typeInfo().id != std::type_index{ typeid(void) }); + auto ta = tc.typeInfo().get(); + CHECK(ta); + CHECK(ta->size() == 2); + CHECK(tc.typeInfo().get() == nullptr); + auto x = tc.typeInfo().get(); + CHECK(x); + CHECK(std::string("testname") == x->name); +} + +struct TestAttrUniq {} constexpr testAttrUniq; +template <> struct rtti2::AttrType { + using type = rtti2::UniqueAttribute; +}; +struct TestClass2 : public virtual rtti2::RTTIBase { + TestClass2() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType()) {} +}; +template <> struct rtti2::RTTIinfo { + constexpr static auto info = List(testAttrUniq, testAttrUniq); +}; + +TEST_CASE("rtti2 uniq attribute", "[rtti2]") +{ + REQUIRE_THROWS(TestClass2{}); +} + +struct TestAttrBase { const char* foo; }; +template <> struct rtti2::AttrType { + using type = rtti2::DerivedAttribute; +}; +struct TestAttrDerived : TestAttrBase {}; +template <> struct rtti2::AttrType { + using type = rtti2::DerivedAttribute; +}; + +struct TestClassA : public virtual rtti2::RTTIBase { + TestClassA() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType()) {} +}; +template <> struct rtti2::RTTIinfo { + constexpr static auto info = List(TestAttrDerived{ {"foo"} }); +}; + +struct TestClassB : public virtual rtti2::RTTIBase, public TestClassA { + TestClassB() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType()) {} +}; +template <> struct rtti2::RTTIinfo { + constexpr static auto info = List(rtti2::baseclass{}); +}; + +TEST_CASE("rtti2 derived", "[rtti2]") { + TestClassA tca{}; + auto attr = tca.typeInfo().get(); + CHECK(attr); + CHECK(std::string("foo") == attr->at(0)->foo); + TestClassB tcb{}; + CHECK(tcb.typeInfo().bases[0].get().id == tca.typeInfo().id); + CHECK(rtti2::isSame(tca.typeInfo())); + CHECK(rtti2::isDerived(tcb.typeInfo())); +} diff --git a/PolyEngine/Tests/CoreTests/Src/RTTITests.cpp b/PolyEngine/Tests/CoreTests/Src/RTTITests.cpp index dee18851..7a161635 100644 --- a/PolyEngine/Tests/CoreTests/Src/RTTITests.cpp +++ b/PolyEngine/Tests/CoreTests/Src/RTTITests.cpp @@ -4,7 +4,7 @@ #include using namespace Poly; - +/* enum class eRTTITestEnum { VAL_1, @@ -80,4 +80,4 @@ TEST_CASE("RTTI property", "[RTTI]") { CHECK(properties[2].Type == RTTI::TypeInfo::INVALID); CHECK(properties[2].Name == "Val2"); CHECK((char*)b + properties[2].Offset == (char*)&(a->val2)); -} +} */ diff --git a/PolyEngine/UnitTests/Src/RTTI2Test.cpp b/PolyEngine/UnitTests/Src/RTTI2Test.cpp deleted file mode 100644 index 7965ef97..00000000 --- a/PolyEngine/UnitTests/Src/RTTI2Test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -//#include -#include -#include - -using namespace pe::core::rtti; - -struct TestAttr {} constexpr testAttr; - -struct TestClass : public virtual RTTI2::RTTIBase { - TestClass() : RTTI2::RTTIBase(RTTI2::TypeManager::get().registerOrGetType()) {} -}; -template <> struct RTTI2::RTTIinfo { - constexpr static auto info = List(testAttr, testAttr, RTTI2::classname{ "testname" }); -}; - -TEST_CASE("RTTI2 simple attribute", "[RTTI2]") { - TestClass tc{}; - CHECK(tc.typeInfo().id != std::type_index{ typeid(void) }); - auto ta = tc.typeInfo().get(); - CHECK(ta); - CHECK(ta->size() == 2); - CHECK(tc.typeInfo().get() == nullptr); - auto x = tc.typeInfo().get(); - CHECK(x); - CHECK(std::string("testname") == x->name); -} - -struct TestAttrUniq {} constexpr testAttrUniq; -template <> struct RTTI2::AttrType { - using type = RTTI2::UniqueAttribute; -}; -struct TestClass2 : public virtual RTTI2::RTTIBase { - TestClass2() : RTTI2::RTTIBase(RTTI2::TypeManager::get().registerOrGetType()) {} -}; -template <> struct RTTI2::RTTIinfo { - constexpr static auto info = List(testAttrUniq, testAttrUniq); -}; - -TEST_CASE("RTTI2 uniq attribute", "[RTTI2]") -{ - REQUIRE_THROWS(TestClass2{}); -} - -struct TestAttrBase { const char* foo; }; -template <> struct RTTI2::AttrType { - using type = RTTI2::DerivedAttribute; -}; -struct TestAttrDerived : TestAttrBase {}; -template <> struct RTTI2::AttrType { - using type = RTTI2::DerivedAttribute; -}; - -struct TestClassA : public virtual RTTI2::RTTIBase { - TestClassA() : RTTI2::RTTIBase(RTTI2::TypeManager::get().registerOrGetType()) {} -}; -template <> struct RTTI2::RTTIinfo { - constexpr static auto info = List(TestAttrDerived{ "foo" }); -}; - -struct TestClassB : public virtual RTTI2::RTTIBase, public TestClassA { - TestClassB() : RTTI2::RTTIBase(RTTI2::TypeManager::get().registerOrGetType()) {} -}; -template <> struct RTTI2::RTTIinfo { - constexpr static auto info = List(RTTI2::baseclass{}); -}; - -TEST_CASE("RTTI2 derived", "[RTTI2]") { - TestClassA tca{}; - auto attr = tca.typeInfo().get(); - CHECK(attr); - CHECK(std::string("foo") == attr->at(0)->foo); - TestClassB tcb{}; - CHECK(tcb.typeInfo().bases[0].get().id == tca.typeInfo().id); - CHECK(RTTI2::isSame(tca.typeInfo())); - CHECK(RTTI2::isDerived(tcb.typeInfo())); -} \ No newline at end of file