EnTT: src/entt/entity/component.hpp Source File

EnTT 3.16.0

Loading...
Searching...
No Matches
component.hpp
1#ifndef ENTT_ENTITY_COMPONENT_HPP
2#define ENTT_ENTITY_COMPONENT_HPP
3
4#include <cstddef>
5#include <type_traits>
6#include "../config/config.h"
7#include "fwd.hpp"
8
9namespace entt {
10
12namespace internal {
13
14template<typename Type, typename = void>
15struct in_place_delete: std::bool_constant<!(std::is_move_constructible_v<Type> && std::is_move_assignable_v<Type>)> {};
16
17template<>
18struct in_place_delete<void>: std::false_type {};
19
20template<typename Type>
21struct in_place_delete<Type, std::enable_if_t<Type::in_place_delete>>
22 : std::true_type {};
23
24template<typename Type, typename = void>
25struct page_size: std::integral_constant<std::size_t, !std::is_empty_v<ENTT_ETO_TYPE(Type)> * ENTT_PACKED_PAGE> {};
26
27template<>
28struct page_size<void>: std::integral_constant<std::size_t, 0u> {};
29
30template<typename Type>
31struct page_size<Type, std::void_t<decltype(Type::page_size)>>
32 : std::integral_constant<std::size_t, Type::page_size> {};
33
34} // namespace internal
36
42template<typename Type, typename Entity, typename>
43 struct component_traits {
44 static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
45
47 using element_type = Type;
49 using entity_type = Entity;
50
52 static constexpr bool in_place_delete = internal::in_place_delete<Type>::value;
54 static constexpr std::size_t page_size = internal::page_size<Type>::value;
55};
56
57} // namespace entt
58
59#endif
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::component_traits
Common way to access various properties of components.
Definition component.hpp:43
entt::component_traits< Type, Entity >::in_place_delete
static constexpr bool in_place_delete
Definition component.hpp:52
entt::component_traits::element_type
Type element_type
Element type.
Definition component.hpp:47
entt::component_traits::entity_type
Entity entity_type
Underlying entity identifier.
Definition component.hpp:49
entt::component_traits< Type, Entity >::page_size
static constexpr std::size_t page_size
Definition component.hpp:54