NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
pit.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_PIT_HPP
27 #define NFD_DAEMON_TABLE_PIT_HPP
28 
29 #include "name-tree.hpp"
30 #include "pit-entry.hpp"
31 
32 namespace nfd {
33 namespace pit {
34 
42 typedef std::vector<shared_ptr<pit::Entry>> DataMatchResult;
43 
44 } // namespace pit
45 
48 class Pit : noncopyable
49 {
50 public:
51  explicit
52  Pit(NameTree& nameTree);
53 
56  size_t
57  size() const;
58 
63  shared_ptr<pit::Entry>
64  find(const Interest& interest) const;
65 
71  std::pair<shared_ptr<pit::Entry>, bool>
72  insert(const Interest& interest);
73 
78  findAllDataMatches(const Data& data) const;
79 
83  void
84  erase(shared_ptr<pit::Entry> pitEntry);
85 
86 public: // enumeration
87  class const_iterator;
88 
95  begin() const;
96 
102  end() const;
103 
104  class const_iterator : public std::iterator<std::forward_iterator_tag, const pit::Entry>
105  {
106  public:
107  const_iterator();
108 
109  explicit
111 
112  ~const_iterator();
113 
114  const pit::Entry&
115  operator*() const;
116 
117  shared_ptr<pit::Entry>
118  operator->() const;
119 
121  operator++();
122 
124  operator++(int);
125 
126  bool
127  operator==(const const_iterator& other) const;
128 
129  bool
130  operator!=(const const_iterator& other) const;
131 
132  private:
133  NameTree::const_iterator m_nameTreeIterator;
139  size_t m_iPitEntry;
140  };
141 
142 private:
151  std::pair<shared_ptr<pit::Entry>, bool>
152  findOrInsert(const Interest& interest, bool allowInsert);
153 
154 private:
155  NameTree& m_nameTree;
156  size_t m_nItems;
157 };
158 
159 inline size_t
160 Pit::size() const
161 {
162  return m_nItems;
163 }
164 
165 inline shared_ptr<pit::Entry>
166 Pit::find(const Interest& interest) const
167 {
168  return const_cast<Pit*>(this)->findOrInsert(interest, false).first;
169 }
170 
171 inline std::pair<shared_ptr<pit::Entry>, bool>
172 Pit::insert(const Interest& interest)
173 {
174  return this->findOrInsert(interest, true);
175 }
176 
177 inline Pit::const_iterator
178 Pit::end() const
179 {
180  return const_iterator(m_nameTree.end());
181 }
182 
183 inline
185  : m_iPitEntry(0)
186 {
187 }
188 
189 inline
191  : m_nameTreeIterator(it)
192  , m_iPitEntry(0)
193 {
194 }
195 
196 inline
198 {
199 }
200 
201 inline Pit::const_iterator
203 {
204  Pit::const_iterator temp(*this);
205  ++(*this);
206  return temp;
207 }
208 
209 inline Pit::const_iterator&
211 {
212  ++m_iPitEntry;
213  if (m_iPitEntry < m_nameTreeIterator->getPitEntries().size()) {
214  return *this;
215  }
216 
217  ++m_nameTreeIterator;
218  m_iPitEntry = 0;
219  return *this;
220 }
221 
222 inline const pit::Entry&
224 {
225  return *(this->operator->());
226 }
227 
228 inline shared_ptr<pit::Entry>
230 {
231  return m_nameTreeIterator->getPitEntries().at(m_iPitEntry);
232 }
233 
234 inline bool
236 {
237  return m_nameTreeIterator == other.m_nameTreeIterator &&
238  m_iPitEntry == other.m_iPitEntry;
239 }
240 
241 inline bool
243 {
244  return !(*this == other);
245 }
246 
247 } // namespace nfd
248 
249 #endif // NFD_DAEMON_TABLE_PIT_HPP
const_iterator end() const
returns an iterator referring to the past-the-end PIT entry
Definition: pit.hpp:178
bool operator==(const const_iterator &other) const
Definition: pit.hpp:235
represents an Interest packet
Definition: interest.hpp:45
shared_ptr< pit::Entry > find(const Interest &interest) const
finds a PIT entry for Interest
Definition: pit.hpp:166
represents the Interest Table
Definition: pit.hpp:48
Table::const_iterator iterator
Definition: cs-internal.hpp:41
bool operator!=(const const_iterator &other) const
Definition: pit.hpp:242
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
represents a PIT entry
Definition: pit-entry.hpp:69
Class Name Tree.
Definition: name-tree.hpp:79
std::pair< shared_ptr< pit::Entry >, bool > insert(const Interest &interest)
inserts a PIT entry for Interest
Definition: pit.hpp:172
shared_ptr< pit::Entry > operator->() const
Definition: pit.hpp:229
bool operator!=(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)
represents a Data packet
Definition: data.hpp:39
const_iterator & operator++()
Definition: pit.hpp:210
size_t size() const
Definition: pit.hpp:160
const pit::Entry & operator*() const
Definition: pit.hpp:223
bool operator==(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)
std::vector< shared_ptr< pit::Entry > > DataMatchResult
Definition: pit.hpp:42