Flecs: include/flecs/addons/cpp/mixins/metrics/builder.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.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8namespace flecs {
9
14
16 struct metric_builder {
18 metric_builder(flecs::world_t *world, flecs::entity_t entity)
19 : world_(world)
20 {
21 desc_.entity = entity;
22 }
23
25 ~metric_builder();
26
28 metric_builder& member(flecs::entity_t e) {
29 desc_.member = e;
30 return *this;
31 }
32
34 metric_builder& member(const char *name);
35
37 template <typename T>
38 metric_builder& member(const char *name);
39
41 metric_builder& dotmember(const char *name);
42
44 template <typename T>
45 metric_builder& dotmember(const char *name);
46
48 metric_builder& id(flecs::id_t the_id) {
49 desc_.id = the_id;
50 return *this;
51 }
52
54 metric_builder& id(flecs::entity_t first, flecs::entity_t second) {
55 desc_.id = ecs_pair(first, second);
56 return *this;
57 }
58
60 template <typename T>
61 metric_builder& id() {
62 return id(_::type<T>::id(world_));
63 }
64
66 template <typename First>
67 metric_builder& id(flecs::entity_t second) {
68 return id(_::type<First>::id(world_), second);
69 }
70
72 template <typename Second>
73 metric_builder& id_second(flecs::entity_t first) {
74 return id(first, _::type<Second>::id(world_));
75 }
76
78 template <typename First, typename Second>
79 metric_builder& id() {
80 return id<First>(_::type<Second>::id(world_));
81 }
82
84 metric_builder& targets(bool value = true) {
85 desc_.targets = value;
86 return *this;
87 }
88
90 metric_builder& kind(flecs::entity_t the_kind) {
91 desc_.kind = the_kind;
92 return *this;
93 }
94
96 template <typename Kind>
97 metric_builder& kind() {
98 return kind(_::type<Kind>::id(world_));
99 }
100
102 metric_builder& brief(const char *b) {
103 desc_.brief = b;
104 return *this;
105 }
106
108 operator flecs::entity();
109
110protected:
111 flecs::world_t *world_;
112 ecs_metric_desc_t desc_ = {};
113 bool created_ = false;
114};
115
119
120}
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_metric_desc_t
Used with ecs_metric_init() to create metric.
Definition metrics.h:76
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::metric_builder
Metric builder interface.
Definition builder.hpp:16
flecs::metric_builder::entity
operator flecs::entity()
Finalize the metric and return the entity.
Definition impl.hpp:71
flecs::metric_builder::id
metric_builder & id(flecs::entity_t first, flecs::entity_t second)
Set the ID for the metric as a pair.
Definition builder.hpp:54
flecs::metric_builder::kind
metric_builder & kind()
Set the metric kind by type.
Definition builder.hpp:97
flecs::metric_builder::id
metric_builder & id(flecs::entity_t second)
Set the ID for the metric as a pair with type First.
Definition builder.hpp:67
flecs::metric_builder::~metric_builder
~metric_builder()
Destructor.
Definition impl.hpp:27
flecs::metric_builder::brief
metric_builder & brief(const char *b)
Set a brief description for the metric.
Definition builder.hpp:102
flecs::metric_builder::id
metric_builder & id(flecs::id_t the_id)
Set the ID for the metric.
Definition builder.hpp:48
flecs::metric_builder::metric_builder
metric_builder(flecs::world_t *world, flecs::entity_t entity)
Construct a metric builder.
Definition builder.hpp:18
flecs::metric_builder::id_second
metric_builder & id_second(flecs::entity_t first)
Set the ID for the metric as a pair with type Second.
Definition builder.hpp:73
flecs::metric_builder::id
metric_builder & id()
Set the ID for the metric by type.
Definition builder.hpp:61
flecs::metric_builder::targets
metric_builder & targets(bool value=true)
Set whether to create metrics for targets.
Definition builder.hpp:84
flecs::metric_builder::dotmember
metric_builder & dotmember(const char *name)
Set the member to use for the metric using dot notation.
Definition impl.hpp:59
flecs::metric_builder::id
metric_builder & id()
Set the ID for the metric as a pair with types First and Second.
Definition builder.hpp:79
flecs::metric_builder::member
metric_builder & member(flecs::entity_t e)
Set the member to use for the metric by entity ID.
Definition builder.hpp:28
flecs::metric_builder::kind
metric_builder & kind(flecs::entity_t the_kind)
Set the metric kind (e.g., Counter, Gauge).
Definition builder.hpp:90
flecs::world
The world.
Definition world.hpp:246