Split Meta.hpp

This commit is contained in:
Stephen Seo 2016-03-04 20:20:56 +09:00
parent 4092c7c565
commit c318121dc8
7 changed files with 96 additions and 61 deletions

View file

@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.0)
project(EntityComponentSystem)
set(EntityComponentSystem_HEADERS
EC/Meta.hpp)
EC/Meta/TypeList.hpp
EC/Meta/Contains.hpp
EC/Meta/IndexOf.hpp)
add_library(EntityComponentSystem INTERFACE)
target_include_directories(EntityComponentSystem INTERFACE ${CMAKE_SOURCE_DIR})

View file

@ -1,59 +0,0 @@
#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 >;
template <typename T, typename... Types>
struct IndexOf
{
};
template <typename T, typename... Types>
struct IndexOf<T, TypeList<T, Types...> > :
std::integral_constant<std::size_t, 0>
{
};
template <typename T, typename Type, typename... Types>
struct IndexOf<T, TypeList<Type, Types...> > :
std::integral_constant<std::size_t, 1 +
IndexOf<T, TypeList<Types...> >::value
>
{
};
}
}
#endif

33
src/EC/Meta/Contains.hpp Normal file
View file

@ -0,0 +1,33 @@
#ifndef EC_META_CONTAINS_HPP
#define EC_META_CONTAINS_HPP
#include "TypeList.hpp"
namespace EC
{
namespace Meta
{
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

33
src/EC/Meta/IndexOf.hpp Normal file
View file

@ -0,0 +1,33 @@
#ifndef EC_META_INDEX_OF_HPP
#define EC_META_INDEX_OF_HPP
#include "TypeList.hpp"
namespace EC
{
namespace Meta
{
template <typename T, typename... Types>
struct IndexOf
{
};
template <typename T, typename... Types>
struct IndexOf<T, TypeList<T, Types...> > :
std::integral_constant<std::size_t, 0>
{
};
template <typename T, typename Type, typename... Types>
struct IndexOf<T, TypeList<Type, Types...> > :
std::integral_constant<std::size_t, 1 +
IndexOf<T, TypeList<Types...> >::value
>
{
};
}
}
#endif

5
src/EC/Meta/Meta.hpp Normal file
View file

@ -0,0 +1,5 @@
#include "TypeList.hpp"
#include "Contains.hpp"
#include "IndexOf.hpp"

21
src/EC/Meta/TypeList.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef EC_META_TYPE_LIST_HPP
#define EC_META_TYPE_LIST_HPP
#include <type_traits>
namespace EC
{
namespace Meta
{
template <typename... Types>
struct TypeList
{
static constexpr std::size_t size{sizeof...(Types)};
};
}
}
#endif

View file

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <EC/Meta.hpp>
#include <EC/Meta/Meta.hpp>
struct C0 {};
struct C1 {};