Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
type.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9
21struct type {
23 type() : world_(nullptr), type_(nullptr) { }
24
31 : world_(world)
32 , type_(t) { }
33
39 return flecs::string(ecs_type_str(world_, type_));
40 }
41
46 int32_t count() const {
47 if (!type_) {
48 return 0;
49 }
50 return type_->count;
51 }
52
57 flecs::id_t* array() const {
58 if (!type_) {
59 return nullptr;
60 }
61 return type_->array;
62 }
63
69 flecs::id get(int32_t index) const {
70 ecs_assert(type_ != NULL, ECS_INVALID_PARAMETER, NULL);
71 ecs_assert(type_->count > index, ECS_OUT_OF_RANGE, NULL);
72 if (!type_) {
73 return flecs::id();
74 }
75 return flecs::id(world_, type_->array[index]);
76 }
77
79 const flecs::id_t* begin() const {
80 if (type_ && type_->count) {
81 return type_->array;
82 } else {
83 return &empty_;
84 }
85 }
86
88 const flecs::id_t* end() const {
89 if (type_ && type_->count) {
90 return &type_->array[type_->count];
91 } else {
92 return &empty_;
93 }
94 }
95
97 operator const type_t*() const {
98 return type_;
99 }
100private:
101 world_t *world_;
102 const type_t *type_;
103 flecs::id_t empty_;
104};
105
108}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
#define ECS_OUT_OF_RANGE
Out of range error code.
Definition log.h:677
#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_world_t world_t
World type.
Definition c_types.hpp:18
char * ecs_type_str(const ecs_world_t *world, const ecs_type_t *type)
Convert a type to a string.
A type is a list of (component) IDs.
Definition flecs.h:402
ecs_id_t * array
Array with IDs.
Definition flecs.h:403
int32_t count
Number of elements in array.
Definition flecs.h:404
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Owned string wrapper.
Definition string.hpp:15
Type class.
Definition type.hpp:21
const flecs::id_t * end() const
Get an iterator to the end of the type's ID array.
Definition type.hpp:88
flecs::id_t * array() const
Return a pointer to the ID array.
Definition type.hpp:57
int32_t count() const
Return the number of IDs in the type.
Definition type.hpp:46
flecs::string str() const
Convert the type to a comma-separated string.
Definition type.hpp:38
type()
Default constructor.
Definition type.hpp:23
flecs::id get(int32_t index) const
Get the ID at a specified index in the type.
Definition type.hpp:69
type(world_t *world, const type_t *t)
Construct a type from a world and C type pointer.
Definition type.hpp:30
const flecs::id_t * begin() const
Get an iterator to the beginning of the type's ID array.
Definition type.hpp:79
The world.
Definition world.hpp:246