Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
decl.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9
10struct id;
11struct entity;
12
27struct id {
28 id()
29 : world_(nullptr)
30 , id_(0) { }
31
32 explicit id(flecs::id_t value)
33 : world_(nullptr)
34 , id_(value) { }
35
36 explicit id(flecs::world_t *world, flecs::id_t value = 0)
37 : world_(world)
38 , id_(value) { }
39
40 explicit id(flecs::world_t *world, flecs::id_t first, flecs::id_t second)
41 : world_(world)
42 , id_(ecs_pair(first, second)) { }
43
44 explicit id(flecs::world_t *world, const char *expr)
45 : world_(world)
46 , id_(ecs_id_from_str(world, expr)) { }
47
48 explicit id(flecs::id_t first, flecs::id_t second)
49 : world_(nullptr)
50 , id_(ecs_pair(first, second)) { }
51
52 explicit id(const flecs::id& first, const flecs::id& second)
53 : world_(first.world_)
54 , id_(ecs_pair(first.id_, second.id_)) { }
55
57 bool is_pair() const {
58 return (id_ & ECS_ID_FLAGS_MASK) == flecs::PAIR;
59 }
60
62 bool is_wildcard() const {
63 return ecs_id_is_wildcard(id_);
64 }
65
67 bool is_entity() const {
68 return !(id_ & ECS_ID_FLAGS_MASK);
69 }
70
72 flecs::entity entity() const;
73
75 flecs::entity add_flags(flecs::id_t flags) const;
76
78 flecs::entity remove_flags(flecs::id_t flags) const;
79
82
85
87 flecs::entity type_id() const;
88
90 bool has_flags(flecs::id_t flags) const {
91 return ((id_ & flags) == flags);
92 }
93
95 bool has_flags() const {
96 return (id_ & ECS_ID_FLAGS_MASK) != 0;
97 }
98
100 flecs::entity flags() const;
101
103 bool has_relation(flecs::id_t first) const {
104 if (!is_pair()) {
105 return false;
106 }
107 return ECS_PAIR_FIRST(id_) == first;
108 }
109
114 flecs::entity first() const;
115
120 flecs::entity second() const;
121
122 /* Convert id to string */
123 flecs::string str() const {
124 return flecs::string(ecs_id_str(world_, id_));
125 }
126
129 return flecs::string_view( ecs_id_flag_str(id_ & ECS_ID_FLAGS_MASK));
130 }
131
133 flecs::id_t raw_id() const {
134 return id_;
135 }
136
137 operator flecs::id_t() const {
138 return id_;
139 }
140
141 flecs::world world() const;
142
143protected:
144 /* World is optional, but guarantees that entity identifiers extracted from
145 * the id are valid */
146 flecs::world_t *world_;
147 flecs::id_t id_;
148};
149
152}
const char * ecs_id_flag_str(ecs_id_t id_flags)
Convert id flag to string.
char * ecs_id_str(const ecs_world_t *world, ecs_id_t id)
Convert (component) id to string.
bool ecs_id_is_wildcard(ecs_id_t id)
Utility to check if id is a wildcard.
ecs_id_t ecs_id_from_str(const ecs_world_t *world, const char *expr)
Convert string to a (component) id.
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
bool is_pair() const
Test if id is pair (has first, second)
Definition decl.hpp:57
flecs::entity entity() const
Return id as entity (only allowed when id is valid entity)
Definition impl.hpp:10
flecs::entity flags() const
Return id flags set on id.
Definition impl.hpp:16
flecs::entity remove_flags() const
Return id without role.
Definition impl.hpp:50
flecs::entity type_id() const
Return component type of id.
Definition impl.hpp:62
flecs::entity add_flags(flecs::id_t flags) const
Return id with role added.
Definition impl.hpp:40
bool has_relation(flecs::id_t first) const
Test if id has specified first.
Definition decl.hpp:103
bool has_flags(flecs::id_t flags) const
Test if id has specified role.
Definition decl.hpp:90
flecs::id_t raw_id() const
Return flecs::id_t value.
Definition decl.hpp:133
bool is_entity() const
Test if id is entity.
Definition decl.hpp:67
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
bool has_flags() const
Test if id has any role.
Definition decl.hpp:95
flecs::string flags_str() const
Convert role of id to string.
Definition decl.hpp:128
flecs::entity remove_generation() const
Return id without role.
Definition impl.hpp:54
bool is_wildcard() const
Test if id is a wildcard.
Definition decl.hpp:62
The world.
Definition world.hpp:137