fwd.hpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #ifndef ENTT_ENTITY_FWD_HPP
  2. #define ENTT_ENTITY_FWD_HPP
  3. #include <cstdint>
  4. #include <memory>
  5. #include <type_traits>
  6. #include "../core/fwd.hpp"
  7. #include "../core/type_traits.hpp"
  8. namespace entt {
  9. /*! @brief Default entity identifier. */
  10. enum class entity : id_type {};
  11. /*! @brief Storage deletion policy. */
  12. enum class deletion_policy : std::uint8_t {
  13. /*! @brief Swap-and-pop deletion policy. */
  14. swap_and_pop = 0u,
  15. /*! @brief In-place deletion policy. */
  16. in_place = 1u,
  17. /*! @brief Swap-only deletion policy. */
  18. swap_only = 2u
  19. };
  20. template<typename Entity = entity, typename = std::allocator<Entity>>
  21. class basic_sparse_set;
  22. template<typename Type, typename = entity, typename = std::allocator<Type>, typename = void>
  23. class basic_storage;
  24. template<typename, typename>
  25. class basic_sigh_mixin;
  26. template<typename Entity = entity, typename = std::allocator<Entity>>
  27. class basic_registry;
  28. template<typename, typename, typename = void>
  29. class basic_view;
  30. template<typename Type, typename = std::allocator<Type *>>
  31. class basic_runtime_view;
  32. template<typename, typename, typename>
  33. class basic_group;
  34. template<typename, typename Mask = std::uint32_t, typename = std::allocator<Mask>>
  35. class basic_observer;
  36. template<typename>
  37. class basic_organizer;
  38. template<typename, typename...>
  39. struct basic_handle;
  40. template<typename>
  41. class basic_snapshot;
  42. template<typename>
  43. class basic_snapshot_loader;
  44. template<typename>
  45. class basic_continuous_loader;
  46. /*! @brief Alias declaration for the most common use case. */
  47. using sparse_set = basic_sparse_set<>;
  48. /**
  49. * @brief Alias declaration for the most common use case.
  50. * @tparam Type Type of objects assigned to the entities.
  51. */
  52. template<typename Type>
  53. using storage = basic_storage<Type>;
  54. /**
  55. * @brief Alias declaration for the most common use case.
  56. * @tparam Type Underlying storage type.
  57. */
  58. template<typename Type>
  59. using sigh_mixin = basic_sigh_mixin<Type, basic_registry<typename Type::entity_type, typename Type::base_type::allocator_type>>;
  60. /*! @brief Alias declaration for the most common use case. */
  61. using registry = basic_registry<>;
  62. /*! @brief Alias declaration for the most common use case. */
  63. using observer = basic_observer<registry>;
  64. /*! @brief Alias declaration for the most common use case. */
  65. using organizer = basic_organizer<registry>;
  66. /*! @brief Alias declaration for the most common use case. */
  67. using handle = basic_handle<registry>;
  68. /*! @brief Alias declaration for the most common use case. */
  69. using const_handle = basic_handle<const registry>;
  70. /**
  71. * @brief Alias declaration for the most common use case.
  72. * @tparam Args Other template parameters.
  73. */
  74. template<typename... Args>
  75. using handle_view = basic_handle<registry, Args...>;
  76. /**
  77. * @brief Alias declaration for the most common use case.
  78. * @tparam Args Other template parameters.
  79. */
  80. template<typename... Args>
  81. using const_handle_view = basic_handle<const registry, Args...>;
  82. /*! @brief Alias declaration for the most common use case. */
  83. using snapshot = basic_snapshot<registry>;
  84. /*! @brief Alias declaration for the most common use case. */
  85. using snapshot_loader = basic_snapshot_loader<registry>;
  86. /*! @brief Alias declaration for the most common use case. */
  87. using continuous_loader = basic_continuous_loader<registry>;
  88. /*! @brief Alias declaration for the most common use case. */
  89. using runtime_view = basic_runtime_view<sparse_set>;
  90. /*! @brief Alias declaration for the most common use case. */
  91. using const_runtime_view = basic_runtime_view<const sparse_set>;
  92. /**
  93. * @brief Alias for exclusion lists.
  94. * @tparam Type List of types.
  95. */
  96. template<typename... Type>
  97. struct exclude_t final: type_list<Type...> {
  98. /*! @brief Default constructor. */
  99. explicit constexpr exclude_t() {}
  100. };
  101. /**
  102. * @brief Variable template for exclusion lists.
  103. * @tparam Type List of types.
  104. */
  105. template<typename... Type>
  106. inline constexpr exclude_t<Type...> exclude{};
  107. /**
  108. * @brief Alias for lists of observed components.
  109. * @tparam Type List of types.
  110. */
  111. template<typename... Type>
  112. struct get_t final: type_list<Type...> {
  113. /*! @brief Default constructor. */
  114. explicit constexpr get_t() {}
  115. };
  116. /**
  117. * @brief Variable template for lists of observed components.
  118. * @tparam Type List of types.
  119. */
  120. template<typename... Type>
  121. inline constexpr get_t<Type...> get{};
  122. /**
  123. * @brief Alias for lists of owned components.
  124. * @tparam Type List of types.
  125. */
  126. template<typename... Type>
  127. struct owned_t final: type_list<Type...> {
  128. /*! @brief Default constructor. */
  129. explicit constexpr owned_t() {}
  130. };
  131. /**
  132. * @brief Variable template for lists of owned components.
  133. * @tparam Type List of types.
  134. */
  135. template<typename... Type>
  136. inline constexpr owned_t<Type...> owned{};
  137. /**
  138. * @brief Applies a given _function_ to a get list and generate a new list.
  139. * @tparam Type Types provided by the get list.
  140. * @tparam Op Unary operation as template class with a type member named `type`.
  141. */
  142. template<typename... Type, template<typename...> class Op>
  143. struct type_list_transform<get_t<Type...>, Op> {
  144. /*! @brief Resulting get list after applying the transform function. */
  145. using type = get_t<typename Op<Type>::type...>;
  146. };
  147. /**
  148. * @brief Applies a given _function_ to an exclude list and generate a new list.
  149. * @tparam Type Types provided by the exclude list.
  150. * @tparam Op Unary operation as template class with a type member named `type`.
  151. */
  152. template<typename... Type, template<typename...> class Op>
  153. struct type_list_transform<exclude_t<Type...>, Op> {
  154. /*! @brief Resulting exclude list after applying the transform function. */
  155. using type = exclude_t<typename Op<Type>::type...>;
  156. };
  157. /**
  158. * @brief Applies a given _function_ to an owned list and generate a new list.
  159. * @tparam Type Types provided by the owned list.
  160. * @tparam Op Unary operation as template class with a type member named `type`.
  161. */
  162. template<typename... Type, template<typename...> class Op>
  163. struct type_list_transform<owned_t<Type...>, Op> {
  164. /*! @brief Resulting owned list after applying the transform function. */
  165. using type = owned_t<typename Op<Type>::type...>;
  166. };
  167. /**
  168. * @brief Provides a common way to define storage types.
  169. * @tparam Type Storage value type.
  170. * @tparam Entity A valid entity type.
  171. * @tparam Allocator Type of allocator used to manage memory and elements.
  172. */
  173. template<typename Type, typename Entity = entity, typename Allocator = std::allocator<Type>, typename = void>
  174. struct storage_type {
  175. /*! @brief Type-to-storage conversion result. */
  176. using type = sigh_mixin<basic_storage<Type, Entity, Allocator>>;
  177. };
  178. /**
  179. * @brief Helper type.
  180. * @tparam Args Arguments to forward.
  181. */
  182. template<typename... Args>
  183. using storage_type_t = typename storage_type<Args...>::type;
  184. /**
  185. * Type-to-storage conversion utility that preserves constness.
  186. * @tparam Type Storage value type, eventually const.
  187. * @tparam Entity A valid entity type.
  188. * @tparam Allocator Type of allocator used to manage memory and elements.
  189. */
  190. template<typename Type, typename Entity = entity, typename Allocator = std::allocator<std::remove_const_t<Type>>>
  191. struct storage_for {
  192. /*! @brief Type-to-storage conversion result. */
  193. using type = constness_as_t<storage_type_t<std::remove_const_t<Type>, Entity, Allocator>, Type>;
  194. };
  195. /**
  196. * @brief Helper type.
  197. * @tparam Args Arguments to forward.
  198. */
  199. template<typename... Args>
  200. using storage_for_t = typename storage_for<Args...>::type;
  201. /**
  202. * @brief Alias declaration for the most common use case.
  203. * @tparam Get Types of storage iterated by the view.
  204. * @tparam Exclude Types of storage used to filter the view.
  205. */
  206. template<typename Get, typename Exclude = exclude_t<>>
  207. using view = basic_view<type_list_transform_t<Get, storage_for>, type_list_transform_t<Exclude, storage_for>>;
  208. /**
  209. * @brief Alias declaration for the most common use case.
  210. * @tparam Owned Types of storage _owned_ by the group.
  211. * @tparam Get Types of storage _observed_ by the group.
  212. * @tparam Exclude Types of storage used to filter the group.
  213. */
  214. template<typename Owned, typename Get, typename Exclude>
  215. using group = basic_group<type_list_transform_t<Owned, storage_for>, type_list_transform_t<Get, storage_for>, type_list_transform_t<Exclude, storage_for>>;
  216. } // namespace entt
  217. #endif