Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AnyCounterBase.hpp
1#pragma once
2
3#include "util/Concepts.hpp"
4#include "util/prometheus/impl/CounterImpl.hpp"
5
6#include <concepts>
7#include <memory>
8#include <type_traits>
9
10namespace util::prometheus::impl {
11
12template <SomeNumberType NumberType>
13class AnyCounterBase {
14public:
15 using ValueType = NumberType;
16
17 template <SomeCounterImpl ImplType = CounterImpl<ValueType>>
18 requires std::same_as<ValueType, typename std::remove_cvref_t<ImplType>::ValueType>
19 AnyCounterBase(ImplType&& impl = ImplType{})
20 : pimpl_(std::make_unique<Model<ImplType>>(std::forward<ImplType>(impl)))
21 {
22 }
23
24protected:
25 struct Concept {
26 virtual ~Concept() = default;
27
28 virtual void add(ValueType) = 0;
29
30 virtual void set(ValueType) = 0;
31
32 virtual ValueType
33 value() const = 0;
34 };
35
36 template <SomeCounterImpl ImplType>
37 struct Model : Concept {
38 template <SomeCounterImpl SomeImplType>
39 requires std::same_as<ImplType, SomeImplType>
40 Model(SomeImplType&& impl) : impl(std::forward<SomeImplType>(impl))
41 {
42 }
43
44 void
45 add(ValueType value) override
46 {
47 impl.add(value);
48 }
49
50 void
51 set(ValueType v) override
52 {
53 impl.set(v);
54 }
55
56 ValueType
57 value() const override
58 {
59 return impl.value();
60 }
61
62 ImplType impl;
63 };
64
65 std::unique_ptr<Concept> pimpl_;
66};
67
68} // namespace util::prometheus::impl
Definition AnyCounterBase.hpp:25
Definition AnyCounterBase.hpp:37