]> git.seodisparate.com - EntityComponentMetaSystem/commitdiff
Basic meta stuff working
authorStephen Seo <seo.disparate@gmail.com>
Thu, 25 Feb 2016 03:08:02 +0000 (12:08 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 25 Feb 2016 03:08:02 +0000 (12:08 +0900)
src/CMakeLists.txt
src/EC/Meta.hpp [new file with mode: 0644]
src/test/Main.cpp [new file with mode: 0644]
src/test/MetaTest.cpp [new file with mode: 0644]

index fe1408491e268c0a55b727ee4aa05d016a82d0b2..8b8ca510df2b36ddc7190a48eba1e826585a62ca 100644 (file)
@@ -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 (file)
index 0000000..e314acf
--- /dev/null
@@ -0,0 +1,40 @@
+
+#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
+
diff --git a/src/test/Main.cpp b/src/test/Main.cpp
new file mode 100644 (file)
index 0000000..73f36b4
--- /dev/null
@@ -0,0 +1,8 @@
+
+#include <gtest/gtest.h>
+
+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 (file)
index 0000000..e8f64ef
--- /dev/null
@@ -0,0 +1,39 @@
+
+#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);
+}