From a503eb628db80a9904da435527026191ff7e57a0 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 4 Mar 2016 21:35:26 +0900 Subject: [PATCH] Added EC/Meta/Combine.hpp Also some renaming in MetaTest.hpp --- src/EC/Meta/Combine.hpp | 29 ++++++++++++++ src/EC/Meta/Meta.hpp | 1 + src/test/MetaTest.cpp | 87 +++++++++++++++++++++++++++++------------ 3 files changed, 91 insertions(+), 26 deletions(-) create mode 100644 src/EC/Meta/Combine.hpp diff --git a/src/EC/Meta/Combine.hpp b/src/EC/Meta/Combine.hpp new file mode 100644 index 0000000..59e0e9a --- /dev/null +++ b/src/EC/Meta/Combine.hpp @@ -0,0 +1,29 @@ + +#ifndef EC_META_COMBINE_HPP +#define EC_META_COMBINE_HPP + +#include "TypeList.hpp" + +namespace EC +{ + namespace Meta + { + template + struct CombineHelper + { + using type = TypeList<>; + }; + + template + struct CombineHelper, TypeList > + { + using type = TypeList; + }; + + template + using Combine = typename CombineHelper::type; + } +} + +#endif + diff --git a/src/EC/Meta/Meta.hpp b/src/EC/Meta/Meta.hpp index c157869..1bb976d 100644 --- a/src/EC/Meta/Meta.hpp +++ b/src/EC/Meta/Meta.hpp @@ -1,5 +1,6 @@ #include "TypeList.hpp" +#include "Combine.hpp" #include "Contains.hpp" #include "ContainsAll.hpp" #include "IndexOf.hpp" diff --git a/src/test/MetaTest.cpp b/src/test/MetaTest.cpp index 4a78de8..84771c1 100644 --- a/src/test/MetaTest.cpp +++ b/src/test/MetaTest.cpp @@ -12,81 +12,116 @@ struct C3 {}; struct T0 {}; struct T1 {}; -using listAll = EC::Meta::TypeList; -using listSome = EC::Meta::TypeList; +using ListComponentsAll = EC::Meta::TypeList; +using ListComponentsSome = EC::Meta::TypeList; -using listTagsAll = EC::Meta::TypeList; +using ListTagsAll = EC::Meta::TypeList; + +using ListAll = EC::Meta::TypeList; TEST(Meta, Contains) { - int size = listAll::size; + int size = ListComponentsAll::size; EXPECT_EQ(size, 4); - bool result = EC::Meta::Contains::value; + bool result = EC::Meta::Contains::value; EXPECT_TRUE(result); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_TRUE(result); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_TRUE(result); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_TRUE(result); - size = listSome::size; + size = ListComponentsSome::size; EXPECT_EQ(size, 2); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_FALSE(result); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_TRUE(result); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_FALSE(result); - result = EC::Meta::Contains::value; + result = EC::Meta::Contains::value; EXPECT_TRUE(result); } TEST(Meta, ContainsAll) { - bool contains = EC::Meta::ContainsAll::value; + bool contains = EC::Meta::ContainsAll::value; EXPECT_TRUE(contains); - contains = EC::Meta::ContainsAll::value; + contains = EC::Meta::ContainsAll::value; EXPECT_FALSE(contains); - contains = EC::Meta::ContainsAll::value; + contains = EC::Meta::ContainsAll::value; EXPECT_TRUE(contains); } TEST(Meta, IndexOf) { - int index = EC::Meta::IndexOf::value; + int index = EC::Meta::IndexOf::value; EXPECT_EQ(index, 0); - index = EC::Meta::IndexOf::value; + index = EC::Meta::IndexOf::value; EXPECT_EQ(index, 1); - index = EC::Meta::IndexOf::value; + index = EC::Meta::IndexOf::value; EXPECT_EQ(index, 2); - index = EC::Meta::IndexOf::value; + index = EC::Meta::IndexOf::value; EXPECT_EQ(index, 3); - index = EC::Meta::IndexOf::value; + index = EC::Meta::IndexOf::value; EXPECT_EQ(index, 0); - index = EC::Meta::IndexOf::value; + index = EC::Meta::IndexOf::value; EXPECT_EQ(index, 1); } TEST(Meta, Bitset) { - EC::Bitset bitset; - EXPECT_EQ(bitset.size(), listAll::size + listTagsAll::size); + EC::Bitset bitset; + EXPECT_EQ(bitset.size(), ListComponentsAll::size + ListTagsAll::size); - bitset[EC::Meta::IndexOf::value] = true; + bitset[EC::Meta::IndexOf::value] = true; EXPECT_TRUE(bitset.getComponentBit()); bitset.flip(); EXPECT_FALSE(bitset.getComponentBit()); bitset.reset(); - bitset[listAll::size + EC::Meta::IndexOf::value] = true; + bitset[ListComponentsAll::size + EC::Meta::IndexOf::value] = true; EXPECT_TRUE(bitset.getTagBit()); bitset.flip(); EXPECT_FALSE(bitset.getTagBit()); } +TEST(Meta, Combine) +{ + using CombinedAll = EC::Meta::Combine; + + int listAllTemp = ListAll::size; + int combinedAllTemp = CombinedAll::size; + EXPECT_EQ(combinedAllTemp, listAllTemp); + + listAllTemp = EC::Meta::IndexOf::value; + combinedAllTemp = EC::Meta::IndexOf::value; + EXPECT_EQ(combinedAllTemp, listAllTemp); + + listAllTemp = EC::Meta::IndexOf::value; + combinedAllTemp = EC::Meta::IndexOf::value; + EXPECT_EQ(combinedAllTemp, listAllTemp); + + listAllTemp = EC::Meta::IndexOf::value; + combinedAllTemp = EC::Meta::IndexOf::value; + EXPECT_EQ(combinedAllTemp, listAllTemp); + + listAllTemp = EC::Meta::IndexOf::value; + combinedAllTemp = EC::Meta::IndexOf::value; + EXPECT_EQ(combinedAllTemp, listAllTemp); + + listAllTemp = EC::Meta::IndexOf::value; + combinedAllTemp = EC::Meta::IndexOf::value; + EXPECT_EQ(combinedAllTemp, listAllTemp); + + listAllTemp = EC::Meta::IndexOf::value; + combinedAllTemp = EC::Meta::IndexOf::value; + EXPECT_EQ(combinedAllTemp, listAllTemp); +} +