Flecs: include/flecs/addons/cpp/mixins/term/impl.hpp Source File
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
impl.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "builder_i.hpp"
9
10namespace flecs {
11
16 struct term final : term_builder_i<term> {
18 term()
19 : term_builder_i<term>(&value)
20 , value({})
21 , world_(nullptr) { }
22
24 term(flecs::world_t *world_ptr)
25 : term_builder_i<term>(&value)
26 , value({})
27 , world_(world_ptr) { }
28
30 term(flecs::world_t *world_ptr, ecs_term_t t)
31 : term_builder_i<term>(&value)
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)
40 : term_builder_i<term>(&value)
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
52 term(flecs::world_t *world_ptr, entity_t first, entity_t second)
53 : term_builder_i<term>(&value)
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)
62 : term_builder_i<term>(&value)
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
73 term(id_t first, id_t second)
74 : term_builder_i<term>(&value)
75 , value({})
76 , world_(nullptr) {
77 value.first.id = first;
78 value.second.id = second;
79 }
80
82 void reset() {
83 value = {};
84 this->set_term(nullptr);
85 }
86
88 bool is_set() {
89 return ecs_term_is_initialized(&value);
90 }
91
93 flecs::id id() {
94 return flecs::id(world_, value.id);
95 }
96
98 flecs::inout_kind_t inout() {
99 return static_cast<flecs::inout_kind_t>(value.inout);
100 }
101
103 flecs::oper_kind_t oper() {
104 return static_cast<flecs::oper_kind_t>(value.oper);
105 }
106
108 flecs::entity get_src() {
109 return flecs::entity(world_, ECS_TERM_REF_ID(&value.src));
110 }
111
113 flecs::entity get_first() {
114 return flecs::entity(world_, ECS_TERM_REF_ID(&value.first));
115 }
116
118 flecs::entity get_second() {
119 return flecs::entity(world_, ECS_TERM_REF_ID(&value.second));
120 }
121
123 operator flecs::term_t() const {
124 return value;
125 }
126
128 flecs::term_t value;
129
130protected:
131 flecs::world_t* world_v() override { return world_; }
132
133private:
134 flecs::world_t *world_;
135};
136
138template <typename... Args>
139 inline flecs::term world::term(Args &&... args) const {
140 return flecs::term(world_, FLECS_FWD(args)...);
141}
142
143template <typename T>
144 inline flecs::term world::term() const {
145 return flecs::term(world_, _::type<T>::id(world_));
146}
147
148template <typename First, typename Second>
149 inline 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::world::term
flecs::term term() const
Create a term for a (component) type.
Definition impl.hpp:144
flecs::term_t
ecs_term_t term_t
Term type.
Definition c_types.hpp:24
flecs::id_t
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
flecs::oper_kind_t
oper_kind_t
Operator kind.
Definition c_types.hpp:49
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
flecs::inout_kind_t
inout_kind_t
Inout kind.
Definition c_types.hpp:39
ecs_term_is_initialized
bool ecs_term_is_initialized(const ecs_term_t *term)
Test whether a term is set.
ecs_term_ref_t::id
ecs_entity_t id
Entity ID.
Definition flecs.h:800
ecs_term_t
Type that describes a term (single element in a query).
Definition flecs.h:814
ecs_term_t::id
ecs_id_t id
Component ID to be matched by term.
Definition flecs.h:815
ecs_term_t::second
ecs_term_ref_t second
Second element of pair.
Definition flecs.h:822
ecs_term_t::first
ecs_term_ref_t first
Component or first element of pair.
Definition flecs.h:821
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
flecs::term_builder_i< term >::set_term
void set_term(ecs_term_t *term)
Definition builder_i.hpp:411
flecs::term_builder_i< term >::second
term & second()
Definition builder_i.hpp:135
flecs::term_builder_i< term >::term_builder_i
term_builder_i()
Definition builder_i.hpp:105
flecs::term_builder_i< term >::first
term & first()
Definition builder_i.hpp:127
flecs::term
Class that describes a term.
Definition impl.hpp:16
flecs::term::term
term(id_t first, id_t second)
Construct from a pair of IDs (no world).
Definition impl.hpp:73
flecs::term::term
term(id_t component_id)
Construct from a component ID (no world).
Definition impl.hpp:61
flecs::term::term
term(flecs::world_t *world_ptr, id_t component_id)
Construct from a world and a component ID.
Definition impl.hpp:39
flecs::term::term
term()
Default constructor.
Definition impl.hpp:18
flecs::term::term
term(flecs::world_t *world_ptr, ecs_term_t t)
Construct from a world and an existing term descriptor.
Definition impl.hpp:30
flecs::term::is_set
bool is_set()
Check if the term is initialized.
Definition impl.hpp:88
flecs::term::get_src
flecs::entity get_src()
Get the source entity of the term.
Definition impl.hpp:108
flecs::term::id
flecs::id id()
Get the term ID.
Definition impl.hpp:93
flecs::term::reset
void reset()
Reset the term to its default state.
Definition impl.hpp:82
flecs::term::get_first
flecs::entity get_first()
Get the first element of the term.
Definition impl.hpp:113
flecs::term::inout
flecs::inout_kind_t inout()
Get the inout kind of the term.
Definition impl.hpp:98
flecs::term::get_second
flecs::entity get_second()
Get the second element of the term.
Definition impl.hpp:118
flecs::term::value
flecs::term_t value
The underlying term value.
Definition impl.hpp:128
flecs::term::term
term(flecs::world_t *world_ptr)
Construct from a world.
Definition impl.hpp:24
flecs::term::term
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::term::oper
flecs::oper_kind_t oper()
Get the operator kind of the term.
Definition impl.hpp:103
flecs::world::world_
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1540
builder_i.hpp
Term builder interface.