Flecs v4.1
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
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
49 : world_(nullptr)
50 , id_(ecs_pair(first, second)) { }
51
52 explicit id(const flecs::id& first, const flecs::id& second)
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
76
79
82
85
87 flecs::entity type_id() const;
88
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
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
125 }
126
129 return flecs::string_view( ecs_id_flag_str(id_ & ECS_ID_FLAGS_MASK));
130 }
131
134 return id_;
135 }
136
137 operator flecs::id_t() const {
138 return id_;
139 }
140
142 flecs::world world() const;
143
144protected:
150};
151
154}
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
ecs_world_t world_t
World type.
Definition c_types.hpp:18
char * ecs_id_str(const ecs_world_t *world, ecs_id_t component)
Convert a component ID to a string.
const char * ecs_id_flag_str(uint64_t component_flags)
Convert a component flag to a string.
ecs_id_t ecs_id_from_str(const ecs_world_t *world, const char *expr)
Convert a string to a component.
bool ecs_id_is_wildcard(ecs_id_t component)
Utility to check if a component is a wildcard.
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
flecs::string str() const
Convert ID to string.
Definition decl.hpp:123
bool is_pair() const
Test if ID is a pair (has first, second).
Definition decl.hpp:57
flecs::entity entity() const
Return ID as entity (only allowed when ID is a valid entity).
Definition impl.hpp:10
flecs::world world() const
Get the world.
Definition impl.hpp:58
flecs::entity flags() const
Return ID flags set on ID.
Definition impl.hpp:16
flecs::entity remove_flags() const
Return ID without flags.
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 flags added.
Definition impl.hpp:40
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
bool has_relation(flecs::id_t first) const
Test if ID has the specified first element.
Definition decl.hpp:103
bool has_flags(flecs::id_t flags) const
Test if ID has specified flags.
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 an entity.
Definition decl.hpp:67
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Definition decl.hpp:147
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
bool has_flags() const
Test if ID has any flags.
Definition decl.hpp:95
flecs::string flags_str() const
Convert flags of ID to string.
Definition decl.hpp:128
flecs::entity remove_generation() const
Return ID without generation.
Definition impl.hpp:54
bool is_wildcard() const
Test if ID is a wildcard.
Definition decl.hpp:62
Non-owning string view.
Definition string.hpp:169
Owned string wrapper.
Definition string.hpp:15
The world.
Definition world.hpp:246