Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
impl.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9
10template <typename E>
11inline E entity_view::to_constant() const {
12#ifdef FLECS_META
13 using U = typename std::underlying_type<E>::type;
14 const E* ptr = static_cast<const E*>(ecs_get_id(world_, id_,
15 ecs_pair(flecs::Constant, _::type<U>::id(world_))));
16 ecs_assert(ptr != NULL, ECS_INVALID_PARAMETER, "entity is not a constant");
17 return ptr[0];
18#else
19 ecs_assert(false, ECS_UNSUPPORTED,
20 "operation not supported without FLECS_META addon");
21 return E();
22#endif
23}
24
25template <typename E, if_t< is_enum<E>::value >>
26inline flecs::entity world::to_entity(E constant) const {
27 const auto& et = enum_type<E>(world_);
28 return flecs::entity(world_, et.entity(constant));
29}
30
31}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
E to_constant() const
Convert entity to enum constant.
Definition impl.hpp:11
flecs::entity to_entity(E constant) const
Convert enum constant to entity.
const void * ecs_get_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get an immutable pointer to a component.
Entity.
Definition entity.hpp:30