rippled
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 <ripple/beast/insight/CounterImpl.h>
24 
25 #include <memory>
26 
27 namespace beast {
28 namespace insight {
29 
38 class Counter final
39 {
40 public:
42 
47  {
48  }
49 
55  explicit Counter (std::shared_ptr <CounterImpl> const& impl)
56  : m_impl (impl)
57  {
58  }
59 
62  void
63  increment (value_type amount) const
64  {
65  if (m_impl)
66  m_impl->increment (amount);
67  }
68 
69  Counter const&
70  operator+= (value_type amount) const
71  {
72  increment (amount);
73  return *this;
74  }
75 
76  Counter const&
77  operator-= (value_type amount) const
78  {
79  increment (-amount);
80  return *this;
81  }
82 
83  Counter const&
84  operator++ () const
85  {
86  increment (1);
87  return *this;
88  }
89 
90  Counter const&
91  operator++ (int) const
92  {
93  increment (1);
94  return *this;
95  }
96 
97  Counter const&
98  operator-- () const
99  {
100  increment (-1);
101  return *this;
102  }
103 
104  Counter const&
105  operator-- (int) const
106  {
107  increment (-1);
108  return *this;
109  }
110 
111 private:
113 };
114 
115 }
116 }
117 
118 #endif
beast::insight::Counter::m_impl
std::shared_ptr< CounterImpl > m_impl
Definition: Counter.h:112
beast::insight::Counter::operator+=
Counter const & operator+=(value_type amount) const
Definition: Counter.h:70
std::shared_ptr
STL class.
beast::insight::Counter
A metric for measuring an integral value.
Definition: Counter.h:38
beast::insight::CounterImpl::value_type
std::int64_t value_type
Definition: CounterImpl.h:35
std::int64_t
beast::insight::Counter::Counter
Counter(std::shared_ptr< CounterImpl > const &impl)
Create the metric reference the specified implementation.
Definition: Counter.h:55
beast::insight::Counter::operator--
Counter const & operator--() const
Definition: Counter.h:98
memory
beast::insight::Counter::Counter
Counter()
Create a null metric.
Definition: Counter.h:46
beast::insight::Counter::increment
void increment(value_type amount) const
Increment the counter.
Definition: Counter.h:63
beast::insight::Counter::operator-=
Counter const & operator-=(value_type amount) const
Definition: Counter.h:77
beast::insight::Counter::operator++
Counter const & operator++() const
Definition: Counter.h:84
beast
Definition: base_uint.h:582