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
13
19template <typename T>
20concept SomeBoolImpl = requires(T a) {
21 { a.set(0) } -> std::same_as<void>;
22 { a.value() } -> std::same_as<int64_t>;
23};
24
31template <SomeBoolImpl ImplType>
32class AnyBool {
33 std::reference_wrapper<ImplType> impl_;
34
35public:
41 explicit AnyBool(ImplType& impl) : impl_(impl)
42 {
43 }
44
51 AnyBool&
52 operator=(bool value)
53 {
54 impl_.get().set(value ? 1 : 0);
55 return *this;
56 }
57
63 operator bool() const
64 {
65 auto const value = impl_.get().value();
66 ASSERT(value == 0 || value == 1, "Invalid value for bool: {}", value);
67 return value == 1;
68 }
69};
70
75
76} // namespace util::prometheus
A wrapped to provide bool interface for a Prometheus metric.
Definition Bool.hpp:32
AnyBool(ImplType &impl)
Construct a bool metric.
Definition Bool.hpp:41
AnyBool & operator=(bool value)
Set the value of the bool metric.
Definition Bool.hpp:52
Specifies an integer metric implementation that can back AnyBool (e.g. GaugeInt).
Definition Bool.hpp:20
Prometheus metrics: counters, gauges, histograms and their registry and serialization.
Definition Bool.hpp:12
AnyBool< GaugeInt > Bool
Alias for Prometheus bool metric with GaugeInt implementation.
Definition Bool.hpp:74