blob: cef42ff308606d6d288255817b34dcf1bd9dd2c9 [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"
16
17namespace nfd {
18
19class NameTree;
20
21namespace name_tree {
22
23// Forward declaration
24class Node;
25class Entry;
26
27/**
28 * @brief Name Tree Node Class
29 */
30class Node
31{
32public:
33 Node();
34
35 ~Node();
36
37public:
38 // variables are in public as this is just a data structure
39 shared_ptr<Entry> m_entry; // Name Tree Entry (i.e., Name Prefix Entry)
40 Node* m_prev; // Previous Name Tree Node (to resolve hash collision)
41 Node* m_next; // Next Name Tree Node (to resolve hash collision)
42};
43
44/**
45 * @brief Name Tree Entry Class
46 */
47class Entry
48{
49 // Make private members accessible by Name Tree
50 friend class nfd::NameTree;
51public:
52 explicit
53 Entry(const Name& prefix);
54
55 ~Entry();
56
57 const Name&
58 getPrefix() const;
59
60 void
61 setHash(uint32_t hash);
62
63 uint32_t
64 getHash() const;
65
66 void
67 setParent(shared_ptr<Entry> parent);
68
69 shared_ptr<Entry>
70 getParent() const;
71
72 std::vector<shared_ptr<Entry> >&
73 getChildren();
Junxiao Shi40631842014-03-01 13:52:37 -070074
75 bool
76 isEmpty() const;
HYuana9b85752014-02-26 02:32:30 -060077
78 void
79 setFibEntry(shared_ptr<fib::Entry> fib);
80
81 shared_ptr<fib::Entry>
82 getFibEntry() const;
83
84 bool
85 eraseFibEntry(shared_ptr<fib::Entry> fib);
86
87 void
88 insertPitEntry(shared_ptr<pit::Entry> pit);
89
90 std::vector<shared_ptr<pit::Entry> >&
91 getPitEntries();
92
93 /**
94 * @brief Erase a PIT Entry
95 * @details The address of this PIT Entry is required
96 */
97 bool
98 erasePitEntry(shared_ptr<pit::Entry> pit);
99
100 void
101 setMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
102
103 shared_ptr<measurements::Entry>
104 getMeasurementsEntry() const;
105
106 bool
107 eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements);
108
109private:
110 uint32_t m_hash;
111 Name m_prefix;
112 shared_ptr<Entry> m_parent; // Pointing to the parent entry.
113 std::vector<shared_ptr<Entry> > m_children; // Children pointers.
114 shared_ptr<fib::Entry> m_fibEntry;
115 std::vector<shared_ptr<pit::Entry> > m_pitEntries;
116 shared_ptr<measurements::Entry> m_measurementsEntry;
117
118 // get the Name Tree Node that is associated with this Name Tree Entry
119 Node* m_node;
120};
121
122inline const Name&
123Entry::getPrefix() const
124{
125 return m_prefix;
126}
127
128inline uint32_t
129Entry::getHash() const
130{
131 return m_hash;
132}
133
134inline shared_ptr<Entry>
135Entry::getParent() const
136{
137 return m_parent;
138}
139
140inline std::vector<shared_ptr<name_tree::Entry> >&
141Entry::getChildren()
142{
143 return m_children;
144}
145
Junxiao Shi40631842014-03-01 13:52:37 -0700146inline bool
147Entry::isEmpty() const
148{
149 return m_children.empty() &&
150 !static_cast<bool>(m_fibEntry) &&
151 m_pitEntries.empty() &&
152 !static_cast<bool>(m_measurementsEntry);
153}
154
HYuana9b85752014-02-26 02:32:30 -0600155inline shared_ptr<fib::Entry>
156Entry::getFibEntry() const
157{
158 return m_fibEntry;
159}
160
161inline std::vector<shared_ptr<pit::Entry> >&
162Entry::getPitEntries()
163{
164 return m_pitEntries;
165}
166
167inline shared_ptr<measurements::Entry>
168Entry::getMeasurementsEntry() const
169{
170 return m_measurementsEntry;
171}
172
173} // namespace name_tree
174} // namespace nfd
175
176#endif // NFD_TABLE_NAME_TREE_ENTRY_HPP