blob: e3c72f2cdcad64a0bf39c2009ef611686c72b756 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7// Name Tree Entry (i.e., Name Prefix Entry)
8
9#ifndef NFD_TABLE_NAME_TREE_ENTRY_HPP
10#define NFD_TABLE_NAME_TREE_ENTRY_HPP
11
12#include "common.hpp"
13#include "table/fib-entry.hpp"
14#include "table/pit-entry.hpp"
15#include "table/measurements-entry.hpp"
Junxiao Shibb5105f2014-03-03 12:06:45 -070016#include "table/strategy-choice-entry.hpp"
HYuana9b85752014-02-26 02:32:30 -060017
18namespace nfd {
19
20class NameTree;
21
22namespace name_tree {
23
Haowei Yuane1079fc2014-03-08 14:41:25 -060024// Forward declarations
HYuana9b85752014-02-26 02:32:30 -060025class Node;
26class Entry;
27
28/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060029 * \brief Name Tree Node Class
HYuana9b85752014-02-26 02:32:30 -060030 */
31class Node
32{
33public:
34 Node();
35
36 ~Node();
37
38public:
39 // variables are in public as this is just a data structure
40 shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry)
41 Node* m_prev; // Previous Name Tree Node (to resolve hash collision)
42 Node* m_next; // Next Name Tree Node (to resolve hash collision)
43};
44
45/**
Haowei Yuane1079fc2014-03-08 14:41:25 -060046 * \brief Name Tree Entry Class
HYuana9b85752014-02-26 02:32:30 -060047 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070048class Entry : public enable_shared_from_this<Entry>, noncopyable
HYuana9b85752014-02-26 02:32:30 -060049{
50 // Make private members accessible by Name Tree
51 friend class nfd::NameTree;
52public:
53 explicit
54 Entry(const Name& prefix);
55
56 ~Entry();
57
58 const Name&
59 getPrefix() const;
60
61 void
62 setHash(uint32_t hash);
63
64 uint32_t
65 getHash() const;
66
67 void
68 setParent(shared_ptr<Entry> parent);
69
70 shared_ptr<Entry>
71 getParent() const;
72
73 std::vector<shared_ptr<Entry> >&
74 getChildren();
Haowei Yuane1079fc2014-03-08 14:41:25 -060075
76 bool
77 hasChildren() const;
78
Junxiao Shi40631842014-03-01 13:52:37 -070079 bool
80 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060081
82 void
Junxiao Shiefceadc2014-03-09 18:52:57 -070083 setFibEntry(shared_ptr<fib::Entry> fibEntry);
HYuana9b85752014-02-26 02:32:30 -060084
85 shared_ptr<fib::Entry>
86 getFibEntry() const;
87
HYuana9b85752014-02-26 02:32:30 -060088 void
89 insertPitEntry(shared_ptr<pit::Entry> pit);
90
Haowei Yuane1079fc2014-03-08 14:41:25 -060091 bool
92 hasPitEntries() const;
93
HYuana9b85752014-02-26 02:32:30 -060094 std::vector<shared_ptr<pit::Entry> >&
95 getPitEntries();
96
97 /**
Haowei Yuane1079fc2014-03-08 14:41:25 -060098 * \brief Erase a PIT Entry
99 * \details The address of this PIT Entry is required
HYuana9b85752014-02-26 02:32:30 -0600100 */
101 bool
102 erasePitEntry(shared_ptr<pit::Entry> pit);
103
104 void
105 setMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
106
107 shared_ptr<measurements::Entry>
108 getMeasurementsEntry() const;
109
110 bool
111 eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
112
Junxiao Shibb5105f2014-03-03 12:06:45 -0700113 void
114 setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry);
115
116 shared_ptr<strategy_choice::Entry>
117 getStrategyChoiceEntry() const;
118
HYuana9b85752014-02-26 02:32:30 -0600119private:
120 uint32_t m_hash;
121 Name m_prefix;
122 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
123 std::vector<shared_ptr<Entry> > m_children; // Children pointers.
124 shared_ptr<fib::Entry> m_fibEntry;
125 std::vector<shared_ptr<pit::Entry> > m_pitEntries;
126 shared_ptr<measurements::Entry> m_measurementsEntry;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700127 shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600128
129 // get the Name Tree Node that is associated with this Name Tree Entry
130 Node* m_node;
131};
132
133inline const Name&
134Entry::getPrefix() const
135{
136 return m_prefix;
137}
138
139inline uint32_t
140Entry::getHash() const
141{
142 return m_hash;
143}
144
145inline shared_ptr<Entry>
146Entry::getParent() const
147{
148 return m_parent;
149}
150
151inline std::vector<shared_ptr<name_tree::Entry> >&
152Entry::getChildren()
153{
154 return m_children;
155}
156
Junxiao Shi40631842014-03-01 13:52:37 -0700157inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600158Entry::hasChildren() const
159{
160 return !m_children.empty();
161}
162
163inline bool
Junxiao Shi40631842014-03-01 13:52:37 -0700164Entry::isEmpty() const
165{
166 return m_children.empty() &&
167 !static_cast<bool>(m_fibEntry) &&
168 m_pitEntries.empty() &&
169 !static_cast<bool>(m_measurementsEntry);
170}
171
HYuana9b85752014-02-26 02:32:30 -0600172inline shared_ptr<fib::Entry>
173Entry::getFibEntry() const
174{
175 return m_fibEntry;
176}
177
Haowei Yuane1079fc2014-03-08 14:41:25 -0600178inline bool
179Entry::hasPitEntries() const
180{
181 return !m_pitEntries.empty();
182}
183
HYuana9b85752014-02-26 02:32:30 -0600184inline std::vector<shared_ptr<pit::Entry> >&
185Entry::getPitEntries()
186{
187 return m_pitEntries;
188}
189
190inline shared_ptr<measurements::Entry>
191Entry::getMeasurementsEntry() const
192{
193 return m_measurementsEntry;
194}
195
Junxiao Shibb5105f2014-03-03 12:06:45 -0700196inline shared_ptr<strategy_choice::Entry>
197Entry::getStrategyChoiceEntry() const
198{
199 return m_strategyChoiceEntry;
200}
201
HYuana9b85752014-02-26 02:32:30 -0600202} // namespace name_tree
203} // namespace nfd
204
205#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP