HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * 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 | **/ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 24 | |
| 25 | // Name Tree Entry (i.e., Name Prefix Entry) |
| 26 | |
| 27 | #include "name-tree-entry.hpp" |
| 28 | |
| 29 | namespace nfd { |
| 30 | namespace name_tree { |
| 31 | |
| 32 | Node::Node() : m_prev(0), m_next(0) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | Node::~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 | |
| 46 | Entry::Entry(const Name& name) : m_hash(0), m_prefix(name) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | Entry::~Entry() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | Entry::setHash(uint32_t hash) |
| 56 | { |
| 57 | m_hash = hash; |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | Entry::setParent(shared_ptr<Entry> parent) |
| 62 | { |
| 63 | m_parent = parent; |
| 64 | } |
| 65 | |
| 66 | void |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 67 | Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 68 | { |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 69 | 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 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void |
| 79 | Entry::insertPitEntry(shared_ptr<pit::Entry> pit) |
| 80 | { |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 81 | if (static_cast<bool>(pit)) { |
| 82 | pit->m_nameTreeEntry = this->shared_from_this(); |
| 83 | m_pitEntries.push_back(pit); |
| 84 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | bool |
| 88 | Entry::erasePitEntry(shared_ptr<pit::Entry> pit) |
| 89 | { |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 90 | 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(); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 95 | // 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 |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 100 | } |
| 101 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 102 | // not found this entry |
| 103 | return false; // failure |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements) |
| 108 | { |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 109 | if (static_cast<bool>(m_measurementsEntry)) { |
| 110 | m_measurementsEntry->m_nameTreeEntry.reset(); |
| 111 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 112 | m_measurementsEntry = measurements; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 113 | if (static_cast<bool>(m_measurementsEntry)) { |
| 114 | m_measurementsEntry->m_nameTreeEntry = this->shared_from_this(); |
| 115 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 116 | } |
| 117 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 118 | void |
| 119 | Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry) |
| 120 | { |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 121 | if (static_cast<bool>(m_strategyChoiceEntry)) { |
| 122 | m_strategyChoiceEntry->m_nameTreeEntry.reset(); |
| 123 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 124 | m_strategyChoiceEntry = strategyChoiceEntry; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 125 | if (static_cast<bool>(m_strategyChoiceEntry)) { |
| 126 | m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this(); |
| 127 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 128 | } |
| 129 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 130 | } // namespace name_tree |
| 131 | } // namespace nfd |