Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
builder_i.hpp
Go to the documentation of this file.
1
6#pragma once
7
9
10namespace flecs {
11
16template<typename Base, typename ... Components>
17struct alert_builder_i : query_builder_i<Base, Components ...> {
18private:
19 using BaseClass = query_builder_i<Base, Components ...>;
20
21public:
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
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}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
flecs::entity to_entity(E constant) const
Convert enum constant to entity.
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
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.
Query builder interface.
Alert descriptor, used with ecs_alert_init().
Definition alerts.h:77
ecs_alert_severity_filter_t severity_filters[(4)]
Severity filters can be used to assign different severities to the same alert.
Definition alerts.h:113
const char * brief
Description of alert.
Definition alerts.h:103
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_entity_t member
Alert when member value is out of range.
Definition alerts.h:124
ecs_id_t id
(Component) id of member to monitor.
Definition alerts.h:128
ecs_entity_t severity
Metric kind.
Definition alerts.h:107
ecs_query_desc_t query
Alert query.
Definition alerts.h:86
const char * doc_name
User friendly name.
Definition alerts.h:100
const char * message
Template for alert message.
Definition alerts.h:97
const char * var
Variable from which to fetch the member (optional).
Definition alerts.h:132
Alert severity filter.
Definition alerts.h:68
Alert builder interface.
Definition builder_i.hpp:17
Base & severity_filter(flecs::id_t with, const char *var=nullptr)
Add severity filter.
Base & doc_name(const char *doc_name)
Set doc name for alert.
Definition builder_i.hpp:52
Base & message(const char *message)
Alert message.
Definition builder_i.hpp:34
Base & severity_filter(T with, const char *var=nullptr)
Add severity filter.
Base & severity()
Set severity of alert (default is Error)
Definition builder_i.hpp:80
Base & var(const char *v)
Set source variable for member (optional, defaults to $this)
Base & member(const char *m, const char *v=nullptr)
Set member to create an alert for out of range values.
Base & severity(flecs::entity_t kind)
Set severity of alert (default is Error)
Definition builder_i.hpp:61
Base & severity_filter(flecs::entity_t kind, flecs::id_t with, const char *var=nullptr)
Add severity filter.
Definition builder_i.hpp:85
Base & member(flecs::entity_t m)
Set member to create an alert for out of range values.
Base & id(flecs::id_t id)
Set (component) id for member (optional).
Base & brief(const char *brief)
Set brief description for alert.
Definition builder_i.hpp:43
Base & severity_filter(const char *var=nullptr)
Add severity filter.
Entity.
Definition entity.hpp:30
Query builder interface.
Definition builder_i.hpp:18
The world.
Definition world.hpp:137
flecs::id pair() const
Get pair id from relationship, object.