NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
name-tree-iterator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
27 #define NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
28 
29 #include "name-tree-hashtable.hpp"
30 
31 namespace nfd {
32 namespace name_tree {
33 
34 class NameTree;
35 
38 typedef function<bool(const Entry& entry)> EntrySelector;
39 
42 struct AnyEntry
43 {
44  bool
45  operator()(const Entry& entry) const
46  {
47  return true;
48  }
49 };
50 
55 typedef function<std::pair<bool,bool>(const Entry& entry)> EntrySubTreeSelector;
56 
60 {
61  std::pair<bool, bool>
62  operator()(const Entry& entry) const
63  {
64  return {true, true};
65  }
66 };
67 
68 class EnumerationImpl;
69 
72 class Iterator : public std::iterator<std::forward_iterator_tag, const Entry>
73 {
74 public:
75  Iterator();
76 
77  Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref);
78 
79  const Entry&
80  operator*() const
81  {
82  BOOST_ASSERT(m_impl != nullptr);
83  return *m_entry;
84  }
85 
86  const Entry*
87  operator->() const
88  {
89  BOOST_ASSERT(m_impl != nullptr);
90  return m_entry;
91  }
92 
93  Iterator&
94  operator++();
95 
96  Iterator
97  operator++(int);
98 
99  bool
100  operator==(const Iterator& other) const;
101 
102  bool
103  operator!=(const Iterator& other) const
104  {
105  return !this->operator==(other);
106  }
107 
108 private:
111  shared_ptr<EnumerationImpl> m_impl;
112 
115  const Entry* m_entry;
116 
119  const Entry* m_ref;
120 
123  int m_state;
124 
125  friend std::ostream& operator<<(std::ostream&, const Iterator&);
126  friend class FullEnumerationImpl;
128  friend class PrefixMatchImpl;
129 };
130 
131 std::ostream&
132 operator<<(std::ostream& os, const Iterator& i);
133 
137 {
138 public:
139  explicit
140  EnumerationImpl(const NameTree& nt);
141 
142  virtual void
143  advance(Iterator& i) = 0;
144 
145 protected:
146  const NameTree& nt;
147  const Hashtable& ht;
148 };
149 
153 {
154 public:
155  FullEnumerationImpl(const NameTree& nt, const EntrySelector& pred);
156 
157  virtual void
158  advance(Iterator& i) override;
159 
160 private:
161  EntrySelector m_pred;
162 };
163 
170 {
171 public:
172  PartialEnumerationImpl(const NameTree& nt, const EntrySubTreeSelector& pred);
173 
174  virtual void
175  advance(Iterator& i) override;
176 
177 private:
178  EntrySubTreeSelector m_pred;
179 };
180 
186 {
187 public:
188  PrefixMatchImpl(const NameTree& nt, const EntrySelector& pred);
189 
190 private:
191  virtual void
192  advance(Iterator& i) override;
193 
194 private:
195  EntrySelector m_pred;
196 };
197 
203 typedef boost::iterator_range<Iterator> Range;
204 
205 } // namespace name_tree
206 } // namespace nfd
207 
208 #endif // NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
const Entry * operator->() const
full enumeration implementation
function< std::pair< bool, bool >const Entry &entry)> EntrySubTreeSelector
a predicate to accept or reject an Entry and its children
an EntrySelector that accepts every Entry
bool operator()(const Entry &entry) const
an EntrySubTreeSelector that accepts every Entry and its children
const Entry & operator*() const
std::ostream & operator<<(std::ostream &os, const Iterator &i)
std::pair< bool, bool > operator()(const Entry &entry) const
a hashtable for fast exact name lookup
bool operator!=(const Iterator &other) const
Table::const_iterator iterator
Definition: cs-internal.hpp:41
partial enumeration implementation
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
partial enumeration implementation
function< bool(const Entry &entry)> EntrySelector
a predicate to accept or reject an Entry in find operations
a common index structure for FIB, PIT, StrategyChoice, and Measurements
Definition: name-tree.hpp:36
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
enumeration operation implementation
an entry in the name tree
bool operator==(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)