Added EC/Meta/Combine.hpp
Also some renaming in MetaTest.hpp
This commit is contained in:
parent
c08f7d6445
commit
a503eb628d
3 changed files with 91 additions and 26 deletions
29
src/EC/Meta/Combine.hpp
Normal file
29
src/EC/Meta/Combine.hpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
#ifndef EC_META_COMBINE_HPP
|
||||||
|
#define EC_META_COMBINE_HPP
|
||||||
|
|
||||||
|
#include "TypeList.hpp"
|
||||||
|
|
||||||
|
namespace EC
|
||||||
|
{
|
||||||
|
namespace Meta
|
||||||
|
{
|
||||||
|
template <typename TTypeListA, typename TTypeListB>
|
||||||
|
struct CombineHelper
|
||||||
|
{
|
||||||
|
using type = TypeList<>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... TypesA, typename... TypesB>
|
||||||
|
struct CombineHelper<TypeList<TypesA...>, TypeList<TypesB...> >
|
||||||
|
{
|
||||||
|
using type = TypeList<TypesA..., TypesB...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TTypeListA, typename TTypeListB>
|
||||||
|
using Combine = typename CombineHelper<TTypeListA, TTypeListB>::type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "TypeList.hpp"
|
#include "TypeList.hpp"
|
||||||
|
#include "Combine.hpp"
|
||||||
#include "Contains.hpp"
|
#include "Contains.hpp"
|
||||||
#include "ContainsAll.hpp"
|
#include "ContainsAll.hpp"
|
||||||
#include "IndexOf.hpp"
|
#include "IndexOf.hpp"
|
||||||
|
|
|
@ -12,81 +12,116 @@ struct C3 {};
|
||||||
struct T0 {};
|
struct T0 {};
|
||||||
struct T1 {};
|
struct T1 {};
|
||||||
|
|
||||||
using listAll = EC::Meta::TypeList<C0, C1, C2, C3>;
|
using ListComponentsAll = EC::Meta::TypeList<C0, C1, C2, C3>;
|
||||||
using listSome = EC::Meta::TypeList<C1, C3>;
|
using ListComponentsSome = EC::Meta::TypeList<C1, C3>;
|
||||||
|
|
||||||
using listTagsAll = EC::Meta::TypeList<T0, T1>;
|
using ListTagsAll = EC::Meta::TypeList<T0, T1>;
|
||||||
|
|
||||||
|
using ListAll = EC::Meta::TypeList<C0, C1, C2, C3, T0, T1>;
|
||||||
|
|
||||||
TEST(Meta, Contains)
|
TEST(Meta, Contains)
|
||||||
{
|
{
|
||||||
int size = listAll::size;
|
int size = ListComponentsAll::size;
|
||||||
EXPECT_EQ(size, 4);
|
EXPECT_EQ(size, 4);
|
||||||
|
|
||||||
bool result = EC::Meta::Contains<C0, listAll>::value;
|
bool result = EC::Meta::Contains<C0, ListComponentsAll>::value;
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
result = EC::Meta::Contains<C1, listAll>::value;
|
result = EC::Meta::Contains<C1, ListComponentsAll>::value;
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
result = EC::Meta::Contains<C2, listAll>::value;
|
result = EC::Meta::Contains<C2, ListComponentsAll>::value;
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
result = EC::Meta::Contains<C3, listAll>::value;
|
result = EC::Meta::Contains<C3, ListComponentsAll>::value;
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
|
|
||||||
size = listSome::size;
|
size = ListComponentsSome::size;
|
||||||
EXPECT_EQ(size, 2);
|
EXPECT_EQ(size, 2);
|
||||||
|
|
||||||
result = EC::Meta::Contains<C0, listSome>::value;
|
result = EC::Meta::Contains<C0, ListComponentsSome>::value;
|
||||||
EXPECT_FALSE(result);
|
EXPECT_FALSE(result);
|
||||||
result = EC::Meta::Contains<C1, listSome>::value;
|
result = EC::Meta::Contains<C1, ListComponentsSome>::value;
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
result = EC::Meta::Contains<C2, listSome>::value;
|
result = EC::Meta::Contains<C2, ListComponentsSome>::value;
|
||||||
EXPECT_FALSE(result);
|
EXPECT_FALSE(result);
|
||||||
result = EC::Meta::Contains<C3, listSome>::value;
|
result = EC::Meta::Contains<C3, ListComponentsSome>::value;
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Meta, ContainsAll)
|
TEST(Meta, ContainsAll)
|
||||||
{
|
{
|
||||||
bool contains = EC::Meta::ContainsAll<listSome, listAll>::value;
|
bool contains = EC::Meta::ContainsAll<ListComponentsSome, ListComponentsAll>::value;
|
||||||
EXPECT_TRUE(contains);
|
EXPECT_TRUE(contains);
|
||||||
|
|
||||||
contains = EC::Meta::ContainsAll<listAll, listSome>::value;
|
contains = EC::Meta::ContainsAll<ListComponentsAll, ListComponentsSome>::value;
|
||||||
EXPECT_FALSE(contains);
|
EXPECT_FALSE(contains);
|
||||||
|
|
||||||
contains = EC::Meta::ContainsAll<listAll, listAll>::value;
|
contains = EC::Meta::ContainsAll<ListComponentsAll, ListComponentsAll>::value;
|
||||||
EXPECT_TRUE(contains);
|
EXPECT_TRUE(contains);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Meta, IndexOf)
|
TEST(Meta, IndexOf)
|
||||||
{
|
{
|
||||||
int index = EC::Meta::IndexOf<C0, listAll>::value;
|
int index = EC::Meta::IndexOf<C0, ListComponentsAll>::value;
|
||||||
EXPECT_EQ(index, 0);
|
EXPECT_EQ(index, 0);
|
||||||
index = EC::Meta::IndexOf<C1, listAll>::value;
|
index = EC::Meta::IndexOf<C1, ListComponentsAll>::value;
|
||||||
EXPECT_EQ(index, 1);
|
EXPECT_EQ(index, 1);
|
||||||
index = EC::Meta::IndexOf<C2, listAll>::value;
|
index = EC::Meta::IndexOf<C2, ListComponentsAll>::value;
|
||||||
EXPECT_EQ(index, 2);
|
EXPECT_EQ(index, 2);
|
||||||
index = EC::Meta::IndexOf<C3, listAll>::value;
|
index = EC::Meta::IndexOf<C3, ListComponentsAll>::value;
|
||||||
EXPECT_EQ(index, 3);
|
EXPECT_EQ(index, 3);
|
||||||
|
|
||||||
index = EC::Meta::IndexOf<C1, listSome>::value;
|
index = EC::Meta::IndexOf<C1, ListComponentsSome>::value;
|
||||||
EXPECT_EQ(index, 0);
|
EXPECT_EQ(index, 0);
|
||||||
index = EC::Meta::IndexOf<C3, listSome>::value;
|
index = EC::Meta::IndexOf<C3, ListComponentsSome>::value;
|
||||||
EXPECT_EQ(index, 1);
|
EXPECT_EQ(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Meta, Bitset)
|
TEST(Meta, Bitset)
|
||||||
{
|
{
|
||||||
EC::Bitset<listAll, listTagsAll> bitset;
|
EC::Bitset<ListComponentsAll, ListTagsAll> bitset;
|
||||||
EXPECT_EQ(bitset.size(), listAll::size + listTagsAll::size);
|
EXPECT_EQ(bitset.size(), ListComponentsAll::size + ListTagsAll::size);
|
||||||
|
|
||||||
bitset[EC::Meta::IndexOf<C1, listAll>::value] = true;
|
bitset[EC::Meta::IndexOf<C1, ListComponentsAll>::value] = true;
|
||||||
EXPECT_TRUE(bitset.getComponentBit<C1>());
|
EXPECT_TRUE(bitset.getComponentBit<C1>());
|
||||||
bitset.flip();
|
bitset.flip();
|
||||||
EXPECT_FALSE(bitset.getComponentBit<C1>());
|
EXPECT_FALSE(bitset.getComponentBit<C1>());
|
||||||
|
|
||||||
bitset.reset();
|
bitset.reset();
|
||||||
bitset[listAll::size + EC::Meta::IndexOf<T0, listTagsAll>::value] = true;
|
bitset[ListComponentsAll::size + EC::Meta::IndexOf<T0, ListTagsAll>::value] = true;
|
||||||
EXPECT_TRUE(bitset.getTagBit<T0>());
|
EXPECT_TRUE(bitset.getTagBit<T0>());
|
||||||
bitset.flip();
|
bitset.flip();
|
||||||
EXPECT_FALSE(bitset.getTagBit<T0>());
|
EXPECT_FALSE(bitset.getTagBit<T0>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Meta, Combine)
|
||||||
|
{
|
||||||
|
using CombinedAll = EC::Meta::Combine<ListComponentsAll, ListTagsAll>;
|
||||||
|
|
||||||
|
int listAllTemp = ListAll::size;
|
||||||
|
int combinedAllTemp = CombinedAll::size;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
|
||||||
|
listAllTemp = EC::Meta::IndexOf<C0, ListAll>::value;
|
||||||
|
combinedAllTemp = EC::Meta::IndexOf<C0, CombinedAll>::value;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
|
||||||
|
listAllTemp = EC::Meta::IndexOf<C1, ListAll>::value;
|
||||||
|
combinedAllTemp = EC::Meta::IndexOf<C1, CombinedAll>::value;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
|
||||||
|
listAllTemp = EC::Meta::IndexOf<C2, ListAll>::value;
|
||||||
|
combinedAllTemp = EC::Meta::IndexOf<C2, CombinedAll>::value;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
|
||||||
|
listAllTemp = EC::Meta::IndexOf<C3, ListAll>::value;
|
||||||
|
combinedAllTemp = EC::Meta::IndexOf<C3, CombinedAll>::value;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
|
||||||
|
listAllTemp = EC::Meta::IndexOf<T0, ListAll>::value;
|
||||||
|
combinedAllTemp = EC::Meta::IndexOf<T0, CombinedAll>::value;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
|
||||||
|
listAllTemp = EC::Meta::IndexOf<T1, ListAll>::value;
|
||||||
|
combinedAllTemp = EC::Meta::IndexOf<T1, CombinedAll>::value;
|
||||||
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue