counter.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_CORE_COUNTER_HPP
27 #define NFD_CORE_COUNTER_HPP
28 
29 #include "common.hpp"
30 
31 namespace nfd {
32 
39 {
40 public:
41  typedef uint64_t rep;
42 
43  constexpr
45  : m_value(0)
46  {
47  }
48 
49  SimpleCounter(const SimpleCounter&) = delete;
50 
52  operator=(const SimpleCounter&) = delete;
53 
56  operator rep() const
57  {
58  return m_value;
59  }
60 
63  void
64  set(rep value)
65  {
66  m_value = value;
67  }
68 
69 protected:
70  rep m_value;
71 };
72 
78 {
79 public:
84  {
85  ++m_value;
86  return *this;
87  }
88  // postfix ++ operator is not provided because it's not needed
89 };
90 
95 class ByteCounter : public SimpleCounter
96 {
97 public:
100  ByteCounter&
102  {
103  m_value += n;
104  return *this;
105  }
106 };
107 
113 template<typename T>
115 {
116 public:
117  typedef size_t Rep;
118 
119  explicit constexpr
120  SizeCounter(const T* table = nullptr)
121  : m_table(table)
122  {
123  }
124 
125  SizeCounter(const SizeCounter&) = delete;
126 
127  SizeCounter&
128  operator=(const SizeCounter&) = delete;
129 
130  void
131  observe(const T* table)
132  {
133  m_table = table;
134  }
135 
138  operator Rep() const
139  {
140  BOOST_ASSERT(m_table != nullptr);
141  return m_table->size();
142  }
143 
144 private:
145  const T* m_table;
146 };
147 
148 } // namespace nfd
149 
150 #endif // NFD_CORE_COUNTER_HPP
represents a counter of number of bytes
Definition: counter.hpp:95
constexpr SimpleCounter()
Definition: counter.hpp:44
SimpleCounter & operator=(const SimpleCounter &)=delete
provides a counter that observes the size of a table
Definition: counter.hpp:114
represents a counter that encloses an integer value
Definition: counter.hpp:38
represents a counter of number of packets
Definition: counter.hpp:77
void observe(const T *table)
Definition: counter.hpp:131
ByteCounter & operator+=(rep n)
increase the counter
Definition: counter.hpp:101
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
PacketCounter & operator++()
increment the counter by one
Definition: counter.hpp:83
constexpr SizeCounter(const T *table=nullptr)
Definition: counter.hpp:120