-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})
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()
+
--- /dev/null
+
+#ifndef EC_META_HPP
+#define EC_META_HPP
+
+#include <type_traits>
+
+namespace EC
+{
+ namespace Meta
+ {
+ template <typename... Types>
+ struct TypeList
+ {
+ static constexpr std::size_t size{sizeof...(Types)};
+
+ };
+
+ template <typename T, typename... Types>
+ struct ContainsHelper :
+ std::false_type
+ {
+ };
+
+ template <typename T, typename Type, typename... Types>
+ struct ContainsHelper<T, TypeList<Type, Types...> > :
+ std::conditional<
+ std::is_same<T, Type>::value,
+ std::true_type,
+ ContainsHelper<T, TypeList<Types...> >
+ >::type
+ {
+ };
+
+ template <typename T, typename TTypeList>
+ using Contains = std::integral_constant<bool, ContainsHelper<T, TTypeList>::value >;
+ }
+}
+
+#endif
+
--- /dev/null
+
+#include <gtest/gtest.h>
+
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+
+#include <gtest/gtest.h>
+
+#include <EC/Meta.hpp>
+
+TEST(Meta, Contains)
+{
+ struct C0 {};
+ struct C1 {};
+ struct C2 {};
+ struct C3 {};
+
+ using listAll = EC::Meta::TypeList<C0, C1, C2, C3>;
+
+ int size = listAll::size;
+ EXPECT_EQ(size, 4);
+
+ bool result = EC::Meta::Contains<C0, listAll>::value;
+ EXPECT_TRUE(result);
+ result = EC::Meta::Contains<C1, listAll>::value;
+ EXPECT_TRUE(result);
+ result = EC::Meta::Contains<C2, listAll>::value;
+ EXPECT_TRUE(result);
+ result = EC::Meta::Contains<C3, listAll>::value;
+ EXPECT_TRUE(result);
+
+ using listSome = EC::Meta::TypeList<C1, C3>;
+ size = listSome::size;
+ EXPECT_EQ(size, 2);
+
+ result = EC::Meta::Contains<C0, listSome>::value;
+ EXPECT_FALSE(result);
+ result = EC::Meta::Contains<C1, listSome>::value;
+ EXPECT_TRUE(result);
+ result = EC::Meta::Contains<C2, listSome>::value;
+ EXPECT_FALSE(result);
+ result = EC::Meta::Contains<C3, listSome>::value;
+ EXPECT_TRUE(result);
+}