Clio
develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
CounterImpl.hpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of clio: https://github.com/XRPLF/clio
4
Copyright (c) 2023, the clio developers.
5
6
Permission to use, copy, modify, and distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#pragma once
21
22
#include "util/Atomic.hpp"
23
24
#include <type_traits>
25
26
namespace
util::prometheus::impl {
27
28
template
<
typename
T>
29
concept
SomeCounterImpl
=
requires
(T a) {
30
typename
std::remove_cvref_t<T>::ValueType;
31
requires
SomeNumberType<typename std::remove_cvref_t<T>::ValueType
>;
32
{ a.add(
typename
std::remove_cvref_t<T>::ValueType{1}) } -> std::same_as<void>;
33
{ a.set(
typename
std::remove_cvref_t<T>::ValueType{1}) } -> std::same_as<void>;
34
{ a.value() } ->
SomeNumberType
;
35
};
36
37
template
<SomeNumberType NumberType>
38
class
CounterImpl
{
39
public
:
40
using
ValueType = NumberType;
41
42
CounterImpl
() =
default
;
43
44
CounterImpl
(
CounterImpl
const
&) =
delete
;
45
46
CounterImpl
(
CounterImpl
&& other) =
default
;
47
48
CounterImpl
&
49
operator=(
CounterImpl
const
&) =
delete
;
50
CounterImpl
&
51
operator=(
CounterImpl
&&) =
default
;
52
53
void
54
add(ValueType
const
value)
55
{
56
value_->add(value);
57
}
58
59
void
60
set(ValueType
const
value)
61
{
62
value_->set(value);
63
}
64
65
ValueType
66
value()
const
67
{
68
return
value_->value();
69
}
70
71
private
:
72
AtomicPtr<ValueType> value_ = std::make_unique<Atomic<ValueType>>(0);
73
};
74
75
}
// namespace util::prometheus::impl
util::prometheus::impl::CounterImpl
Definition
CounterImpl.hpp:38
util::SomeNumberType
Specifies a number type.
Definition
Concepts.hpp:34
util::prometheus::impl::SomeCounterImpl
Definition
CounterImpl.hpp:29
src
util
prometheus
impl
CounterImpl.hpp
Generated by
1.12.0