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-2019, 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 {
35 namespace name_tree {
36 
37 class Node;
38 
41 class Entry : noncopyable
42 {
43 public:
44  Entry(const Name& prefix, Node* node);
45 
46  const Name&
47  getName() const
48  {
49  return m_name;
50  }
51 
55  Entry*
56  getParent() const
57  {
58  return m_parent;
59  }
60 
67  void
68  setParent(Entry& entry);
69 
74  void
75  unsetParent();
76 
79  bool
80  hasChildren() const
81  {
82  return !m_children.empty();
83  }
84 
87  const std::vector<Entry*>&
88  getChildren() const
89  {
90  return m_children;
91  }
92 
96  bool
97  isEmpty() const
98  {
99  return !this->hasChildren() && !this->hasTableEntries();
100  }
101 
102 public: // attached table entries
106  bool
107  hasTableEntries() const;
108 
109  fib::Entry*
110  getFibEntry() const
111  {
112  return m_fibEntry.get();
113  }
114 
115  void
116  setFibEntry(unique_ptr<fib::Entry> fibEntry);
117 
118  bool
120  {
121  return !this->getPitEntries().empty();
122  }
123 
124  const std::vector<shared_ptr<pit::Entry>>&
126  {
127  return m_pitEntries;
128  }
129 
130  void
131  insertPitEntry(shared_ptr<pit::Entry> pitEntry);
132 
133  void
134  erasePitEntry(pit::Entry* pitEntry);
135 
138  {
139  return m_measurementsEntry.get();
140  }
141 
142  void
143  setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry);
144 
147  {
148  return m_strategyChoiceEntry.get();
149  }
150 
151  void
152  setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry);
153 
159  template<typename ENTRY>
160  static Entry*
161  get(const ENTRY& tableEntry)
162  {
163  return tableEntry.m_nameTreeEntry;
164  }
165 
166 private:
167  Name m_name;
168  Node* m_node;
169  Entry* m_parent = nullptr;
170  std::vector<Entry*> m_children;
171 
172  unique_ptr<fib::Entry> m_fibEntry;
173  std::vector<shared_ptr<pit::Entry>> m_pitEntries;
174  unique_ptr<measurements::Entry> m_measurementsEntry;
175  unique_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
176 
177  friend Node* getNode(const Entry& entry);
178 };
179 
183 template<typename ENTRY>
185 {
186 public:
189  using Getter = ENTRY* (Entry::*)() const;
190 
194  explicit
195  GetTableEntry(Getter getter = nullptr)
196  : m_getter(getter)
197  {
198  }
199 
200  const ENTRY&
201  operator()(const Entry& nte) const
202  {
203  return *(nte.*m_getter)();
204  }
205 
206 private:
207  Getter m_getter;
208 };
209 
210 } // namespace name_tree
211 } // namespace nfd
212 
213 #endif // NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
void unsetParent()
Unset parent of this entry.
const std::vector< Entry * > & getChildren() const
bool isEmpty() const
Represents a Measurements entry.
void erasePitEntry(pit::Entry *pitEntry)
void setMeasurementsEntry(unique_ptr< measurements::Entry > measurementsEntry)
bool hasChildren() const
Check whether this entry has any children.
represents a FIB entry
Definition: fib-entry.hpp:53
ENTRY *(Entry::*)() const Getter
A function pointer to the getter on Entry class that returns ENTRY.
void setParent(Entry &entry)
Set parent of this entry.
strategy_choice::Entry * getStrategyChoiceEntry() const
const std::vector< shared_ptr< pit::Entry > > & getPitEntries() const
Entry(const Name &prefix, Node *node)
const ENTRY & operator()(const Entry &nte) const
friend Node * getNode(const Entry &entry)
Entry * getParent() const
void setStrategyChoiceEntry(unique_ptr< strategy_choice::Entry > strategyChoiceEntry)
fib::Entry * getFibEntry() const
An Interest table entry.
Definition: pit-entry.hpp:58
bool hasPitEntries() const
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
void setFibEntry(unique_ptr< fib::Entry > fibEntry)
bool hasTableEntries() const
An entry in the name tree.
Represents a Strategy Choice entry.
measurements::Entry * getMeasurementsEntry() const
const Name & getName() const
GetTableEntry(Getter getter=nullptr)
void insertPitEntry(shared_ptr< pit::Entry > pitEntry)
a functor to get a table entry from a name tree entry