NFD: Named Data Networking Forwarding Daemon 24.07-28-gdcc0e6e0
Loading...
Searching...
No Matches
name-tree-iterator.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
27#define NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
28
30
31#include <boost/operators.hpp>
32#include <boost/range/iterator_range_core.hpp>
33
34#include <functional>
35
36namespace nfd::name_tree {
37
38class NameTree;
39
43using EntrySelector = std::function<bool(const Entry&)>;
44
49{
50 constexpr bool
51 operator()(const Entry&) const noexcept
52 {
53 return true;
54 }
55};
56
61using EntrySubTreeSelector = std::function<std::pair<bool, bool>(const Entry&)>;
62
67{
68 constexpr std::pair<bool, bool>
69 operator()(const Entry&) const noexcept
70 {
71 return {true, true};
72 }
73};
74
75class EnumerationImpl;
76
80class Iterator : public boost::forward_iterator_helper<Iterator, const Entry>
81{
82public:
84
85 Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref);
86
87 const Entry&
88 operator*() const noexcept
89 {
90 BOOST_ASSERT(m_impl != nullptr);
91 return *m_entry;
92 }
93
95 operator++();
96
97 friend bool
98 operator==(const Iterator& lhs, const Iterator& rhs) noexcept
99 {
100 return lhs.m_entry == rhs.m_entry;
101 }
102
103private:
106 shared_ptr<EnumerationImpl> m_impl;
107
110 const Entry* m_entry = nullptr;
111
114 const Entry* m_ref = nullptr;
115
118 int m_state = 0;
119
120 friend std::ostream& operator<<(std::ostream&, const Iterator&);
123 friend class PrefixMatchImpl;
124};
125
126std::ostream&
127operator<<(std::ostream& os, const Iterator& i);
128
133{
134public:
135 explicit
137
138 virtual void
140
141protected:
142 ~EnumerationImpl() = default;
143
144protected:
145 const NameTree& nt;
146 const Hashtable& ht;
147};
148
153{
154public:
155 FullEnumerationImpl(const NameTree& nt, const EntrySelector& pred);
156
157 void
158 advance(Iterator& i) final;
159
160private:
161 EntrySelector m_pred;
162};
163
171{
172public:
174
175 void
176 advance(Iterator& i) final;
177
178private:
180};
181
188{
189public:
190 PrefixMatchImpl(const NameTree& nt, const EntrySelector& pred);
191
192private:
193 void
194 advance(Iterator& i) final;
195
196private:
197 EntrySelector m_pred;
198};
199
206using Range = boost::iterator_range<Iterator>;
207
208} // namespace nfd::name_tree
209
210#endif // NFD_DAEMON_TABLE_NAME_TREE_ITERATOR_HPP
An entry in the name tree.
Enumeration operation implementation.
virtual void advance(Iterator &i)=0
Full enumeration implementation.
A hashtable for fast exact name lookup.
friend bool operator==(const Iterator &lhs, const Iterator &rhs) noexcept
friend std::ostream & operator<<(std::ostream &, const Iterator &)
const Entry & operator*() const noexcept
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition name-tree.hpp:37
Partial enumeration implementation.
Partial enumeration implementation.
std::ostream & operator<<(std::ostream &os, const Iterator &i)
boost::iterator_range< Iterator > Range
A forward range of name tree entries.
std::function< bool(const Entry &)> EntrySelector
A predicate to accept or reject an Entry in find operations.
std::function< std::pair< bool, bool >(const Entry &)> EntrySubTreeSelector
A predicate to accept or reject an Entry and its children.
An EntrySelector that accepts every Entry.
constexpr bool operator()(const Entry &) const noexcept
An EntrySubTreeSelector that accepts every Entry and its children.
constexpr std::pair< bool, bool > operator()(const Entry &) const noexcept