blob: 1708dbfe89ef252ea5c991d56ab78debb8ed7efd [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
24// Forward declaration
25class Node;
26class Entry;
27
28/**
29 * @brief Name Tree Node Class
30 */
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/**
46 * @brief Name Tree Entry Class
47 */
48class Entry
49{
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();
Junxiao Shi40631842014-03-01 13:52:37 -070075
76 bool
77 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060078
79 void
80 setFibEntry(shared_ptr<fib::Entry> fib);
81
82 shared_ptr<fib::Entry>
83 getFibEntry() const;
84
85 bool
86 eraseFibEntry(shared_ptr<fib::Entry> fib);
87
88 void
89 insertPitEntry(shared_ptr<pit::Entry> pit);
90
91 std::vector<shared_ptr<pit::Entry> >&
92 getPitEntries();
93
94 /**
95 * @brief Erase a PIT Entry
96 * @details The address of this PIT Entry is required
97 */
98 bool
99 erasePitEntry(shared_ptr<pit::Entry> pit);
100
101 void
102 setMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
103
104 shared_ptr<measurements::Entry>
105 getMeasurementsEntry() const;
106
107 bool
108 eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
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
155Entry::isEmpty() const
156{
157 return m_children.empty() &&
158 !static_cast<bool>(m_fibEntry) &&
159 m_pitEntries.empty() &&
160 !static_cast<bool>(m_measurementsEntry);
161}
162
HYuana9b85752014-02-26 02:32:30 -0600163inline shared_ptr<fib::Entry>
164Entry::getFibEntry() const
165{
166 return m_fibEntry;
167}
168
169inline std::vector<shared_ptr<pit::Entry> >&
170Entry::getPitEntries()
171{
172 return m_pitEntries;
173}
174
175inline shared_ptr<measurements::Entry>
176Entry::getMeasurementsEntry() const
177{
178 return m_measurementsEntry;
179}
180
Junxiao Shibb5105f2014-03-03 12:06:45 -0700181inline shared_ptr<strategy_choice::Entry>
182Entry::getStrategyChoiceEntry() const
183{
184 return m_strategyChoiceEntry;
185}
186
HYuana9b85752014-02-26 02:32:30 -0600187} // namespace name_tree
188} // namespace nfd
189
190#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP