blob: 56619618448d5979e266fc14d28747673f7ff1a8 [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
Junxiao Shibb5105f2014-03-03 12:06:45 -0700110 void
111 setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry);
112
113 shared_ptr<strategy_choice::Entry>
114 getStrategyChoiceEntry() const;
115
HYuana9b85752014-02-26 02:32:30 -0600116private:
117 uint32_t m_hash;
118 Name m_prefix;
119 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
120 std::vector<shared_ptr<Entry> > m_children; // Children pointers.
121 shared_ptr<fib::Entry> m_fibEntry;
122 std::vector<shared_ptr<pit::Entry> > m_pitEntries;
123 shared_ptr<measurements::Entry> m_measurementsEntry;
Junxiao Shibb5105f2014-03-03 12:06:45 -0700124 shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
HYuana9b85752014-02-26 02:32:30 -0600125
126 // get the Name Tree Node that is associated with this Name Tree Entry
127 Node* m_node;
128};
129
130inline const Name&
131Entry::getPrefix() const
132{
133 return m_prefix;
134}
135
136inline uint32_t
137Entry::getHash() const
138{
139 return m_hash;
140}
141
142inline shared_ptr<Entry>
143Entry::getParent() const
144{
145 return m_parent;
146}
147
148inline std::vector<shared_ptr<name_tree::Entry> >&
149Entry::getChildren()
150{
151 return m_children;
152}
153
Junxiao Shi40631842014-03-01 13:52:37 -0700154inline bool
Haowei Yuane1079fc2014-03-08 14:41:25 -0600155Entry::hasChildren() const
156{
157 return !m_children.empty();
158}
159
160inline bool
Junxiao Shi40631842014-03-01 13:52:37 -0700161Entry::isEmpty() const
162{
163 return m_children.empty() &&
164 !static_cast<bool>(m_fibEntry) &&
165 m_pitEntries.empty() &&
166 !static_cast<bool>(m_measurementsEntry);
167}
168
HYuana9b85752014-02-26 02:32:30 -0600169inline shared_ptr<fib::Entry>
170Entry::getFibEntry() const
171{
172 return m_fibEntry;
173}
174
Haowei Yuane1079fc2014-03-08 14:41:25 -0600175inline bool
176Entry::hasPitEntries() const
177{
178 return !m_pitEntries.empty();
179}
180
HYuana9b85752014-02-26 02:32:30 -0600181inline std::vector<shared_ptr<pit::Entry> >&
182Entry::getPitEntries()
183{
184 return m_pitEntries;
185}
186
187inline shared_ptr<measurements::Entry>
188Entry::getMeasurementsEntry() const
189{
190 return m_measurementsEntry;
191}
192
Junxiao Shibb5105f2014-03-03 12:06:45 -0700193inline shared_ptr<strategy_choice::Entry>
194Entry::getStrategyChoiceEntry() const
195{
196 return m_strategyChoiceEntry;
197}
198
HYuana9b85752014-02-26 02:32:30 -0600199} // namespace name_tree
200} // namespace nfd
201
202#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP