Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PolyEngine/CMakeListsCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
add_subdirectory(${ENGINE_ROOT_DIR}/Standalone ${COMMON_BUILD_DIR}/Standalone)
4 changes: 2 additions & 2 deletions PolyEngine/Core/Src/pe/core/rtti/RTTI2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace pe::core::rtti
{
namespace RTTI2
{
TypeManager& get()
TypeManager& TypeManager::get()
{
static TypeManager instance{};
return instance;
}
}
}
}
12 changes: 6 additions & 6 deletions PolyEngine/Core/Src/pe/core/rtti/RTTI2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ namespace pe::core::rtti

namespace impl
{
template <typename F, typename X>
void runListImpl(F f, X x) { f(x); }

template <typename F, typename X, typename ... XS>
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 <typename F, typename X>
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
Expand Down
76 changes: 76 additions & 0 deletions PolyEngine/Tests/CoreTests/Src/RTTI2Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//#include <pe/Defines.hpp>
#include <catch.hpp>
#include <pe/core/rtti/RTTI2.hpp>

namespace rtti2 = pe::core::rtti::RTTI2;

struct TestAttr {} constexpr testAttr;

struct TestClass : public virtual rtti2::RTTIBase {
TestClass() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType<TestClass>()) {}
};
template <> struct rtti2::RTTIinfo<TestClass> {
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<TestAttr>();
CHECK(ta);
CHECK(ta->size() == 2);
CHECK(tc.typeInfo().get<int>() == nullptr);
auto x = tc.typeInfo().get<rtti2::ClassName>();
CHECK(x);
CHECK(std::string("testname") == x->name);
}

struct TestAttrUniq {} constexpr testAttrUniq;
template <> struct rtti2::AttrType<TestAttrUniq> {
using type = rtti2::UniqueAttribute<TestAttrUniq>;
};
struct TestClass2 : public virtual rtti2::RTTIBase {
TestClass2() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType<TestClass2>()) {}
};
template <> struct rtti2::RTTIinfo<TestClass2> {
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<TestAttrBase> {
using type = rtti2::DerivedAttribute<TestAttrBase>;
};
struct TestAttrDerived : TestAttrBase {};
template <> struct rtti2::AttrType<TestAttrDerived> {
using type = rtti2::DerivedAttribute<TestAttrBase>;
};

struct TestClassA : public virtual rtti2::RTTIBase {
TestClassA() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType<TestClassA>()) {}
};
template <> struct rtti2::RTTIinfo<TestClassA> {
constexpr static auto info = List(TestAttrDerived{ {"foo"} });
};

struct TestClassB : public virtual rtti2::RTTIBase, public TestClassA {
TestClassB() : rtti2::RTTIBase(rtti2::TypeManager::get().registerOrGetType<TestClassB>()) {}
};
template <> struct rtti2::RTTIinfo<TestClassB> {
constexpr static auto info = List(rtti2::baseclass<TestClassA>{});
};

TEST_CASE("rtti2 derived", "[rtti2]") {
TestClassA tca{};
auto attr = tca.typeInfo().get<TestAttrBase>();
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<TestClassA>(tca.typeInfo()));
CHECK(rtti2::isDerived<TestClassA>(tcb.typeInfo()));
}
4 changes: 2 additions & 2 deletions PolyEngine/Tests/CoreTests/Src/RTTITests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <pe/core/rtti/RTTI.hpp>

using namespace Poly;

/*
enum class eRTTITestEnum
{
VAL_1,
Expand Down Expand Up @@ -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));
}
} */
76 changes: 0 additions & 76 deletions PolyEngine/UnitTests/Src/RTTI2Test.cpp

This file was deleted.