EnTT  3.5.2
Public Types | Public Member Functions | List of all members
entt::basic_handle< Entity > Struct Template Reference

Non-owning handle to an entity. More...

#include <handle.hpp>

Public Types

using entity_type = std::remove_const_t< Entity >
 Underlying entity identifier.
 
using registry_type = std::conditional_t< std::is_const_v< Entity >, const basic_registry< entity_type >, basic_registry< entity_type > >
 Type of registry accepted by the handle.
 

Public Member Functions

 basic_handle (registry_type &ref, entity_type value=null) noexcept
 Constructs a handle from a given registry and entity. More...
 
basic_handle & operator= (const entity_type value) noexcept
 Assigns an entity to a handle. More...
 
basic_handle & operator= (null_t) noexcept
 Assigns the null object to a handle. More...
 
 operator basic_handle< const entity_type > () const noexcept
 Constructs a const handle from a non-const one. More...
 
 operator entity_type () const noexcept
 Converts a handle to its underlying entity. More...
 
 operator bool () const
 Checks if a handle refers to a valid entity or not. More...
 
registry_type & registry () const noexcept
 Returns a reference to the underlying registry. More...
 
entity_type entity () const noexcept
 Returns the entity associated with a handle. More...
 
template<typename Component , typename... Args>
decltype(auto) emplace (Args &&... args) const
 Assigns the given component to a handle. More...
 
template<typename Component , typename... Args>
decltype(auto) emplace_or_replace (Args &&... args) const
 Assigns or replaces the given component for a handle. More...
 
template<typename Component , typename... Func>
decltype(auto) patch (Func &&... func) const
 Patches the given component for a handle. More...
 
template<typename Component , typename... Args>
decltype(auto) replace (Args &&... args) const
 Replaces the given component for a handle. More...
 
template<typename... Components>
void remove () const
 Removes the given components from a handle. More...
 
template<typename... Components>
decltype(auto) remove_if_exists () const
 Removes the given components from a handle. More...
 
void remove_all () const
 Removes all the components from a handle and makes it orphaned. More...
 
template<typename... Components>
decltype(auto) has () const
 Checks if a handle has all the given components. More...
 
template<typename... Components>
decltype(auto) any () const
 Checks if a handle has at least one of the given components. More...
 
template<typename... Components>
decltype(auto) get () const
 Returns references to the given components for a handle. More...
 
template<typename Component , typename... Args>
decltype(auto) get_or_emplace (Args &&... args) const
 Returns a reference to the given component for a handle. More...
 
template<typename... Components>
decltype(auto) try_get () const
 Returns pointers to the given components for a handle. More...
 
bool orphan () const
 Checks if a handle has components assigned. More...
 
template<typename Func >
void visit (Func &&func) const
 Visits a handle and returns the types for its components. More...
 

Detailed Description

template<typename Entity>
struct entt::basic_handle< Entity >

Non-owning handle to an entity.

Tiny wrapper around a registry and an entity.

Template Parameters
EntityA valid entity type (see entt_traits for more details).

Definition at line 19 of file handle.hpp.

Constructor & Destructor Documentation

◆ basic_handle()

template<typename Entity >
entt::basic_handle< Entity >::basic_handle ( registry_type &  ref,
entity_type  value = null 
)
inlinenoexcept

Constructs a handle from a given registry and entity.

Parameters
refAn instance of the registry class.
valueAn entity identifier.

Definition at line 35 of file handle.hpp.

Member Function Documentation

◆ any()

template<typename Entity >
template<typename... Components>
decltype(auto) entt::basic_handle< Entity >::any ( ) const
inline

Checks if a handle has at least one of the given components.

See also
basic_registry::any
Template Parameters
ComponentComponents for which to perform the check.
Returns
True if the handle has at least one of the given components, false otherwise.

Definition at line 197 of file handle.hpp.

◆ emplace()

template<typename Entity >
template<typename Component , typename... Args>
decltype(auto) entt::basic_handle< Entity >::emplace ( Args &&...  args) const
inline

Assigns the given component to a handle.

See also
basic_registry::emplace
Template Parameters
ComponentType of component to create.
ArgsTypes of arguments to use to construct the component.
Parameters
argsParameters to use to initialize the component.
Returns
A reference to the newly created component.

Definition at line 106 of file handle.hpp.

◆ emplace_or_replace()

template<typename Entity >
template<typename Component , typename... Args>
decltype(auto) entt::basic_handle< Entity >::emplace_or_replace ( Args &&...  args) const
inline

Assigns or replaces the given component for a handle.

See also
basic_registry::emplace_or_replace
Template Parameters
ComponentType of component to assign or replace.
ArgsTypes of arguments to use to construct the component.
Parameters
argsParameters to use to initialize the component.
Returns
A reference to the newly created component.

Definition at line 119 of file handle.hpp.

◆ entity()

template<typename Entity >
entity_type entt::basic_handle< Entity >::entity ( ) const
inlinenoexcept

Returns the entity associated with a handle.

Returns
The entity associated with the handle.

Definition at line 93 of file handle.hpp.

◆ get()

template<typename Entity >
template<typename... Components>
decltype(auto) entt::basic_handle< Entity >::get ( ) const
inline

Returns references to the given components for a handle.

See also
basic_registry::get
Template Parameters
ComponentTypes of components to get.
Returns
References to the components owned by the handle.

Definition at line 208 of file handle.hpp.

◆ get_or_emplace()

template<typename Entity >
template<typename Component , typename... Args>
decltype(auto) entt::basic_handle< Entity >::get_or_emplace ( Args &&...  args) const
inline

Returns a reference to the given component for a handle.

See also
basic_registry::get_or_emplace
Template Parameters
ComponentType of component to get.
ArgsTypes of arguments to use to construct the component.
Parameters
argsParameters to use to initialize the component.
Returns
Reference to the component owned by the handle.

Definition at line 221 of file handle.hpp.

◆ has()

template<typename Entity >
template<typename... Components>
decltype(auto) entt::basic_handle< Entity >::has ( ) const
inline

Checks if a handle has all the given components.

See also
basic_registry::has
Template Parameters
ComponentComponents for which to perform the check.
Returns
True if the handle has all the components, false otherwise.

Definition at line 185 of file handle.hpp.

◆ operator basic_handle< const entity_type >()

template<typename Entity >
entt::basic_handle< Entity >::operator basic_handle< const entity_type > ( ) const
inlinenoexcept

Constructs a const handle from a non-const one.

Returns
A const handle referring to the same entity.

Definition at line 61 of file handle.hpp.

◆ operator bool()

template<typename Entity >
entt::basic_handle< Entity >::operator bool ( ) const
inlineexplicit

Checks if a handle refers to a valid entity or not.

Returns
True if the handle refers to a valid entity, false otherwise.

Definition at line 77 of file handle.hpp.

◆ operator entity_type()

template<typename Entity >
entt::basic_handle< Entity >::operator entity_type ( ) const
inlinenoexcept

Converts a handle to its underlying entity.

Returns
An entity identifier.

Definition at line 69 of file handle.hpp.

◆ operator=() [1/2]

template<typename Entity >
basic_handle& entt::basic_handle< Entity >::operator= ( const entity_type  value)
inlinenoexcept

Assigns an entity to a handle.

Parameters
valueAn entity identifier.
Returns
This handle.

Definition at line 44 of file handle.hpp.

◆ operator=() [2/2]

template<typename Entity >
basic_handle& entt::basic_handle< Entity >::operator= ( null_t  )
inlinenoexcept

Assigns the null object to a handle.

Returns
This handle.

Definition at line 53 of file handle.hpp.

◆ orphan()

template<typename Entity >
bool entt::basic_handle< Entity >::orphan ( ) const
inline

Checks if a handle has components assigned.

Returns
True if the handle has no components assigned, false otherwise.

Definition at line 240 of file handle.hpp.

◆ patch()

template<typename Entity >
template<typename Component , typename... Func>
decltype(auto) entt::basic_handle< Entity >::patch ( Func &&...  func) const
inline

Patches the given component for a handle.

See also
basic_registry::patch
Template Parameters
ComponentType of component to patch.
FuncTypes of the function objects to invoke.
Parameters
funcValid function objects.
Returns
A reference to the patched component.

Definition at line 132 of file handle.hpp.

◆ registry()

template<typename Entity >
registry_type& entt::basic_handle< Entity >::registry ( ) const
inlinenoexcept

Returns a reference to the underlying registry.

Returns
A reference to the underlying registry.

Definition at line 85 of file handle.hpp.

◆ remove()

template<typename Entity >
template<typename... Components>
void entt::basic_handle< Entity >::remove ( ) const
inline

Removes the given components from a handle.

See also
basic_registry::remove
Template Parameters
ComponentTypes of components to remove.

Definition at line 155 of file handle.hpp.

◆ remove_all()

template<typename Entity >
void entt::basic_handle< Entity >::remove_all ( ) const
inline

Removes all the components from a handle and makes it orphaned.

See also
basic_registry::remove_all

Definition at line 174 of file handle.hpp.

◆ remove_if_exists()

template<typename Entity >
template<typename... Components>
decltype(auto) entt::basic_handle< Entity >::remove_if_exists ( ) const
inline

Removes the given components from a handle.

See also
basic_registry::remove_if_exists
Template Parameters
ComponentTypes of components to remove.
Returns
The number of components actually removed.

Definition at line 166 of file handle.hpp.

◆ replace()

template<typename Entity >
template<typename Component , typename... Args>
decltype(auto) entt::basic_handle< Entity >::replace ( Args &&...  args) const
inline

Replaces the given component for a handle.

See also
basic_registry::replace
Template Parameters
ComponentType of component to replace.
ArgsTypes of arguments to use to construct the component.
Parameters
argsParameters to use to initialize the component.
Returns
A reference to the component being replaced.

Definition at line 145 of file handle.hpp.

◆ try_get()

template<typename Entity >
template<typename... Components>
decltype(auto) entt::basic_handle< Entity >::try_get ( ) const
inline

Returns pointers to the given components for a handle.

See also
basic_registry::try_get
Template Parameters
ComponentTypes of components to get.
Returns
Pointers to the components owned by the handle.

Definition at line 232 of file handle.hpp.

◆ visit()

template<typename Entity >
template<typename Func >
void entt::basic_handle< Entity >::visit ( Func &&  func) const
inline

Visits a handle and returns the types for its components.

See also
basic_registry::visit
Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

Definition at line 251 of file handle.hpp.


The documentation for this struct was generated from the following files: