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
66 /* Set retain period of alert.
67 *
68 * @see ecs_alert_desc_t::retain_period
69 */
70 Base& retain_period(ecs_ftime_t period) {
71 desc_->retain_period = period;
72 return *this;
73 }
74
79 template <typename Severity>
80 Base& severity() {
81 return severity(_::type<Severity>::id(world_v()));
82 }
83
85 Base& severity_filter(flecs::entity_t kind, flecs::id_t with, const char *var = nullptr) {
86 ecs_assert(severity_filter_count < ECS_ALERT_MAX_SEVERITY_FILTERS,
87 ECS_INVALID_PARAMETER, "Maximum number of severity filters reached");
88
89 ecs_alert_severity_filter_t *filter =
90 &desc_->severity_filters[severity_filter_count ++];
91
92 filter->severity = kind;
93 filter->with = with;
94 filter->var = var;
95 return *this;
96 }
97
99 template <typename Severity>
100 Base& severity_filter(flecs::id_t with, const char *var = nullptr) {
101 return severity_filter(_::type<Severity>::id(world_v()), with, var);
102 }
103
105 template <typename Severity, typename T, if_not_t< is_enum<T>::value > = 0>
106 Base& severity_filter(const char *var = nullptr) {
107 return severity_filter(_::type<Severity>::id(world_v()),
108 _::type<T>::id(world_v()), var);
109 }
110
112 template <typename Severity, typename T, if_t< is_enum<T>::value > = 0 >
113 Base& severity_filter(T with, const char *var = nullptr) {
114 flecs::world w(world_v());
115 flecs::entity constant = w.to_entity<T>(with);
116 return severity_filter(_::type<Severity>::id(world_v()),
117 w.pair<T>(constant), var);
118 }
119
121 Base& member(flecs::entity_t m) {
122 desc_->member = m;
123 return *this;
124 }
125
128 Base& id(flecs::id_t id) {
129 desc_->id = id;
130 return *this;
131 }
132
134 template <typename T>
135 Base& member(const char *m, const char *v = nullptr) {
136 flecs::entity_t id = _::type<T>::id(world_v());
137 flecs::entity_t mid = ecs_lookup_path_w_sep(
138 world_v(), id, m, "::", "::", false);
139 ecs_assert(m != 0, ECS_INVALID_PARAMETER, NULL);
140 desc_->var = v;
141 return this->member(mid);
142 }
143
145 Base& var(const char *v) {
146 desc_->var = v;
147 return *this;
148 }
149
150protected:
151 virtual flecs::world_t* world_v() = 0;
152
153private:
154 operator Base&() {
155 return *static_cast<Base*>(this);
156 }
157
158 ecs_alert_desc_t *desc_;
159 int32_t severity_filter_count = 0;
160};
161
162}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
flecs::component::constant
untyped_component & constant(const char *name, T value)
Add constant.
Definition untyped_component.inl:192
flecs::world::to_entity
flecs::entity to_entity(E constant) const
Convert enum constant to entity.
Definition impl.hpp:20
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)
Lookup 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:77
ecs_alert_desc_t::retain_period
ecs_ftime_t retain_period
The retain period specifies how long an alert must be inactive before it is cleared.
Definition alerts.h:120
ecs_alert_severity_filter_t
Alert severity filter.
Definition alerts.h:68
flecs::_::type
Definition flecs.hpp:39
flecs::alert_builder_i::severity_filter
Base & severity_filter(flecs::id_t with, const char *var=nullptr)
Add severity filter.
Definition builder_i.hpp:100
flecs::alert_builder_i::doc_name
Base & doc_name(const char *doc_name)
Set doc name for alert.
Definition builder_i.hpp:52
flecs::alert_builder_i::message
Base & message(const char *message)
Alert message.
Definition builder_i.hpp:34
flecs::alert_builder_i::severity_filter
Base & severity_filter(T with, const char *var=nullptr)
Add severity filter.
Definition builder_i.hpp:113
flecs::alert_builder_i::severity
Base & severity()
Set severity of alert (default is Error).
Definition builder_i.hpp:80
flecs::alert_builder_i::var
Base & var(const char *v)
Set source variable for member (optional, defaults to $this).
Definition builder_i.hpp:145
flecs::alert_builder_i::member
Base & member(const char *m, const char *v=nullptr)
Set member to create an alert for out of range values.
Definition builder_i.hpp:135
flecs::alert_builder_i::severity
Base & severity(flecs::entity_t kind)
Set severity of 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 severity filter.
Definition builder_i.hpp:85
flecs::alert_builder_i::member
Base & member(flecs::entity_t m)
Set member to create an alert for out of range values.
Definition builder_i.hpp:121
flecs::alert_builder_i::id
Base & id(flecs::id_t id)
Set (component) id for member (optional).
Definition builder_i.hpp:128
flecs::alert_builder_i::brief
Base & brief(const char *brief)
Set brief description for alert.
Definition builder_i.hpp:43
flecs::alert_builder_i::severity_filter
Base & severity_filter(const char *var=nullptr)
Add severity filter.
Definition builder_i.hpp:106
flecs::entity
Entity.
Definition entity.hpp:30
flecs::world
The world.
Definition world.hpp:158
flecs::world::pair
flecs::id pair() const
Get pair id from relationship, object.
Definition impl.hpp:80