blob: a3e4880b0632ffbbeaab212a05e25aab94fb1225 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
HYuana9b85752014-02-26 02:32:30 -060024
25// Name Tree Entry (i.e., Name Prefix Entry)
26
27#include "name-tree-entry.hpp"
28
29namespace nfd {
30namespace name_tree {
31
32Node::Node() : m_prev(0), m_next(0)
33{
34}
35
36Node::~Node()
37{
38 // erase the Name Tree Nodes that were created to
39 // resolve hash collisions
40 // So before erasing a single node, make sure its m_next == 0
41 // See eraseEntryIfEmpty in name-tree.cpp
42 if (m_next)
43 delete m_next;
44}
45
Junxiao Shi9f7455b2014-04-07 21:02:16 -070046Entry::Entry(const Name& name)
47 : m_hash(0)
48 , m_prefix(name)
HYuana9b85752014-02-26 02:32:30 -060049{
50}
51
52Entry::~Entry()
53{
54}
55
56void
57Entry::setHash(uint32_t hash)
58{
59 m_hash = hash;
60}
61
62void
63Entry::setParent(shared_ptr<Entry> parent)
64{
65 m_parent = parent;
66}
67
68void
Junxiao Shiefceadc2014-03-09 18:52:57 -070069Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
HYuana9b85752014-02-26 02:32:30 -060070{
Junxiao Shi9f7455b2014-04-07 21:02:16 -070071 if (static_cast<bool>(fibEntry)) {
72 BOOST_ASSERT(!static_cast<bool>(fibEntry->m_nameTreeEntry));
73 }
74
Junxiao Shiefceadc2014-03-09 18:52:57 -070075 if (static_cast<bool>(m_fibEntry)) {
76 m_fibEntry->m_nameTreeEntry.reset();
77 }
78 m_fibEntry = fibEntry;
79 if (static_cast<bool>(m_fibEntry)) {
80 m_fibEntry->m_nameTreeEntry = this->shared_from_this();
81 }
HYuana9b85752014-02-26 02:32:30 -060082}
83
84void
Junxiao Shi9f7455b2014-04-07 21:02:16 -070085Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry)
HYuana9b85752014-02-26 02:32:30 -060086{
Junxiao Shi9f7455b2014-04-07 21:02:16 -070087 BOOST_ASSERT(static_cast<bool>(pitEntry));
88 BOOST_ASSERT(!static_cast<bool>(pitEntry->m_nameTreeEntry));
HYuana9b85752014-02-26 02:32:30 -060089
Junxiao Shi9f7455b2014-04-07 21:02:16 -070090 m_pitEntries.push_back(pitEntry);
91 pitEntry->m_nameTreeEntry = this->shared_from_this();
HYuana9b85752014-02-26 02:32:30 -060092}
93
94void
Junxiao Shi9f7455b2014-04-07 21:02:16 -070095Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
HYuana9b85752014-02-26 02:32:30 -060096{
Junxiao Shi9f7455b2014-04-07 21:02:16 -070097 BOOST_ASSERT(static_cast<bool>(pitEntry));
98 BOOST_ASSERT(pitEntry->m_nameTreeEntry.get() == this);
99
100 std::vector<shared_ptr<pit::Entry> >::iterator it =
101 std::find(m_pitEntries.begin(), m_pitEntries.end(), pitEntry);
102 BOOST_ASSERT(it != m_pitEntries.end());
103
104 *it = m_pitEntries.back();
105 m_pitEntries.pop_back();
106 pitEntry->m_nameTreeEntry.reset();
107}
108
109void
110Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry)
111{
112 if (static_cast<bool>(measurementsEntry)) {
113 BOOST_ASSERT(!static_cast<bool>(measurementsEntry->m_nameTreeEntry));
114 }
115
HangZhangcb4fc832014-03-11 16:57:11 +0800116 if (static_cast<bool>(m_measurementsEntry)) {
117 m_measurementsEntry->m_nameTreeEntry.reset();
118 }
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700119 m_measurementsEntry = measurementsEntry;
HangZhangcb4fc832014-03-11 16:57:11 +0800120 if (static_cast<bool>(m_measurementsEntry)) {
121 m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
122 }
HYuana9b85752014-02-26 02:32:30 -0600123}
124
Junxiao Shibb5105f2014-03-03 12:06:45 -0700125void
126Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
127{
Junxiao Shi9f7455b2014-04-07 21:02:16 -0700128 if (static_cast<bool>(strategyChoiceEntry)) {
129 BOOST_ASSERT(!static_cast<bool>(strategyChoiceEntry->m_nameTreeEntry));
130 }
131
Junxiao Shiefceadc2014-03-09 18:52:57 -0700132 if (static_cast<bool>(m_strategyChoiceEntry)) {
133 m_strategyChoiceEntry->m_nameTreeEntry.reset();
134 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700135 m_strategyChoiceEntry = strategyChoiceEntry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700136 if (static_cast<bool>(m_strategyChoiceEntry)) {
137 m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
138 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700139}
140
HYuana9b85752014-02-26 02:32:30 -0600141} // namespace name_tree
142} // namespace nfd