NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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:
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 
111 template<typename T>
113 {
114 public:
115  typedef size_t rep;
116 
117  constexpr
118  SizeCounter(const T& table)
119  : m_table(table)
120  {
121  }
122 
123  SizeCounter(const SizeCounter&) = delete;
124 
125  SizeCounter&
126  operator=(const SizeCounter&) = delete;
127 
130  operator rep() const
131  {
132  return m_table.size();
133  }
134 
135 private:
136  const T& m_table;
137 };
138 
139 } // namespace nfd
140 
141 #endif // NFD_CORE_COUNTER_HPP
represents a counter of number of packets
Definition: counter.hpp:77
constexpr SizeCounter(const T &table)
Definition: counter.hpp:118
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:112
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