Skip to content
Flecs v4.1
impl.hpp
Go to the documentation of this file.
1/**
2 * @file addons/cpp/mixins/id/impl.hpp
3 * @brief ID class implementation.
4 */
5
6#pragma once
7
8namespace flecs {
9
10inline flecs::entity id::entity() const {
13 return flecs::entity(world_, id_);
14}
15
16inline flecs::entity id::flags() const {
17 return flecs::entity(world_, id_ & ECS_ID_FLAGS_MASK);
18}
19
20inline flecs::entity id::first() const {
22
23 flecs::entity_t e = ECS_PAIR_FIRST(id_);
24 if (world_) {
26 } else {
27 return flecs::entity(e);
28 }
29}
30
31inline flecs::entity id::second() const {
33
34 flecs::entity_t e = ECS_PAIR_SECOND(id_);
35 if (world_ && !is_value_pair()) {
37 } else {
38 return flecs::entity(e);
39 }
40}
41
43 return flecs::entity(world_, id_ | flags);
44}
45
47 (void)flags;
48 ecs_assert((id_ & ECS_ID_FLAGS_MASK) == flags, ECS_INVALID_PARAMETER, nullptr);
49 return flecs::entity(world_, id_ & ECS_COMPONENT_MASK);
50}
51
53 return flecs::entity(world_, id_ & ECS_COMPONENT_MASK);
54}
55
57 return flecs::entity(world_, static_cast<uint32_t>(id_));
58}
59
60inline flecs::world id::world() const {
61 return flecs::world(world_);
62}
63
64inline flecs::entity id::type_id() const {
66}
67
68
69// ID mixin implementation
70
71template <typename T>
72inline flecs::id world::id() const {
74}
75
76template <typename ... Args>
77inline flecs::id world::id(Args&&... args) const {
78 return flecs::id(world_, FLECS_FWD(args)...);
79}
80
81template <typename First, typename Second>
82inline flecs::id world::pair() const {
83 return flecs::id(
84 world_,
85 ecs_pair(
88}
89
90template <typename First>
92 ecs_assert(!ECS_IS_PAIR(o), ECS_INVALID_PARAMETER,
93 "cannot create nested pairs");
94
95 return flecs::id(
96 world_,
97 ecs_pair(
99 o));
100}
101
103 ecs_assert(!ECS_IS_PAIR(r) && !ECS_IS_PAIR(o), ECS_INVALID_PARAMETER,
104 "cannot create nested pairs");
105
106 return flecs::id(
107 world_,
108 ecs_pair(r, o));
109}
110
111}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
#define ECS_INVALID_OPERATION
Invalid operation error code.
Definition log.h:669
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:671
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t component)
Get the type for a component.
ecs_entity_t ecs_get_alive(const ecs_world_t *world, ecs_entity_t e)
Get an alive identifier.
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 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:60
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:52
flecs::entity type_id() const
Return component type of ID.
Definition impl.hpp:64
flecs::entity add_flags(flecs::id_t flags) const
Return ID with flags added.
Definition impl.hpp:42
flecs::id_t id_
The raw ID value.
Definition decl.hpp:154
bool is_value_pair() const
Test if ID is a value pair (has first, value).
Definition decl.hpp:62
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:152
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
flecs::entity remove_generation() const
Return ID without generation.
Definition impl.hpp:56
The world.
Definition world.hpp:129
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1009
flecs::id pair() const
Get pair ID from relationship and object.
Definition impl.hpp:82
flecs::id id() const
Get ID from a type.
Definition impl.hpp:72