Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
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
9
namespace
util::prometheus {
10
11
template
<
typename
T>
12
concept
SomeBoolImpl
=
requires
(T a) {
13
{ a.set(0) } -> std::same_as<void>;
14
{ a.value() } -> std::same_as<int64_t>;
15
};
16
21
template
<SomeBoolImpl ImplType>
22
class
AnyBool
{
23
std::reference_wrapper<ImplType> impl_;
24
25
public
:
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
64
using
Bool = AnyBool<GaugeInt>;
65
66
}
// namespace util::prometheus
util::prometheus::AnyBool
A wrapped to provide bool interface for a Prometheus metric.
Definition
Bool.hpp:22
util::prometheus::AnyBool::AnyBool
AnyBool(ImplType &impl)
Construct a bool metric.
Definition
Bool.hpp:31
util::prometheus::AnyBool::operator=
AnyBool & operator=(bool value)
Set the value of the bool metric.
Definition
Bool.hpp:42
util::prometheus::SomeBoolImpl
Definition
Bool.hpp:12
src
util
prometheus
Bool.hpp
Generated by
1.16.1