Skip to content
Flecs v4.1
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 /** Reset the term to its default state. */
45 void reset() {
46 value = {};
47 this->set_term(nullptr);
48 }
49
50 /** Check if the term is initialized. */
51 bool is_set() {
53 }
54
55 /** Get the term ID. */
57 return flecs::id(world_, value.id);
58 }
59
60 /** Get the inout kind of the term. */
62 return static_cast<flecs::inout_kind_t>(value.inout);
63 }
64
65 /** Get the operator kind of the term. */
67 return static_cast<flecs::oper_kind_t>(value.oper);
68 }
69
70 /** Get the source entity of the term. */
72 return flecs::entity(world_, ECS_TERM_REF_ID(&value.src));
73 }
74
75 /** Get the first element of the term. */
77 return flecs::entity(world_, ECS_TERM_REF_ID(&value.first));
78 }
79
80 /** Get the second element of the term. */
82 return flecs::entity(world_, ECS_TERM_REF_ID(&value.second));
83 }
84
85 /** Convert to the underlying term_t. */
86 operator flecs::term_t() const {
87 return value;
88 }
89
90 /** The underlying term value. */
92
93protected:
94 flecs::world_t* world_v() override { return world_; }
95
96private:
97 flecs::world_t *world_;
98};
99
100/** Term mixin implementation. */
101template <typename... Args>
102inline flecs::term world::term(Args &&... args) const {
103 return flecs::term(world_, FLECS_FWD(args)...);
104}
105
106template <typename T>
107inline flecs::term world::term() const {
109}
110
111template <typename First, typename Second>
112inline flecs::term world::term() const {
113 return flecs::term(world_, ecs_pair(
116}
117
118}
flecs::term term() const
Create a term for a (component) type.
Definition impl.hpp:107
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:820
Type that describes a term (single element in a query).
Definition flecs.h:834
ecs_term_ref_t src
Source of term.
Definition flecs.h:840
ecs_id_t id
Component ID to be matched by term.
Definition flecs.h:835
int16_t oper
Operator of term.
Definition flecs.h:849
ecs_term_ref_t second
Second element of pair.
Definition flecs.h:842
int16_t inout
Access to contents matched by term.
Definition flecs.h:848
ecs_term_ref_t first
Component or first element of pair.
Definition flecs.h:841
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:51
flecs::entity get_src()
Get the source entity of the term.
Definition impl.hpp:71
flecs::id id()
Get the term ID.
Definition impl.hpp:56
void reset()
Reset the term to its default state.
Definition impl.hpp:45
flecs::entity get_first()
Get the first element of the term.
Definition impl.hpp:76
flecs::inout_kind_t inout()
Get the inout kind of the term.
Definition impl.hpp:61
flecs::entity get_second()
Get the second element of the term.
Definition impl.hpp:81
flecs::term_t value
The underlying term value.
Definition impl.hpp:91
flecs::oper_kind_t oper()
Get the operator kind of the term.
Definition impl.hpp:66
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1009
Term builder interface.