Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Bool.hpp
1#pragma once
2
3#include "util/Assert.hpp"
4#include "util/prometheus/Gauge.hpp"
5
6#include <cstdint>
7#include <functional>
8
9namespace util::prometheus {
10
11template <typename T>
12concept SomeBoolImpl = requires(T a) {
13 { a.set(0) } -> std::same_as<void>;
14 { a.value() } -> std::same_as<int64_t>;
15};
16
21template <SomeBoolImpl ImplType>
22class AnyBool {
23 std::reference_wrapper<ImplType> impl_;
24
25public:
31 explicit AnyBool(ImplType& impl) : impl_(impl)
32 {
33 }
34
41 AnyBool&
42 operator=(bool value)
43 {
44 impl_.get().set(value ? 1 : 0);
45 return *this;
46 }
47
53 operator bool() const
54 {
55 auto const value = impl_.get().value();
56 ASSERT(value == 0 || value == 1, "Invalid value for bool: {}", value);
57 return value == 1;
58 }
59};
60
64using Bool = AnyBool<GaugeInt>;
65
66} // namespace util::prometheus
A wrapped to provide bool interface for a Prometheus metric.
Definition Bool.hpp:22
AnyBool(ImplType &impl)
Construct a bool metric.
Definition Bool.hpp:31
AnyBool & operator=(bool value)
Set the value of the bool metric.
Definition Bool.hpp:42
Definition Bool.hpp:12