NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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:
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
void observe(const T *table)
Definition: counter.hpp:131
represents a counter of number of packets
Definition: counter.hpp:77
constexpr SizeCounter(const T *table=nullptr)
Definition: counter.hpp:120
SizeCounter & operator=(const SizeCounter &)=delete
void set(rep value)
replace the counter value
Definition: counter.hpp:64
represents a counter of number of bytes
Definition: counter.hpp:95
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
PacketCounter & operator++()
increment the counter by one
Definition: counter.hpp:83
provides a counter that observes the size of a table
Definition: counter.hpp:114
constexpr SimpleCounter()
Definition: counter.hpp:44
SimpleCounter & operator=(const SimpleCounter &)=delete
represents a counter that encloses an integer value
Definition: counter.hpp:38
ByteCounter & operator+=(rep n)
increase the counter
Definition: counter.hpp:101