Flecs v3.2
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 : m_world(nullptr)
30 , m_id(0) { }
31
32 explicit id(flecs::id_t value)
33 : m_world(nullptr)
34 , m_id(value) { }
35
36 explicit id(flecs::world_t *world, flecs::id_t value = 0)
37 : m_world(world)
38 , m_id(value) { }
39
40 explicit id(flecs::world_t *world, flecs::id_t first, flecs::id_t second)
41 : m_world(world)
42 , m_id(ecs_pair(first, second)) { }
43
44 explicit id(flecs::id_t first, flecs::id_t second)
45 : m_world(nullptr)
46 , m_id(ecs_pair(first, second)) { }
47
48 explicit id(const flecs::id& first, const flecs::id& second)
49 : m_world(first.m_world)
50 , m_id(ecs_pair(first.m_id, second.m_id)) { }
51
53 bool is_pair() const {
54 return (m_id & ECS_ID_FLAGS_MASK) == flecs::Pair;
55 }
56
58 bool is_wildcard() const {
59 return ecs_id_is_wildcard(m_id);
60 }
61
63 bool is_entity() const {
64 return !(m_id & ECS_ID_FLAGS_MASK);
65 }
66
68 flecs::entity entity() const;
69
71 flecs::entity add_flags(flecs::id_t flags) const;
72
74 flecs::entity remove_flags(flecs::id_t flags) const;
75
78
81
83 flecs::entity type_id() const;
84
86 bool has_flags(flecs::id_t flags) const {
87 return ((m_id & flags) == flags);
88 }
89
91 bool has_flags() const {
92 return (m_id & ECS_ID_FLAGS_MASK) != 0;
93 }
94
96 flecs::entity flags() const;
97
99 bool has_relation(flecs::id_t first) const {
100 if (!is_pair()) {
101 return false;
102 }
103 return ECS_PAIR_FIRST(m_id) == first;
104 }
105
110 flecs::entity first() const;
111
116 flecs::entity second() const;
117
118 /* Convert id to string */
119 flecs::string str() const {
120 return flecs::string(ecs_id_str(m_world, m_id));
121 }
122
125 return flecs::string_view( ecs_id_flag_str(m_id & ECS_ID_FLAGS_MASK));
126 }
127
129 flecs::id_t raw_id() const {
130 return m_id;
131 }
132
133 operator flecs::id_t() const {
134 return m_id;
135 }
136
137 flecs::world world() const;
138
139protected:
140 /* World is optional, but guarantees that entity identifiers extracted from
141 * the id are valid */
142 flecs::world_t *m_world;
143 flecs::id_t m_id;
144};
145
148}
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 id to string.
bool ecs_id_is_wildcard(ecs_id_t id)
Utility to check if id is a wildcard.
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:53
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:99
bool has_flags(flecs::id_t flags) const
Test if id has specified role.
Definition decl.hpp:86
flecs::id_t raw_id() const
Return flecs::id_t value.
Definition decl.hpp:129
bool is_entity() const
Test if id is entity.
Definition decl.hpp:63
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:91
flecs::string flags_str() const
Convert role of id to string.
Definition decl.hpp:124
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:58
The world.
Definition world.hpp:132