Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs::ref< T > Struct Template Reference

Component reference. More...

#include <ref.hpp>

Inheritance diagram for flecs::ref< T >:
[legend]

Public Member Functions

 ref ()
 Default constructor.
 
 ref (world_t *world, entity_t entity, flecs::id_t id=0)
 Construct a reference from a world, entity, and optional component ID.
 
 ref (flecs::entity entity, flecs::id_t id=0)
 Construct a reference from an entity and optional component ID.
 
T * operator-> ()
 Dereference operator.
 
T * get ()
 Get a typed pointer to the component value.
 
T * try_get ()
 Try to get a typed pointer to the component value.
 
- Public Member Functions inherited from flecs::untyped_ref
 untyped_ref ()
 Default constructor.
 
 untyped_ref (world_t *world, entity_t entity, flecs::id_t id)
 Construct a reference from a world, entity, and component ID.
 
 untyped_ref (flecs::entity entity, flecs::id_t id)
 Construct a reference from an entity and component ID.
 
flecs::entity entity () const
 Return the entity associated with the reference.
 
flecs::id component () const
 Return the component associated with the reference.
 
void * get ()
 Get a pointer to the component value.
 
bool has ()
 Check if the reference has a valid component value.
 
flecs::world world () const
 Get the world associated with the reference.
 
 operator bool ()
 Implicit conversion to bool.
 
void * try_get ()
 Try to get a pointer to the component value.
 

Detailed Description

template<typename T>
struct flecs::ref< T >

Component reference.

Reference to a component from a specific entity.

Definition at line 108 of file ref.hpp.

Constructor & Destructor Documentation

◆ ref() [1/3]

template<typename T >
flecs::ref< T >::ref ( )
inline

Default constructor.

Creates an empty reference.

Definition at line 110 of file ref.hpp.

◆ ref() [2/3]

template<typename T >
flecs::ref< T >::ref ( world_t * world,
entity_t entity,
flecs::id_t id = 0 )
inline

Construct a reference from a world, entity, and optional component ID.

Parameters
worldThe world.
entityThe entity.
idThe component ID (defaults to type T's ID).

Definition at line 118 of file ref.hpp.

◆ ref() [3/3]

template<typename T >
flecs::ref< T >::ref ( flecs::entity entity,
flecs::id_t id = 0 )

Construct a reference from an entity and optional component ID.

Parameters
entityThe entity.
idThe component ID (defaults to type T's ID).

Definition at line 18 of file impl.hpp.

Member Function Documentation

◆ get()

template<typename T >
T * flecs::ref< T >::get ( )
inline

Get a typed pointer to the component value.

Definition at line 140 of file ref.hpp.

◆ operator->()

template<typename T >
T * flecs::ref< T >::operator-> ( )
inline

Dereference operator.

Return a pointer to the component value.

Definition at line 130 of file ref.hpp.

◆ try_get()

template<typename T >
T * flecs::ref< T >::try_get ( )
inline

Try to get a typed pointer to the component value.

Return nullptr if the reference is invalid.

Definition at line 147 of file ref.hpp.


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