name-tree-entry.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, 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_ENTRY_HPP
27 #define NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
28 
29 #include "table/fib-entry.hpp"
30 #include "table/pit-entry.hpp"
33 
34 namespace nfd::name_tree {
35 
36 class Node;
37 
41 class Entry : noncopyable
42 {
43 public:
44  Entry(const Name& prefix, Node* node);
45 
46  const Name&
47  getName() const noexcept
48  {
49  return m_name;
50  }
51 
55  Entry*
56  getParent() const noexcept
57  {
58  return m_parent;
59  }
60 
67  void
68  setParent(Entry& entry);
69 
74  void
75  unsetParent();
76 
80  bool
81  hasChildren() const
82  {
83  return !m_children.empty();
84  }
85 
89  const std::vector<Entry*>&
90  getChildren() const noexcept
91  {
92  return m_children;
93  }
94 
98  bool
99  isEmpty() const
100  {
101  return !this->hasChildren() && !this->hasTableEntries();
102  }
103 
104 public: // attached table entries
108  bool
109  hasTableEntries() const;
110 
111  fib::Entry*
112  getFibEntry() const
113  {
114  return m_fibEntry.get();
115  }
116 
117  void
118  setFibEntry(unique_ptr<fib::Entry> fibEntry);
119 
120  bool
122  {
123  return !this->getPitEntries().empty();
124  }
125 
126  const std::vector<shared_ptr<pit::Entry>>&
128  {
129  return m_pitEntries;
130  }
131 
132  void
133  insertPitEntry(shared_ptr<pit::Entry> pitEntry);
134 
135  void
136  erasePitEntry(pit::Entry* pitEntry);
137 
140  {
141  return m_measurementsEntry.get();
142  }
143 
144  void
145  setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry);
146 
149  {
150  return m_strategyChoiceEntry.get();
151  }
152 
153  void
154  setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry);
155 
161  template<typename ENTRY>
162  static Entry*
163  get(const ENTRY& tableEntry)
164  {
165  return tableEntry.m_nameTreeEntry;
166  }
167 
168 private:
169  Name m_name;
170  Node* m_node;
171  Entry* m_parent = nullptr;
172  std::vector<Entry*> m_children;
173 
174  unique_ptr<fib::Entry> m_fibEntry;
175  std::vector<shared_ptr<pit::Entry>> m_pitEntries;
176  unique_ptr<measurements::Entry> m_measurementsEntry;
177  unique_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
178 
179  friend Node* getNode(const Entry& entry);
180 };
181 
185 template<typename ENTRY>
187 {
188 public:
191  using Getter = ENTRY* (Entry::*)() const;
192 
196  explicit
197  GetTableEntry(Getter getter = nullptr)
198  : m_getter(getter)
199  {
200  }
201 
202  const ENTRY&
203  operator()(const Entry& nte) const
204  {
205  return *(nte.*m_getter)();
206  }
207 
208 private:
209  Getter m_getter;
210 };
211 
212 } // namespace nfd::name_tree
213 
214 #endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
Represents an entry in the FIB.
Definition: fib-entry.hpp:91
Represents an entry in the Measurements table.
An entry in the name tree.
friend Node * getNode(const Entry &entry)
bool hasPitEntries() const
void unsetParent()
Unset parent of this entry.
Entry(const Name &prefix, Node *node)
void insertPitEntry(shared_ptr< pit::Entry > pitEntry)
void setMeasurementsEntry(unique_ptr< measurements::Entry > measurementsEntry)
void erasePitEntry(pit::Entry *pitEntry)
fib::Entry * getFibEntry() const
measurements::Entry * getMeasurementsEntry() const
void setParent(Entry &entry)
Set parent of this entry.
const std::vector< shared_ptr< pit::Entry > > & getPitEntries() const
Entry * getParent() const noexcept
bool isEmpty() const
static Entry * get(const ENTRY &tableEntry)
void setStrategyChoiceEntry(unique_ptr< strategy_choice::Entry > strategyChoiceEntry)
void setFibEntry(unique_ptr< fib::Entry > fibEntry)
const std::vector< Entry * > & getChildren() const noexcept
Returns the children of this entry.
bool hasChildren() const
Check whether this entry has any children.
const Name & getName() const noexcept
strategy_choice::Entry * getStrategyChoiceEntry() const
bool hasTableEntries() const
A functor to get a table entry from a name tree entry.
ENTRY *(Entry::*)() const Getter
A function pointer to the getter on Entry class that returns ENTRY.
const ENTRY & operator()(const Entry &nte) const
GetTableEntry(Getter getter=nullptr)
Represents an entry in the Interest table (PIT).
Definition: pit-entry.hpp:197
Represents an entry in the Strategy Choice table.