blob: cca190897fdaf3d3b8fa4b581ff132f4b9d7a82d [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 */
Haowei Yuane1079fc2014-03-08 14:41:25 -060048class 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
83 setFibEntry(shared_ptr<fib::Entry> fib);
84
85 shared_ptr<fib::Entry>
86 getFibEntry() const;
87
88 bool
89 eraseFibEntry(shared_ptr<fib::Entry> fib);
90
91 void
92 insertPitEntry(shared_ptr<pit::Entry> pit);
93
Haowei Yuane1079fc2014-03-08 14:41:25 -060094 bool
95 hasPitEntries() const;
96
HYuana9b85752014-02-26 02:32:30 -060097 std::vector<shared_ptr<pit::Entry> >&
98 getPitEntries();
99
100 /**
Haowei Yuane1079fc2014-03-08 14:41:25 -0600101 * \brief Erase a PIT Entry
102 * \details The address of this PIT Entry is required
HYuana9b85752014-02-26 02:32:30 -0600103 */
104 bool
105 erasePitEntry(shared_ptr<pit::Entry> pit);
106
107 void
108 setMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
109
110 shared_ptr<measurements::Entry>
111 getMeasurementsEntry() const;
112
113 bool
114 eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
115
Junxiao Shibb5105f2014-03-03 12:06:45 -0700116 void
117 setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry);
118
119 shared_ptr<strategy_choice::Entry>
120 getStrategyChoiceEntry() const;
121
HYuana9b85752014-02-26 02:32:30 -0600122private:
123 uint32_t m_hash;
124 Name m_prefix;
125 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
126 std::vector<shared_ptr<Entry> > m_children; // Children pointers.
127 shared_ptr<fib::Entry> m_fibEntry;
128 std::vector<shared_ptr<pit::Entry> > m_pitEntries;
129 shared_ptr<measurements::Entry> m_measurementsEntry;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700130 shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600131
132 // get the Name Tree Node that is associated with this Name Tree Entry
133 Node* m_node;
134};
135
136inline const Name&
137Entry::getPrefix() const
138{
139 return m_prefix;
140}
141
142inline uint32_t
143Entry::getHash() const
144{
145 return m_hash;
146}
147
148inline shared_ptr<Entry>
149Entry::getParent() const
150{
151 return m_parent;
152}
153
154inline std::vector<shared_ptr<name_tree::Entry> >&
155Entry::getChildren()
156{
157 return m_children;
158}
159
Junxiao Shi40631842014-03-01 13:52:37 -0700160inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600161Entry::hasChildren() const
162{
163 return !m_children.empty();
164}
165
166inline bool
Junxiao Shi40631842014-03-01 13:52:37 -0700167Entry::isEmpty() const
168{
169 return m_children.empty() &&
170 !static_cast<bool>(m_fibEntry) &&
171 m_pitEntries.empty() &&
172 !static_cast<bool>(m_measurementsEntry);
173}
174
HYuana9b85752014-02-26 02:32:30 -0600175inline shared_ptr<fib::Entry>
176Entry::getFibEntry() const
177{
178 return m_fibEntry;
179}
180
Haowei Yuane1079fc2014-03-08 14:41:25 -0600181inline bool
182Entry::hasPitEntries() const
183{
184 return !m_pitEntries.empty();
185}
186
HYuana9b85752014-02-26 02:32:30 -0600187inline std::vector<shared_ptr<pit::Entry> >&
188Entry::getPitEntries()
189{
190 return m_pitEntries;
191}
192
193inline shared_ptr<measurements::Entry>
194Entry::getMeasurementsEntry() const
195{
196 return m_measurementsEntry;
197}
198
Junxiao Shibb5105f2014-03-03 12:06:45 -0700199inline shared_ptr<strategy_choice::Entry>
200Entry::getStrategyChoiceEntry() const
201{
202 return m_strategyChoiceEntry;
203}
204
HYuana9b85752014-02-26 02:32:30 -0600205} // namespace name_tree
206} // namespace nfd
207
208#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP