1 #ifndef ENTT_ENTITY_HANDLE_HPP
2 #define ENTT_ENTITY_HANDLE_HPP
5 #include "registry.hpp"
18 template<
typename Entity>
25 std::is_const_v<Entity>,
36 : reg{&ref},
entt{value}
77 [[nodiscard]]
explicit operator bool()
const {
78 return reg->valid(
entt);
105 template<
typename Component,
typename... Args>
106 decltype(
auto)
emplace(Args &&... args)
const {
107 return reg->template emplace<Component>(
entt, std::forward<Args>(args)...);
118 template<
typename Component,
typename... Args>
120 return reg->template emplace_or_replace<Component>(
entt, std::forward<Args>(args)...);
131 template<
typename Component,
typename... Func>
132 decltype(
auto)
patch(Func &&... func)
const {
133 return reg->template patch<Component>(
entt, std::forward<Func>(func)...);
144 template<
typename Component,
typename... Args>
145 decltype(
auto)
replace(Args &&... args)
const {
146 return reg->template replace<Component>(
entt, std::forward<Args>(args)...);
154 template<
typename... Components>
165 template<
typename... Components>
175 reg->remove_all(
entt);
184 template<
typename... Components>
185 [[nodiscard]] decltype(
auto)
has()
const {
186 return reg->template
has<Components...>(
entt);
196 template<
typename... Components>
197 [[nodiscard]] decltype(
auto)
any()
const {
198 return reg->template
any<Components...>(
entt);
207 template<
typename... Components>
208 [[nodiscard]] decltype(
auto)
get()
const {
209 return reg->template
get<Components...>(
entt);
220 template<
typename Component,
typename... Args>
222 return reg->template get_or_emplace<Component>(
entt, std::forward<Args>(args)...);
231 template<
typename... Components>
232 [[nodiscard]] decltype(
auto)
try_get()
const {
241 return reg->orphan(
entt);
250 template<
typename Func>
252 reg->visit(
entt, std::forward<Func>(func));
265 template<
typename Entity>
273 template<
typename Entity>
void remove_all() const
Removes all the components from a handle and makes it orphaned.
Non-owning handle to an entity.
Null object for all entity identifiers.
decltype(auto) emplace_or_replace(Args &&... args) const
Assigns or replaces the given component for a handle.
void remove() const
Removes the given components from a handle.
decltype(auto) remove_if_exists() const
Removes the given components from a handle.
decltype(auto) patch(Func &&... func) const
Patches the given component for a handle.
basic_handle(registry_type &ref, entity_type value=null) noexcept
Constructs a handle from a given registry and entity.
decltype(auto) any() const
Checks if a handle has at least one of the given components.
decltype(auto) try_get() const
Returns pointers to the given components for a handle.
decltype(auto) has() const
Checks if a handle has all the given components.
bool orphan() const
Checks if a handle has components assigned.
decltype(auto) emplace(Args &&... args) const
Assigns the given component to a handle.
decltype(auto) replace(Args &&... args) const
Replaces the given component for a handle.
basic_handle & operator=(null_t) noexcept
Assigns the null object to a handle.
entity_type entity() const noexcept
Returns the entity associated with a handle.
basic_handle(basic_registry< Entity > &, Entity) -> basic_handle< Entity >
Deduction guide.
void visit(Func &&func) const
Visits a handle and returns the types for its components.
decltype(auto) get() const
Returns references to the given components for a handle.
basic_handle & operator=(const entity_type value) noexcept
Assigns an entity to a handle.
registry_type & registry() const noexcept
Returns a reference to the underlying registry.
std::conditional_t< std::is_const_v< Entity >, const basic_registry< entity_type >, basic_registry< entity_type > > registry_type
Type of registry accepted by the handle.
decltype(auto) get_or_emplace(Args &&... args) const
Returns a reference to the given component for a handle.
std::remove_const_t< Entity > entity_type
Underlying entity identifier.