1 #ifndef ENTT_ENTITY_HANDLE_HPP
2 #define ENTT_ENTITY_HANDLE_HPP
7 #include "../config/config.h"
8 #include "../core/type_traits.hpp"
10 #include "registry.hpp"
22 template<
typename Entity,
typename... Type>
31 using size_type =
typename registry_type::size_type;
54 template<
typename Other,
typename... Args>
56 static_assert(std::is_same_v<Other, Entity> || std::is_same_v<std::remove_const_t<Other>, Entity>,
"Invalid conversion between different handles");
57 static_assert((
sizeof...(Type) == 0 || ((
sizeof...(Args) != 0 &&
sizeof...(Args) <=
sizeof...(Type)) && ... && (
type_list_contains_v<
type_list<Type...>, Args>))),
"Invalid conversion between different handles");
74 [[nodiscard]]
explicit operator bool() const ENTT_NOEXCEPT {
75 return reg && reg->valid(
entt);
82 [[nodiscard]]
bool valid()
const {
83 return reg->valid(
entt);
116 reg->destroy(
entt, version);
127 template<
typename Component,
typename... Args>
128 decltype(
auto)
emplace(Args &&...args)
const {
129 static_assert(((
sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>),
"Invalid type");
130 return reg->template emplace<Component>(
entt, std::forward<Args>(args)...);
141 template<
typename Component,
typename... Args>
143 static_assert(((
sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>),
"Invalid type");
144 return reg->template emplace_or_replace<Component>(
entt, std::forward<Args>(args)...);
155 template<
typename Component,
typename... Func>
156 decltype(
auto)
patch(Func &&...func)
const {
157 static_assert(((
sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>),
"Invalid type");
158 return reg->template patch<Component>(
entt, std::forward<Func>(func)...);
169 template<
typename Component,
typename... Args>
170 decltype(
auto)
replace(Args &&...args)
const {
171 static_assert(((
sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>),
"Invalid type");
172 return reg->template replace<Component>(
entt, std::forward<Args>(args)...);
181 template<
typename... Component>
184 return reg->template
remove<Component...>(
entt);
192 template<
typename... Component>
204 template<
typename... Component>
205 [[nodiscard]] decltype(
auto)
all_of()
const {
206 return reg->template
all_of<Component...>(
entt);
216 template<
typename... Component>
217 [[nodiscard]] decltype(
auto)
any_of()
const {
218 return reg->template
any_of<Component...>(
entt);
227 template<
typename... Component>
228 [[nodiscard]] decltype(
auto)
get()
const {
230 return reg->template
get<Component...>(
entt);
241 template<
typename Component,
typename... Args>
243 static_assert(((
sizeof...(Type) == 0) || ... || std::is_same_v<Component, Type>),
"Invalid type");
244 return reg->template get_or_emplace<Component>(
entt, std::forward<Args>(args)...);
253 template<
typename... Component>
264 return reg->orphan(
entt);
282 template<
typename Func>
284 for(
auto [
id,
storage]: reg->storage()) {
305 template<
typename... Args,
typename... Other>
307 return lhs.registry() == rhs.registry() && lhs.entity() == rhs.entity();
319 template<
typename... Args,
typename... Other>
321 return !(lhs == rhs);
328 template<
typename Entity>
335 template<
typename Entity>
Fast and reliable entity-component system.
bool contains(const entity_type entt) const
Checks if a sparse set contains an entity.
Basic storage implementation.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
basic_handle(basic_registry< Entity > &, Entity) -> basic_handle< Entity >
Deduction guide.
typename constness_as< To, From >::type constness_as_t
Alias template to facilitate the transcription of the constness.
constexpr bool type_list_contains_v
Helper variable template.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.
Non-owning handle to an entity.
decltype(auto) any_of() const
Checks if a handle has at least one of the given components.
bool orphan() const
Checks if a handle has components assigned.
typename registry_type::size_type size_type
Unsigned integer type.
decltype(auto) get() const
Returns references to the given components for a handle.
void visit(Func &&func) const
Visits a handle and returns the pools for its components.
entity_type entity() const
Returns the entity associated with a handle.
decltype(auto) all_of() const
Checks if a handle has all the given components.
registry_type * registry() const
Returns a pointer to the underlying registry, if any.
typename registry_type::entity_type entity_type
Underlying entity identifier.
decltype(auto) replace(Args &&...args) const
Replaces the given component for a handle.
auto try_get() const
Returns pointers to the given components for a handle.
decltype(auto) patch(Func &&...func) const
Patches the given component for a handle.
decltype(auto) emplace_or_replace(Args &&...args) const
Assigns or replaces the given component for a handle.
decltype(auto) emplace(Args &&...args) const
Assigns the given component to a handle.
basic_handle(registry_type &ref, entity_type value)
Constructs a handle from a given registry and entity.
void destroy()
Destroys the entity associated with a handle.
typename registry_type::version_type version_type
Underlying version type.
bool valid() const
Checks if a handle refers to a valid entity or not.
size_type remove() const
Removes the given components from a handle.
void erase() const
Erases the given components from a handle.
decltype(auto) get_or_emplace(Args &&...args) const
Returns a reference to the given component for a handle.
basic_handle()
Constructs an invalid handle.
constness_as_t< basic_registry< std::remove_const_t< Entity > >, Entity > registry_type
Type of registry accepted by the handle.
void destroy(const version_type version)
Destroys the entity associated with a handle.