Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs::iter Struct Reference

Class for iterating over query results. More...

#include <iter.hpp>

Public Member Functions

 iter (ecs_iter_t *it)
 Construct iterator from C iterator object.
 
row_iterator begin () const
 
row_iterator end () const
 
flecs::entity system () const
 
flecs::entity event () const
 
flecs::id event_id () const
 
flecs::world world () const
 
const flecs::iter_tc_ptr () const
 
size_t count () const
 
ecs_ftime_t delta_time () const
 
ecs_ftime_t delta_system_time () const
 
flecs::type type () const
 
flecs::table table () const
 
flecs::table_range range () const
 
void * ctx ()
 Access ctx.
 
template<typename T >
T * ctx ()
 Access ctx.
 
void * param ()
 Access param.
 
template<typename T >
T * param ()
 Access param.
 
flecs::entity entity (size_t row) const
 Obtain mutable handle to entity being iterated over.
 
bool is_self (int32_t index) const
 Returns whether field is matched on self.
 
bool is_set (int32_t index) const
 Returns whether field is set.
 
bool is_readonly (int32_t index) const
 Returns whether field is readonly.
 
int32_t field_count () const
 Number of fields in iterator.
 
size_t size (int32_t index) const
 Size of field data type.
 
flecs::entity src (int32_t index) const
 Obtain field source (0 if This).
 
flecs::id id (int32_t index) const
 Obtain id matched for field.
 
flecs::id pair (int32_t index) const
 Obtain pair id matched for field.
 
int32_t column_index (int32_t index) const
 Obtain column index for field.
 
int32_t term_index () const
 Obtain term that triggered an observer.
 
flecs::string str () const
 Convert current iterator result to string.
 
template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value, void >::type * = nullptr>
flecs::field< A > field (int32_t index) const
 Get readonly access to field data.
 
template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value==false, void >::type * = nullptr>
flecs::field< A > field (int32_t index) const
 Get read/write access to field data.
 
flecs::untyped_field field (int32_t index) const
 Get unchecked access to field data.
 
void * field_at (int32_t index, size_t row) const
 Get pointer to field at row.
 
template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value, void >::type * = nullptr>
const A & field_at (int32_t index, size_t row) const
 Get reference to field at row.
 
template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value==false, void >::type * = nullptr>
A & field_at (int32_t index, size_t row) const
 Get reference to field at row.
 
flecs::field< const flecs::entity_t > entities () const
 Get readonly access to entity ids.
 
bool changed ()
 Check if the current table has changed since the last iteration.
 
void skip ()
 Skip current table.
 
uint64_t group_id () const
 
flecs::entity get_var (int var_id) const
 Get value of variable by id.
 
flecs::entity get_var (const char *name) const
 Get value of variable by name.
 
bool next ()
 Progress iterator.
 
void each ()
 Forward to each.
 
void fini ()
 Free iterator resources.
 
flecs::string to_json (flecs::iter_to_json_desc_t *desc=nullptr)
 Serialize iterator result to JSON.
 

Detailed Description

Class for iterating over query results.

Definition at line 68 of file iter.hpp.

Constructor & Destructor Documentation

◆ iter()

flecs::iter::iter ( ecs_iter_t * it)
inline

Construct iterator from C iterator object.

This operation is typically not invoked directly by the user.

Parameters
itPointer to C iterator.

Definition at line 78 of file iter.hpp.

Member Function Documentation

◆ begin()

row_iterator flecs::iter::begin ( ) const
inline

Definition at line 80 of file iter.hpp.

◆ c_ptr()

const flecs::iter_t * flecs::iter::c_ptr ( ) const
inline

Definition at line 96 of file iter.hpp.

◆ changed()

bool flecs::iter::changed ( )
inline

Check if the current table has changed since the last iteration.

Can only be used when iterating queries and/or systems.

Definition at line 307 of file iter.hpp.

◆ column_index()

int32_t flecs::iter::column_index ( int32_t index) const
inline

Obtain column index for field.

Parameters
indexThe field index.

Definition at line 220 of file iter.hpp.

◆ count()

size_t flecs::iter::count ( ) const
inline

Definition at line 100 of file iter.hpp.

◆ ctx() [1/2]

void * flecs::iter::ctx ( )
inline

Access ctx.

ctx contains the context pointer assigned to a system.

Definition at line 125 of file iter.hpp.

◆ ctx() [2/2]

template<typename T >
T * flecs::iter::ctx ( )
inline

Access ctx.

ctx contains the context pointer assigned to a system.

Definition at line 133 of file iter.hpp.

◆ delta_system_time()

ecs_ftime_t flecs::iter::delta_system_time ( ) const
inline

Definition at line 112 of file iter.hpp.

◆ delta_time()

ecs_ftime_t flecs::iter::delta_time ( ) const
inline

Definition at line 108 of file iter.hpp.

◆ each()

void flecs::iter::each ( )
inline

Forward to each.

If a system has an each callback registered, this operation will forward the current iterator to the each callback.

Definition at line 359 of file iter.hpp.

◆ end()

row_iterator flecs::iter::end ( ) const
inline

Definition at line 84 of file iter.hpp.

◆ entities()

flecs::field< const flecs::entity_t > flecs::iter::entities ( ) const
inline

Get readonly access to entity ids.

Returns
The entity ids.

Definition at line 300 of file iter.hpp.

◆ entity()

flecs::entity flecs::iter::entity ( size_t row) const
inline

Obtain mutable handle to entity being iterated over.

Parameters
rowRow being iterated over.

Definition at line 27 of file iter.hpp.

◆ event()

flecs::entity flecs::iter::event ( ) const
inline

Definition at line 15 of file iter.hpp.

◆ event_id()

flecs::id flecs::iter::event_id ( ) const
inline

Definition at line 19 of file iter.hpp.

◆ field() [1/3]

template<typename T , typename A , typename std::enable_if< std::is_const< T >::value==false, void >::type * >
flecs::field< A > flecs::iter::field ( int32_t index) const
inline

Get readonly access to field data.

If the specified field index does not match with the provided type, the function will assert.

Template Parameters
TType of the field.
Parameters
indexThe field index.
Returns
The field data.

Definition at line 64 of file iter.hpp.

◆ field() [2/3]

template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value==false, void >::type * = nullptr>
flecs::field< A > flecs::iter::field ( int32_t index) const

Get read/write access to field data.

If the matched id for the specified field does not match with the provided type or if the field is readonly, the function will assert.

Template Parameters
TType of the field.
Parameters
indexThe field index.
Returns
The field data.

◆ field() [3/3]

flecs::untyped_field flecs::iter::field ( int32_t index) const
inline

Get unchecked access to field data.

Unchecked access is required when a system does not know the type of a field at compile time.

Parameters
indexThe field index.

Definition at line 268 of file iter.hpp.

◆ field_at() [1/3]

void * flecs::iter::field_at ( int32_t index,
size_t row ) const
inline

Get pointer to field at row.

Definition at line 275 of file iter.hpp.

◆ field_at() [2/3]

template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value, void >::type * = nullptr>
const A & flecs::iter::field_at ( int32_t index,
size_t row ) const
inline

Get reference to field at row.

Definition at line 282 of file iter.hpp.

◆ field_at() [3/3]

template<typename T , typename A = actual_type_t<T>, typename std::enable_if< std::is_const< T >::value==false, void >::type * = nullptr>
A & flecs::iter::field_at ( int32_t index,
size_t row ) const
inline

Get reference to field at row.

Definition at line 290 of file iter.hpp.

◆ field_count()

int32_t flecs::iter::field_count ( ) const
inline

Number of fields in iterator.

Definition at line 185 of file iter.hpp.

◆ fini()

void flecs::iter::fini ( )
inline

Free iterator resources.

This operation only needs to be called when the iterator is not iterated until completion (e.g. the last call to next() did not return false).

Failing to call this operation on an unfinished iterator will throw a fatal LEAK_DETECTED error.

See also
ecs_iter_fini()

Definition at line 372 of file iter.hpp.

◆ get_var() [1/2]

flecs::entity flecs::iter::get_var ( const char * name) const
inline

Get value of variable by name.

Get value of a query variable for current result.

Definition at line 91 of file iter.hpp.

◆ get_var() [2/2]

flecs::entity flecs::iter::get_var ( int var_id) const
inline

Get value of variable by id.

Get value of a query variable for current result.

Definition at line 83 of file iter.hpp.

◆ group_id()

uint64_t flecs::iter::group_id ( ) const
inline

Definition at line 323 of file iter.hpp.

◆ id()

flecs::id flecs::iter::id ( int32_t index) const
inline

Obtain id matched for field.

Parameters
indexThe field index.

Definition at line 37 of file iter.hpp.

◆ is_readonly()

bool flecs::iter::is_readonly ( int32_t index) const
inline

Returns whether field is readonly.

Parameters
indexThe field index.

Definition at line 179 of file iter.hpp.

◆ is_self()

bool flecs::iter::is_self ( int32_t index) const
inline

Returns whether field is matched on self.

Parameters
indexThe field index.

Definition at line 163 of file iter.hpp.

◆ is_set()

bool flecs::iter::is_set ( int32_t index) const
inline

Returns whether field is set.

Parameters
indexThe field index.

Definition at line 171 of file iter.hpp.

◆ next()

bool flecs::iter::next ( )
inline

Progress iterator.

This operation should only be called from a context where the iterator is not being progressed automatically. An example of a valid context is inside of a run() callback. An example of an invalid context is inside of an each() callback.

Definition at line 343 of file iter.hpp.

◆ pair()

flecs::id flecs::iter::pair ( int32_t index) const
inline

Obtain pair id matched for field.

This operation will fail if the id is not a pair.

Parameters
indexThe field index.

Definition at line 41 of file iter.hpp.

◆ param() [1/2]

void * flecs::iter::param ( )
inline

Access param.

param contains the pointer passed to the param argument of system::run

Definition at line 140 of file iter.hpp.

◆ param() [2/2]

template<typename T >
T * flecs::iter::param ( )
inline

Access param.

param contains the pointer passed to the param argument of system::run

Definition at line 148 of file iter.hpp.

◆ range()

flecs::table_range flecs::iter::range ( ) const
inline

Definition at line 57 of file iter.hpp.

◆ size()

size_t flecs::iter::size ( int32_t index) const
inline

Size of field data type.

Parameters
indexThe field id.

Definition at line 193 of file iter.hpp.

◆ skip()

void flecs::iter::skip ( )
inline

Skip current table.

This indicates to the query that the data in the current table is not modified. By default, iterating a table with a query will mark the iterated components as dirty if they are annotated with InOut or Out.

When this operation is invoked, the components of the current table will not be marked dirty.

Definition at line 318 of file iter.hpp.

◆ src()

flecs::entity flecs::iter::src ( int32_t index) const
inline

Obtain field source (0 if This).

Parameters
indexThe field index.

Definition at line 33 of file iter.hpp.

◆ str()

flecs::string flecs::iter::str ( ) const
inline

Convert current iterator result to string.

Definition at line 232 of file iter.hpp.

◆ system()

flecs::entity flecs::iter::system ( ) const
inline

Definition at line 11 of file iter.hpp.

◆ table()

flecs::table flecs::iter::table ( ) const
inline

Definition at line 53 of file iter.hpp.

◆ term_index()

int32_t flecs::iter::term_index ( ) const
inline

Obtain term that triggered an observer.

Definition at line 226 of file iter.hpp.

◆ type()

flecs::type flecs::iter::type ( ) const
inline

Definition at line 49 of file iter.hpp.

◆ world()

flecs::world flecs::iter::world ( ) const
inline

Definition at line 23 of file iter.hpp.


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