xrpld
Loading...
Searching...
No Matches
Gauge.h
1#pragma once
2
3#include <xrpl/beast/insight/GaugeImpl.h>
4
5#include <memory>
6#include <utility>
7
8namespace beast::insight {
9
20class Gauge final
21{
22public:
25
30 Gauge() = default;
31
39 {
40 }
41
49 void
50 set(value_type value) const
51 {
52 if (impl_)
53 impl_->set(value);
54 }
55
56 // This is a write-through handle: assignment sets the value of the
57 // referenced metric. It is const-qualified and returns Gauge const&
58 // (a non-const Gauge& would require a const_cast), so it does not follow
59 // the conventional assignment-operator signature.
60 // NOLINTNEXTLINE(misc-unconventional-assign-operator)
61 Gauge const&
62 operator=(value_type value) const
63 {
64 set(value);
65 return *this;
66 }
67
68
73 void
75 {
76 if (impl_)
77 impl_->increment(amount);
78 }
79
80 Gauge const&
82 {
83 increment(amount);
84 return *this;
85 }
86
87 Gauge const&
89 {
90 increment(-amount);
91 return *this;
92 }
93
94 Gauge const&
95 operator++() const
96 {
97 increment(1);
98 return *this;
99 }
100
101 Gauge const&
102 operator++(int) const
103 {
104 increment(1);
105 return *this;
106 }
107
108 Gauge const&
110 {
111 increment(-1);
112 return *this;
113 }
114
115 Gauge const&
116 operator--(int) const
117 {
118 increment(-1);
119 return *this;
120 }
121
122
123 [[nodiscard]] std::shared_ptr<GaugeImpl> const&
124 impl() const
125 {
126 return impl_;
127 }
128
129private:
131};
132
133} // namespace beast::insight
std::uint64_t value_type
Definition GaugeImpl.h:13
std::int64_t difference_type
Definition GaugeImpl.h:14
A metric for measuring an integral value.
Definition Gauge.h:21
Gauge const & operator+=(difference_type amount) const
Definition Gauge.h:81
std::shared_ptr< GaugeImpl > const & impl() const
Definition Gauge.h:124
Gauge()=default
Create a null metric.
Gauge const & operator++() const
Definition Gauge.h:95
void set(value_type value) const
Set the value on the gauge.
Definition Gauge.h:50
Gauge(std::shared_ptr< GaugeImpl > impl)
Create the metric reference the specified implementation.
Definition Gauge.h:38
GaugeImpl::value_type value_type
Definition Gauge.h:23
Gauge const & operator=(value_type value) const
Definition Gauge.h:62
GaugeImpl::difference_type difference_type
Definition Gauge.h:24
std::shared_ptr< GaugeImpl > impl_
Definition Gauge.h:130
Gauge const & operator--() const
Definition Gauge.h:109
Gauge const & operator++(int) const
Definition Gauge.h:102
Gauge const & operator-=(difference_type amount) const
Definition Gauge.h:88
void increment(difference_type amount) const
Adjust the value of the gauge.
Definition Gauge.h:74
Gauge const & operator--(int) const
Definition Gauge.h:116
STL namespace.