From 8ffacb16b1f478681f5c77d805df6f386d67837b Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 25 Feb 2016 12:08:02 +0900 Subject: [PATCH] Basic meta stuff working --- src/CMakeLists.txt | 25 +++++++++++++++++++------ src/EC/Meta.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/test/Main.cpp | 8 ++++++++ src/test/MetaTest.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 src/EC/Meta.hpp create mode 100644 src/test/Main.cpp create mode 100644 src/test/MetaTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe14084..8b8ca51 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,11 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.0) project(EntityComponentSystem) -set(EntityComponentSystem_SOURCES - ) +set(EntityComponentSystem_HEADERS + EC/Meta.hpp) -add_library(EntityComponentSystem - ${EntityComponentSystem_SOURCES}) +add_library(EntityComponentSystem INTERFACE) +target_include_directories(EntityComponentSystem INTERFACE ${CMAKE_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}) @@ -34,6 +34,19 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() -install(TARGETS EntityComponentSystem DESTINATION lib) +install(FILES ${EntityComponentSystem_HEADERS} DESTINATION include/EC) +find_package(GTest) +if(GTEST_FOUND) + set(UnitTests_SOURCES + test/MetaTest.cpp + test/Main.cpp) + + add_executable(UnitTests ${UnitTests_SOURCES}) + target_link_libraries(UnitTests EntityComponentSystem ${GTEST_LIBRARIES}) + + enable_testing() + add_test(NAME UnitTests COMMAND UnitTests) +endif() + diff --git a/src/EC/Meta.hpp b/src/EC/Meta.hpp new file mode 100644 index 0000000..e314acf --- /dev/null +++ b/src/EC/Meta.hpp @@ -0,0 +1,40 @@ + +#ifndef EC_META_HPP +#define EC_META_HPP + +#include + +namespace EC +{ + namespace Meta + { + template + struct TypeList + { + static constexpr std::size_t size{sizeof...(Types)}; + + }; + + template + struct ContainsHelper : + std::false_type + { + }; + + template + struct ContainsHelper > : + std::conditional< + std::is_same::value, + std::true_type, + ContainsHelper > + >::type + { + }; + + template + using Contains = std::integral_constant::value >; + } +} + +#endif + diff --git a/src/test/Main.cpp b/src/test/Main.cpp new file mode 100644 index 0000000..73f36b4 --- /dev/null +++ b/src/test/Main.cpp @@ -0,0 +1,8 @@ + +#include + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/test/MetaTest.cpp b/src/test/MetaTest.cpp new file mode 100644 index 0000000..e8f64ef --- /dev/null +++ b/src/test/MetaTest.cpp @@ -0,0 +1,39 @@ + +#include + +#include + +TEST(Meta, Contains) +{ + struct C0 {}; + struct C1 {}; + struct C2 {}; + struct C3 {}; + + using listAll = EC::Meta::TypeList; + + int size = listAll::size; + EXPECT_EQ(size, 4); + + bool result = EC::Meta::Contains::value; + EXPECT_TRUE(result); + result = EC::Meta::Contains::value; + EXPECT_TRUE(result); + result = EC::Meta::Contains::value; + EXPECT_TRUE(result); + result = EC::Meta::Contains::value; + EXPECT_TRUE(result); + + using listSome = EC::Meta::TypeList; + size = listSome::size; + EXPECT_EQ(size, 2); + + result = EC::Meta::Contains::value; + EXPECT_FALSE(result); + result = EC::Meta::Contains::value; + EXPECT_TRUE(result); + result = EC::Meta::Contains::value; + EXPECT_FALSE(result); + result = EC::Meta::Contains::value; + EXPECT_TRUE(result); +}