Flecs v4.0
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 {
22 type() : world_(nullptr), type_(nullptr) { }
23
24 type(world_t *world, const type_t *t)
25 : world_(world)
26 , type_(t) { }
27
30 return flecs::string(ecs_type_str(world_, type_));
31 }
32
34 int32_t count() const {
35 if (!type_) {
36 return 0;
37 }
38 return type_->count;
39 }
40
42 flecs::id_t* array() const {
43 if (!type_) {
44 return nullptr;
45 }
46 return type_->array;
47 }
48
50 flecs::id get(int32_t index) const {
51 ecs_assert(type_ != NULL, ECS_INVALID_PARAMETER, NULL);
52 ecs_assert(type_->count > index, ECS_OUT_OF_RANGE, NULL);
53 if (!type_) {
54 return flecs::id();
55 }
56 return flecs::id(world_, type_->array[index]);
57 }
58
59 flecs::id_t* begin() const {
60 return type_->array;
61 }
62
63 flecs::id_t* end() const {
64 return &type_->array[type_->count];
65 }
66
68 operator const type_t*() const {
69 return type_;
70 }
71private:
72 world_t *world_;
73 const type_t *type_;
74};
75
78}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
flecs::id_t * array() const
Return pointer to array.
Definition type.hpp:42
int32_t count() const
Return number of ids in type.
Definition type.hpp:34
flecs::string str() const
Convert type to comma-separated string.
Definition type.hpp:29
flecs::id get(int32_t index) const
Get id at specified index in type.
Definition type.hpp:50
char * ecs_type_str(const ecs_world_t *world, const ecs_type_t *type)
Convert type to string.
A type is a list of (component) ids.
Definition flecs.h:364
ecs_id_t * array
Array with ids.
Definition flecs.h:365
int32_t count
Number of elements in array.
Definition flecs.h:366
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Type class.
Definition type.hpp:21
The world.
Definition world.hpp:137