rippled
Loading...
Searching...
No Matches
Counter.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or 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#ifndef BEAST_INSIGHT_COUNTER_H_INCLUDED
21#define BEAST_INSIGHT_COUNTER_H_INCLUDED
22
23#include <xrpl/beast/insight/CounterImpl.h>
24
25#include <memory>
26
27namespace beast {
28namespace insight {
29
38class Counter final
39{
40public:
42
47 {
48 }
49
55 explicit Counter(std::shared_ptr<CounterImpl> const& impl) : m_impl(impl)
56 {
57 }
58
61 void
62 increment(value_type amount) const
63 {
64 if (m_impl)
65 m_impl->increment(amount);
66 }
67
68 Counter const&
69 operator+=(value_type amount) const
70 {
71 increment(amount);
72 return *this;
73 }
74
75 Counter const&
76 operator-=(value_type amount) const
77 {
78 increment(-amount);
79 return *this;
80 }
81
82 Counter const&
83 operator++() const
84 {
85 increment(1);
86 return *this;
87 }
88
89 Counter const&
90 operator++(int) const
91 {
92 increment(1);
93 return *this;
94 }
95
96 Counter const&
97 operator--() const
98 {
99 increment(-1);
100 return *this;
101 }
102
103 Counter const&
104 operator--(int) const
105 {
106 increment(-1);
107 return *this;
108 }
109
110private:
112};
113
114} // namespace insight
115} // namespace beast
116
117#endif
A metric for measuring an integral value.
Definition Counter.h:39
std::shared_ptr< CounterImpl > m_impl
Definition Counter.h:111
Counter()
Create a null metric.
Definition Counter.h:46
Counter const & operator--() const
Definition Counter.h:97
void increment(value_type amount) const
Increment the counter.
Definition Counter.h:62
Counter const & operator++(int) const
Definition Counter.h:90
Counter const & operator--(int) const
Definition Counter.h:104
Counter(std::shared_ptr< CounterImpl > const &impl)
Create the metric reference the specified implementation.
Definition Counter.h:55
Counter const & operator++() const
Definition Counter.h:83
Counter const & operator+=(value_type amount) const
Definition Counter.h:69
Counter const & operator-=(value_type amount) const
Definition Counter.h:76