blob: 017dbfebeee3b0c118e8c047745dd0f60b17297b [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiee5a4442014-07-27 17:13:43 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shiee5a4442014-07-27 17:13:43 -070024 */
HYuana9b85752014-02-26 02:32:30 -060025
26#include "name-tree-entry.hpp"
27
28namespace nfd {
29namespace name_tree {
30
Haowei Yuanf52dac72014-03-24 23:35:03 -050031Node::Node()
32 : m_prev(0)
33 , m_next(0)
HYuana9b85752014-02-26 02:32:30 -060034{
35}
36
37Node::~Node()
38{
39 // erase the Name Tree Nodes that were created to
40 // resolve hash collisions
41 // So before erasing a single node, make sure its m_next == 0
42 // See eraseEntryIfEmpty in name-tree.cpp
Junxiao Shiee5a4442014-07-27 17:13:43 -070043 if (m_next != 0)
HYuana9b85752014-02-26 02:32:30 -060044 delete m_next;
45}
46
Junxiao Shi9f7455b2014-04-07 21:02:16 -070047Entry::Entry(const Name& name)
48 : m_hash(0)
49 , m_prefix(name)
HYuana9b85752014-02-26 02:32:30 -060050{
51}
52
53Entry::~Entry()
54{
55}
56
Junxiao Shiee5a4442014-07-27 17:13:43 -070057bool
58Entry::isEmpty() const
59{
60 return m_children.empty() &&
61 !static_cast<bool>(m_fibEntry) &&
62 m_pitEntries.empty() &&
63 !static_cast<bool>(m_measurementsEntry) &&
64 !static_cast<bool>(m_strategyChoiceEntry);
65}
66
67void
68Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
69{
70 if (static_cast<bool>(fibEntry)) {
71 BOOST_ASSERT(!static_cast<bool>(fibEntry->m_nameTreeEntry));
72 }
73
74 if (static_cast<bool>(m_fibEntry)) {
75 m_fibEntry->m_nameTreeEntry.reset();
76 }
77 m_fibEntry = fibEntry;
78 if (static_cast<bool>(m_fibEntry)) {
79 m_fibEntry->m_nameTreeEntry = this->shared_from_this();
80 }
81}
82
83void
84Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry)
85{
86 BOOST_ASSERT(static_cast<bool>(pitEntry));
87 BOOST_ASSERT(!static_cast<bool>(pitEntry->m_nameTreeEntry));
88
89 m_pitEntries.push_back(pitEntry);
90 pitEntry->m_nameTreeEntry = this->shared_from_this();
91}
92
HYuana9b85752014-02-26 02:32:30 -060093void
Junxiao Shi9f7455b2014-04-07 21:02:16 -070094Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
HYuana9b85752014-02-26 02:32:30 -060095{
Junxiao Shi9f7455b2014-04-07 21:02:16 -070096 BOOST_ASSERT(static_cast<bool>(pitEntry));
97 BOOST_ASSERT(pitEntry->m_nameTreeEntry.get() == this);
98
99 std::vector<shared_ptr<pit::Entry> >::iterator it =
100 std::find(m_pitEntries.begin(), m_pitEntries.end(), pitEntry);
101 BOOST_ASSERT(it != m_pitEntries.end());
102
103 *it = m_pitEntries.back();
104 m_pitEntries.pop_back();
105 pitEntry->m_nameTreeEntry.reset();
106}
107
Junxiao Shiee5a4442014-07-27 17:13:43 -0700108void
109Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry)
110{
111 if (static_cast<bool>(measurementsEntry)) {
112 BOOST_ASSERT(!static_cast<bool>(measurementsEntry->m_nameTreeEntry));
113 }
114
115 if (static_cast<bool>(m_measurementsEntry)) {
116 m_measurementsEntry->m_nameTreeEntry.reset();
117 }
118 m_measurementsEntry = measurementsEntry;
119 if (static_cast<bool>(m_measurementsEntry)) {
120 m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
121 }
122}
123
124void
125Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
126{
127 if (static_cast<bool>(strategyChoiceEntry)) {
128 BOOST_ASSERT(!static_cast<bool>(strategyChoiceEntry->m_nameTreeEntry));
129 }
130
131 if (static_cast<bool>(m_strategyChoiceEntry)) {
132 m_strategyChoiceEntry->m_nameTreeEntry.reset();
133 }
134 m_strategyChoiceEntry = strategyChoiceEntry;
135 if (static_cast<bool>(m_strategyChoiceEntry)) {
136 m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
137 }
138}
139
HYuana9b85752014-02-26 02:32:30 -0600140} // namespace name_tree
141} // namespace nfd