blob: 5f7737c6cce16e7b0f7b31c716d5bf07b53553de [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
46Entry::Entry(const Name& name) : m_hash(0), m_prefix(name)
47{
48}
49
50Entry::~Entry()
51{
52}
53
54void
55Entry::setHash(uint32_t hash)
56{
57 m_hash = hash;
58}
59
60void
61Entry::setParent(shared_ptr<Entry> parent)
62{
63 m_parent = parent;
64}
65
66void
Junxiao Shiefceadc2014-03-09 18:52:57 -070067Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
HYuana9b85752014-02-26 02:32:30 -060068{
Junxiao Shiefceadc2014-03-09 18:52:57 -070069 if (static_cast<bool>(m_fibEntry)) {
70 m_fibEntry->m_nameTreeEntry.reset();
71 }
72 m_fibEntry = fibEntry;
73 if (static_cast<bool>(m_fibEntry)) {
74 m_fibEntry->m_nameTreeEntry = this->shared_from_this();
75 }
HYuana9b85752014-02-26 02:32:30 -060076}
77
78void
79Entry::insertPitEntry(shared_ptr<pit::Entry> pit)
80{
HangZhangcb4fc832014-03-11 16:57:11 +080081 if (static_cast<bool>(pit)) {
82 pit->m_nameTreeEntry = this->shared_from_this();
83 m_pitEntries.push_back(pit);
84 }
HYuana9b85752014-02-26 02:32:30 -060085}
86
87bool
88Entry::erasePitEntry(shared_ptr<pit::Entry> pit)
89{
HangZhangcb4fc832014-03-11 16:57:11 +080090 for (size_t i = 0; i < m_pitEntries.size(); i++) {
91 if (m_pitEntries[i] == pit) {
92 BOOST_ASSERT(pit->m_nameTreeEntry);
93
94 pit->m_nameTreeEntry.reset();
HYuana9b85752014-02-26 02:32:30 -060095 // copy the last item to the current position
96 m_pitEntries[i] = m_pitEntries[m_pitEntries.size() - 1];
97 // then erase the last item
98 m_pitEntries.pop_back();
99 return true; // success
HangZhangcb4fc832014-03-11 16:57:11 +0800100 }
101 }
HYuana9b85752014-02-26 02:32:30 -0600102 // not found this entry
103 return false; // failure
104}
105
106void
107Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements)
108{
HangZhangcb4fc832014-03-11 16:57:11 +0800109 if (static_cast<bool>(m_measurementsEntry)) {
110 m_measurementsEntry->m_nameTreeEntry.reset();
111 }
HYuana9b85752014-02-26 02:32:30 -0600112 m_measurementsEntry = measurements;
HangZhangcb4fc832014-03-11 16:57:11 +0800113 if (static_cast<bool>(m_measurementsEntry)) {
114 m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
115 }
HYuana9b85752014-02-26 02:32:30 -0600116}
117
Junxiao Shibb5105f2014-03-03 12:06:45 -0700118void
119Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
120{
Junxiao Shiefceadc2014-03-09 18:52:57 -0700121 if (static_cast<bool>(m_strategyChoiceEntry)) {
122 m_strategyChoiceEntry->m_nameTreeEntry.reset();
123 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700124 m_strategyChoiceEntry = strategyChoiceEntry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700125 if (static_cast<bool>(m_strategyChoiceEntry)) {
126 m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
127 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700128}
129
HYuana9b85752014-02-26 02:32:30 -0600130} // namespace name_tree
131} // namespace nfd