Flecs: include/flecs/addons/cpp/mixins/alerts/builder_i.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
builder_i.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "../query/builder_i.hpp"
9
10namespace flecs {
11
16template<typename Base, typename ... Components>
17 struct alert_builder_i : query_builder_i<Base, Components ...> {
18private:
19 using BaseClass = query_builder_i<Base, Components ...>;
20
21public:
22 alert_builder_i()
23 : BaseClass(nullptr)
24 , desc_(nullptr) { }
25
26 alert_builder_i(ecs_alert_desc_t *desc, int32_t term_index = 0)
27 : BaseClass(&desc->query, term_index)
28 , desc_(desc) { }
29
34 Base& message(const char *message) {
35 desc_->message = message;
36 return *this;
37 }
38
43 Base& brief(const char *brief) {
44 desc_->brief = brief;
45 return *this;
46 }
47
52 Base& doc_name(const char *doc_name) {
53 desc_->doc_name = doc_name;
54 return *this;
55 }
56
61 Base& severity(flecs::entity_t kind) {
62 desc_->severity = kind;
63 return *this;
64 }
65
70 Base& retain_period(ecs_ftime_t period) {
71 desc_->retain_period = period;
72 return *this;
73 }
74
80 template <typename Severity>
81 Base& severity() {
82 return severity(_::type<Severity>::id(world_v()));
83 }
84
91 Base& severity_filter(flecs::entity_t kind, flecs::id_t with, const char *var = nullptr) {
92 ecs_assert(severity_filter_count < ECS_ALERT_MAX_SEVERITY_FILTERS,
93 ECS_INVALID_PARAMETER, "Maximum number of severity filters reached");
94
95 ecs_alert_severity_filter_t *filter =
96 &desc_->severity_filters[severity_filter_count ++];
97
98 filter->severity = kind;
99 filter->with = with;
100 filter->var = var;
101 return *this;
102 }
103
110 template <typename Severity>
111 Base& severity_filter(flecs::id_t with, const char *var = nullptr) {
112 return severity_filter(_::type<Severity>::id(world_v()), with, var);
113 }
114
121 template <typename Severity, typename T, if_not_t< is_enum<T>::value > = 0>
122 Base& severity_filter(const char *var = nullptr) {
123 return severity_filter(_::type<Severity>::id(world_v()),
124 _::type<T>::id(world_v()), var);
125 }
126
134 template <typename Severity, typename T, if_t< is_enum<T>::value > = 0 >
135 Base& severity_filter(T with, const char *var = nullptr) {
136 flecs::world w(world_v());
137 flecs::entity constant = w.to_entity<T>(with);
138 return severity_filter(_::type<Severity>::id(world_v()),
139 w.pair<T>(constant), var);
140 }
141
143 Base& member(flecs::entity_t m) {
144 desc_->member = m;
145 return *this;
146 }
147
150 Base& id(flecs::id_t id) {
151 desc_->id = id;
152 return *this;
153 }
154
156 template <typename T>
157 Base& member(const char *m, const char *v = nullptr) {
158 flecs::entity_t id = _::type<T>::id(world_v());
159 flecs::entity_t mid = ecs_lookup_path_w_sep(
160 world_v(), id, m, "::", "::", false);
161 ecs_assert(mid != 0, ECS_INVALID_PARAMETER, NULL);
162 desc_->var = v;
163 return this->member(mid);
164 }
165
167 Base& var(const char *v) {
168 desc_->var = v;
169 return *this;
170 }
171
172protected:
173 virtual flecs::world_t* world_v() = 0;
174
175private:
176 operator Base&() {
177 return *static_cast<Base*>(this);
178 }
179
180 ecs_alert_desc_t *desc_;
181 int32_t severity_filter_count = 0;
182};
183
184}
ECS_ALERT_MAX_SEVERITY_FILTERS
#define ECS_ALERT_MAX_SEVERITY_FILTERS
Maximum number of severity filters per alert.
Definition alerts.h:32
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
ECS_INVALID_PARAMETER
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:661
flecs::component::constant
untyped_component & constant(const char *name, T value)
Add a constant.
Definition untyped_component.inl:186
flecs::world::to_entity
flecs::entity to_entity(E constant) const
Convert an enum constant to an entity.
Definition impl.hpp:20
flecs::id_t
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
ecs_ftime_t
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
ecs_lookup_path_w_sep
ecs_entity_t ecs_lookup_path_w_sep(const ecs_world_t *world, ecs_entity_t parent, const char *path, const char *sep, const char *prefix, bool recursive)
Look up an entity from a path.
builder_i.hpp
Query builder interface.
ecs_alert_desc_t
Alert descriptor, used with ecs_alert_init().
Definition alerts.h:78
ecs_alert_severity_filter_t
Alert severity filter.
Definition alerts.h:69
flecs::_::type
Definition flecs.hpp:39
flecs::alert_builder_i::severity_filter
Base & severity_filter(flecs::id_t with, const char *var=nullptr)
Add a severity filter.
Definition builder_i.hpp:111
flecs::alert_builder_i::doc_name
Base & doc_name(const char *doc_name)
Set the doc name for an alert.
Definition builder_i.hpp:52
flecs::alert_builder_i::retain_period
Base & retain_period(ecs_ftime_t period)
Set the retain period of an alert.
Definition builder_i.hpp:70
flecs::alert_builder_i::message
Base & message(const char *message)
Set the alert message.
Definition builder_i.hpp:34
flecs::alert_builder_i::severity_filter
Base & severity_filter(T with, const char *var=nullptr)
Add a severity filter.
Definition builder_i.hpp:135
flecs::alert_builder_i::severity
Base & severity()
Set the severity of an alert (default is Error).
Definition builder_i.hpp:81
flecs::alert_builder_i::var
Base & var(const char *v)
Set the source variable for member (optional, defaults to $this).
Definition builder_i.hpp:167
flecs::alert_builder_i::member
Base & member(const char *m, const char *v=nullptr)
Set the member to create an alert for out-of-range values.
Definition builder_i.hpp:157
flecs::alert_builder_i::severity
Base & severity(flecs::entity_t kind)
Set the severity of an alert (default is Error).
Definition builder_i.hpp:61
flecs::alert_builder_i::severity_filter
Base & severity_filter(flecs::entity_t kind, flecs::id_t with, const char *var=nullptr)
Add a severity filter.
Definition builder_i.hpp:91
flecs::alert_builder_i::member
Base & member(flecs::entity_t m)
Set the member to create an alert for out-of-range values.
Definition builder_i.hpp:143
flecs::alert_builder_i::id
Base & id(flecs::id_t id)
Set the (component) ID for the member (optional).
Definition builder_i.hpp:150
flecs::alert_builder_i::brief
Base & brief(const char *brief)
Set the brief description for an alert.
Definition builder_i.hpp:43
flecs::alert_builder_i::severity_filter
Base & severity_filter(const char *var=nullptr)
Add a severity filter.
Definition builder_i.hpp:122
flecs::entity
Entity.
Definition entity.hpp:30
flecs::query_builder_i< Base, Components ... >::with
Base & with()
Definition builder_i.hpp:65
flecs::query_builder_i< Base, Components ... >::query_builder_i
query_builder_i(ecs_query_desc_t *desc, int32_t term_index=0)
Definition builder_i.hpp:20
flecs::term_builder_i::filter
Base & filter()
Mark the term as a filter.
Definition builder_i.hpp:399
flecs::term_builder_i::desc
Base & desc()
Use with cascade() to iterate results in descending (bottom-to-top) order.
Definition builder_i.hpp:264
flecs::world
The world.
Definition world.hpp:246
flecs::world::pair
flecs::id pair() const
Get pair ID from relationship and object.
Definition impl.hpp:80