Skip to content
Flecs v4.2
impl.hpp
Go to the documentation of this file.
1/**
2 * @file addons/cpp/mixins/term/impl.hpp
3 * @brief Term implementation.
4 */
5
6#pragma once
7
8#include "builder_i.hpp"
9
10namespace flecs {
11
12/** Class that describes a term.
13 *
14 * @ingroup cpp_core_queries
15 */
16struct term final : term_builder_i<term> {
17 term() : term(nullptr) { }
18
19 term(flecs::world_t *world_ptr, ecs_term_t t = {})
21 , value(t)
22 , world_(world_ptr) { }
23
24 term(flecs::world_t *world_ptr, id_t component_id)
25 : term(world_ptr)
26 {
27 if (component_id & ECS_ID_FLAGS_MASK) {
28 value.id = component_id;
29 } else {
30 value.first.id = component_id;
31 }
32 }
33
34 term(flecs::world_t *world_ptr, entity_t first, entity_t second)
35 : term(world_ptr, ecs_pair(first, second)) { }
36
37 term(id_t component_id) : term(nullptr, component_id) { }
38
39 term(id_t first, id_t second) : term() {
40 value.first.id = first;
41 value.second.id = second;
42 }
43
44 term(const term& t)
46 , value(t.value)
47 , world_(t.world_)
48 {
49 this->set_term(&value, t);
50 }
51
52 term(term&& t) noexcept : term(t) { }
53
54 term& operator=(const term& t) {
55 value = t.value;
56 world_ = t.world_;
57 this->set_term(&value, t);
58 return *this;
59 }
60
61 term& operator=(term&& t) noexcept {
62 return *this = t;
63 }
64
65 /** Reset the term to its default state. */
66 void reset() {
67 value = {};
68 this->set_term(nullptr);
69 }
70
71 /** Check if the term is initialized. */
72 bool is_set() {
74 }
75
76 /** Get the term ID. */
78 return flecs::id(world_, value.id);
79 }
80
81 /** Get the inout kind of the term. */
83 return static_cast<flecs::inout_kind_t>(value.inout);
84 }
85
86 /** Get the operator kind of the term. */
88 return static_cast<flecs::oper_kind_t>(value.oper);
89 }
90
91 /** Get the source entity of the term. */
93 return flecs::entity(world_, ECS_TERM_REF_ID(&value.src));
94 }
95
96 /** Get the first element of the term. */
98 return flecs::entity(world_, ECS_TERM_REF_ID(&value.first));
99 }
100
101 /** Get the second element of the term. */
103 return flecs::entity(world_, ECS_TERM_REF_ID(&value.second));
104 }
105
106 /** Convert to the underlying term_t. */
107 operator flecs::term_t() const {
108 return value;
109 }
110
111 /** The underlying term value. */
113
114protected:
115 flecs::world_t* world_v() override { return world_; }
116
117private:
118 flecs::world_t *world_;
119};
120
121/** Term mixin implementation. */
122template <typename... Args>
123inline flecs::term world::term(Args &&... args) const {
124 return flecs::term(world_, FLECS_FWD(args)...);
125}
126
127template <typename T>
128inline flecs::term world::term() const {
130}
131
132template <typename First, typename Second>
133inline flecs::term world::term() const {
134 return flecs::term(world_, ecs_pair(
137}
138
139}
flecs::term term() const
Create a term for a (component) type.
Definition impl.hpp:128
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:821
Type that describes a term (single element in a query).
Definition flecs.h:835
ecs_term_ref_t src
Source of term.
Definition flecs.h:841
ecs_id_t id
Component ID to be matched by term.
Definition flecs.h:836
int16_t oper
Operator of term.
Definition flecs.h:850
ecs_term_ref_t second
Second element of pair.
Definition flecs.h:843
int16_t inout
Access to contents matched by term.
Definition flecs.h:849
ecs_term_ref_t first
Component or first element of pair.
Definition flecs.h:842
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
void set_term(ecs_term_t *term)
Class that describes a term.
Definition impl.hpp:16
bool is_set()
Check if the term is initialized.
Definition impl.hpp:72
flecs::entity get_src()
Get the source entity of the term.
Definition impl.hpp:92
flecs::id id()
Get the term ID.
Definition impl.hpp:77
void reset()
Reset the term to its default state.
Definition impl.hpp:66
flecs::entity get_first()
Get the first element of the term.
Definition impl.hpp:97
flecs::inout_kind_t inout()
Get the inout kind of the term.
Definition impl.hpp:82
flecs::entity get_second()
Get the second element of the term.
Definition impl.hpp:102
flecs::term_t value
The underlying term value.
Definition impl.hpp:112
flecs::oper_kind_t oper()
Get the operator kind of the term.
Definition impl.hpp:87
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:866
Term builder interface.