Flecs: flecs::query_base Struct Reference
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
flecs::query_base Struct Reference
C++ API » Core » Queries

Base class for queries. More...

`#include <impl.hpp>`

Inheritance diagram for flecs::query_base:
[legend]

## Public Member Functions
| query_base ()
| Default constructor.
| query_base (query_t *q)
| Construct from a mutable query pointer.
| query_base (const query_t *q)
| Construct from a const query pointer.
| query_base (world_t *world, const ecs_query_desc_t *desc)
| Construct from a world and a query descriptor.
| query_base (const query_base &obj)
| Copy constructor.
query_base & | operator= (const query_base &obj)
| Copy assignment operator.
| query_base (query_base &&obj) noexcept
| Move constructor.
query_base & | operator= (query_base &&obj) noexcept
| Move assignment operator.
flecs::entity | entity () const
| Get the entity associated with the query.
const flecs::query_t * | c_ptr () const
| Get a pointer to the underlying C query.
| operator const flecs::query_t * () const
| Convert to a const query pointer.
| operator bool () const
| Check if the query is valid.
void | destruct ()
| Free a persistent query.
| ~query_base ()
| Destructor.
bool | changed () const
| Return whether the query data changed since the last iteration.
const flecs::query_group_info_t * | group_info (uint64_t group_id) const
| Get info for a group.
flecs::map< uint64_t, void * > | groups () const
| Iterate the active groups of a grouped query.
void * | group_ctx (uint64_t group_id) const
| Get context for a group.
template<typename Func>
void | each_term (const Func &func)
| Iterate each term in the query, invoking a callback for each.
flecs::term | term (int32_t index) const
| Get term at the specified index.
int32_t | term_count () const
| Get the number of terms in the query.
int32_t | field_count () const
| Get the number of fields in the query.
int32_t | find_var (const char *name) const
| Find a variable by name.
bool | has (flecs::entity_t e) const
bool | has (const flecs::table &t) const
bool | has (const flecs::table_range &range) const
flecs::string | str () const
| Convert the query to a string expression.
flecs::string | plan () const
| Return a string representing the query plan.
| operator query<> () const
| Convert to a typed query.
flecs::string | to_json (flecs::iter_to_json_desc_t *desc=nullptr)
| Serialize a query to JSON.
flecs::string | to_json (flecs::iter_to_json_desc_t *desc=nullptr)
| Serialize a query to JSON.

## Protected Attributes
query_t * | query_ = nullptr

## Detailed Description

Base class for queries.

Definition at line 17 of file impl.hpp.

## Constructor & Destructor Documentation

## ◆ query_base() [1/6]

flecs::query_base::query_base | ( |  | ) |
| inline

Default constructor.

Definition at line 19 of file impl.hpp.

## ◆ query_base() [2/6]

flecs::query_base::query_base | ( | query_t * | q | ) |
| inline

Construct from a mutable query pointer.

Definition at line 22 of file impl.hpp.

## ◆ query_base() [3/6]

flecs::query_base::query_base | ( | const query_t * | q | ) |
| inline

Construct from a const query pointer.

Definition at line 28 of file impl.hpp.

## ◆ query_base() [4/6]

flecs::query_base::query_base | ( | world_t * | world,
|  | const ecs_query_desc_t * | desc )
| inline

Construct from a world and a query descriptor.

Definition at line 34 of file impl.hpp.

## ◆ query_base() [5/6]

flecs::query_base::query_base | ( | const query_base & | obj | ) |
| inline

Copy constructor.

Definition at line 49 of file impl.hpp.

## ◆ query_base() [6/6]

flecs::query_base::query_base | ( | query_base && | obj | ) |
| inlinenoexcept

Move constructor.

Definition at line 69 of file impl.hpp.

## ◆ ~query_base()

flecs::query_base::~query_base | ( |  | ) |
| inline

Destructor.

Only frees the query if it is not associated with an entity.

Definition at line 114 of file impl.hpp.

## Member Function Documentation

## ◆ c_ptr()

const flecs::query_t * flecs::query_base::c_ptr | ( |  | ) | const
| inline

Get a pointer to the underlying C query.

Definition at line 87 of file impl.hpp.

## ◆ changed()

bool flecs::query_base::changed | ( |  | ) | const
| inline

Return whether the query data changed since the last iteration.

This operation must be invoked before obtaining the iterator, as this will reset the changed state. The operation will return true after:

- new entities have been matched with
- matched entities were deleted
- matched components were changed

Returns
  true if entities changed, otherwise false.

Definition at line 132 of file impl.hpp.

## ◆ destruct()

void flecs::query_base::destruct | ( |  | ) |
| inline

Free a persistent query.

A persistent query is a query that is associated with an entity, such as system queries and named queries. Persistent queries must be deleted with destruct(), or will be deleted automatically at world cleanup.

Definition at line 106 of file impl.hpp.

## ◆ each_term()

template<typename Func>

void flecs::query_base::each_term | ( | const Func & | func | ) |
| inline

Iterate each term in the query, invoking a callback for each.

Definition at line 171 of file impl.hpp.

## ◆ entity()

flecs::entity flecs::query_base::entity | ( |  | ) | const
| inline

Get the entity associated with the query.

Definition at line 82 of file impl.hpp.

## ◆ field_count()

int32_t flecs::query_base::field_count | ( |  | ) | const
| inline

Get the number of fields in the query.

Definition at line 190 of file impl.hpp.

## ◆ find_var()

int32_t flecs::query_base::find_var | ( | const char * | name | ) | const
| inline

Find a variable by name.

Definition at line 195 of file impl.hpp.

## ◆ group_ctx()

void * flecs::query_base::group_ctx | ( | uint64_t | group_id | ) | const
| inline

Get context for a group.

Parameters

  group_id | The group ID for which to retrieve the context.

Returns
  The group context.

Definition at line 160 of file impl.hpp.

## ◆ group_info()

const flecs::query_group_info_t * flecs::query_base::group_info | ( | uint64_t | group_id | ) | const
| inline

Get info for a group.

Parameters

  group_id | The group ID for which to retrieve the info.

Returns
  The group info.

Definition at line 141 of file impl.hpp.

## ◆ groups()

flecs::map< uint64_t, void * > flecs::query_base::groups | ( |  | ) | const
| inline

Iterate the active groups of a grouped query.

Returns a range over (group_id, value) entries from the query's group map. The map value type is currently opaque, so V is exposed as void*.

Returns
  A flecs::map range over the query's active groups.

Definition at line 151 of file impl.hpp.

## ◆ has() [1/3]

bool flecs::query_base::has | ( | const flecs::table & | t | ) | const
| inline

Definition at line 208 of file impl.hpp.

## ◆ has() [2/3]

bool flecs::query_base::has | ( | const flecs::table_range & | range | ) | const
| inline

Definition at line 217 of file impl.hpp.

## ◆ has() [3/3]

bool flecs::query_base::has | ( | flecs::entity_t | e | ) | const
| inline

Definition at line 199 of file impl.hpp.

## ◆ operator bool()

flecs::query_base::operator bool | ( |  | ) | const
| inline

Check if the query is valid.

Definition at line 97 of file impl.hpp.

## ◆ operator const flecs::query_t *()

flecs::query_base::operator const flecs::query_t * | ( |  | ) | const
| inline

Convert to a const query pointer.

Definition at line 92 of file impl.hpp.

## ◆ operator=() [1/2]

query_base & flecs::query_base::operator= | ( | const query_base & | obj | ) |
| inline

Copy assignment operator.

Definition at line 58 of file impl.hpp.

## ◆ operator=() [2/2]

query_base & flecs::query_base::operator= | ( | query_base && | obj | ) |
| inlinenoexcept

Move assignment operator.

Definition at line 75 of file impl.hpp.

## ◆ plan()

flecs::string flecs::query_base::plan | ( |  | ) | const
| inline

Return a string representing the query plan.

This can be used to analyze the behavior and performance of the query.

See also
  ecs_query_plan()

Definition at line 241 of file impl.hpp.

## ◆ str()

flecs::string flecs::query_base::str | ( |  | ) | const
| inline

Convert the query to a string expression.

Definition at line 232 of file impl.hpp.

## ◆ term()

flecs::term flecs::query_base::term | ( | int32_t | index | ) | const
| inline

Get term at the specified index.

Definition at line 180 of file impl.hpp.

## ◆ term_count()

int32_t flecs::query_base::term_count | ( |  | ) | const
| inline

Get the number of terms in the query.

Definition at line 185 of file impl.hpp.

## ◆ to_json()

flecs::string to_json | ( | flecs::iter_to_json_desc_t * | desc = nullptr | ) |

Serialize a query to JSON.

Definition at line 11 of file query.inl.

## Member Data Documentation

## ◆ query_

query_t* flecs::query_base::query_ = nullptr
| protected

Definition at line 254 of file impl.hpp.

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

- include/flecs/addons/cpp/mixins/query/impl.hpp
- include/flecs/addons/cpp/mixins/json/query.inl