Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
impl.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include "builder_i.hpp"
9
10namespace flecs {
11
16struct term final : term_builder_i<term> {
20 , value({})
21 , world_(nullptr) { }
22
24 term(flecs::world_t *world_ptr)
26 , value({})
27 , world_(world_ptr) { }
28
32 , value({})
33 , world_(world_ptr) {
34 value = t;
35 this->set_term(&value);
36 }
37
39 term(flecs::world_t *world_ptr, id_t component_id)
41 , value({})
42 , world_(world_ptr) {
43 if (component_id & ECS_ID_FLAGS_MASK) {
44 value.id = component_id;
45 } else {
46 value.first.id = component_id;
47 }
48 this->set_term(&value);
49 }
50
54 , value({})
55 , world_(world_ptr) {
56 value.id = ecs_pair(first, second);
57 this->set_term(&value);
58 }
59
61 term(id_t component_id)
63 , value({})
64 , world_(nullptr) {
65 if (component_id & ECS_ID_FLAGS_MASK) {
66 value.id = component_id;
67 } else {
68 value.first.id = component_id;
69 }
70 }
71
75 , value({})
76 , world_(nullptr) {
79 }
80
82 void reset() {
83 value = {};
84 this->set_term(nullptr);
85 }
86
88 bool is_set() {
90 }
91
94 return flecs::id(world_, value.id);
95 }
96
99 return static_cast<flecs::inout_kind_t>(value.inout);
100 }
101
104 return static_cast<flecs::oper_kind_t>(value.oper);
105 }
106
109 return flecs::entity(world_, ECS_TERM_REF_ID(&value.src));
110 }
111
114 return flecs::entity(world_, ECS_TERM_REF_ID(&value.first));
115 }
116
119 return flecs::entity(world_, ECS_TERM_REF_ID(&value.second));
120 }
121
123 operator flecs::term_t() const {
124 return value;
125 }
126
129
130protected:
131 flecs::world_t* world_v() override { return world_; }
132
133private:
134 flecs::world_t *world_;
135};
136
138template <typename... Args>
139inline flecs::term world::term(Args &&... args) const {
140 return flecs::term(world_, FLECS_FWD(args)...);
141}
142
143template <typename T>
144inline flecs::term world::term() const {
145 return flecs::term(world_, _::type<T>::id(world_));
146}
147
148template <typename First, typename Second>
149inline flecs::term world::term() const {
150 return flecs::term(world_, ecs_pair(
151 _::type<First>::id(world_),
152 _::type<Second>::id(world_)));
153}
154
155}
flecs::term term() const
Create a term for a (component) type.
ecs_term_t term_t
Term type.
Definition c_types.hpp:24
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
oper_kind_t
Operator kind.
Definition c_types.hpp:49
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_world_t world_t
World type.
Definition c_types.hpp:18
inout_kind_t
Inout kind.
Definition c_types.hpp:39
bool ecs_term_is_initialized(const ecs_term_t *term)
Test whether a term is set.
ecs_entity_t id
Entity ID.
Definition flecs.h:796
Type that describes a term (single element in a query).
Definition flecs.h:810
ecs_term_ref_t src
Source of term.
Definition flecs.h:816
ecs_id_t id
Component ID to be matched by term.
Definition flecs.h:811
int16_t oper
Operator of term.
Definition flecs.h:825
ecs_term_ref_t second
Second element of pair.
Definition flecs.h:818
int16_t inout
Access to contents matched by term.
Definition flecs.h:824
ecs_term_ref_t first
Component or first element of pair.
Definition flecs.h:817
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Term builder interface.
void set_term(ecs_term_t *term)
Set the current term pointer.
term & second()
Call prior to setting values for the second identifier.
term & first()
Call prior to setting values for the first identifier.
Class that describes a term.
Definition impl.hpp:16
term(id_t first, id_t second)
Construct from a pair of IDs (no world).
Definition impl.hpp:73
term(id_t component_id)
Construct from a component ID (no world).
Definition impl.hpp:61
term(flecs::world_t *world_ptr, id_t component_id)
Construct from a world and a component ID.
Definition impl.hpp:39
term()
Default constructor.
Definition impl.hpp:18
term(flecs::world_t *world_ptr, ecs_term_t t)
Construct from a world and an existing term descriptor.
Definition impl.hpp:30
bool is_set()
Check if the term is initialized.
Definition impl.hpp:88
flecs::entity get_src()
Get the source entity of the term.
Definition impl.hpp:108
flecs::id id()
Get the term ID.
Definition impl.hpp:93
void reset()
Reset the term to its default state.
Definition impl.hpp:82
flecs::entity get_first()
Get the first element of the term.
Definition impl.hpp:113
flecs::inout_kind_t inout()
Get the inout kind of the term.
Definition impl.hpp:98
flecs::entity get_second()
Get the second element of the term.
Definition impl.hpp:118
flecs::term_t value
The underlying term value.
Definition impl.hpp:128
term(flecs::world_t *world_ptr)
Construct from a world.
Definition impl.hpp:24
term(flecs::world_t *world_ptr, entity_t first, entity_t second)
Construct from a world and a pair of entity IDs.
Definition impl.hpp:52
flecs::oper_kind_t oper()
Get the operator kind of the term.
Definition impl.hpp:103
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1545
Term builder interface.