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 | |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 46 | Entry::Entry(const Name& name) |
| 47 | : m_hash(0) |
| 48 | , m_prefix(name) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
| 52 | Entry::~Entry() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | Entry::setHash(uint32_t hash) |
| 58 | { |
| 59 | m_hash = hash; |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | Entry::setParent(shared_ptr<Entry> parent) |
| 64 | { |
| 65 | m_parent = parent; |
| 66 | } |
| 67 | |
| 68 | void |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 69 | Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 70 | { |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 71 | if (static_cast<bool>(fibEntry)) { |
| 72 | BOOST_ASSERT(!static_cast<bool>(fibEntry->m_nameTreeEntry)); |
| 73 | } |
| 74 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 75 | 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 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 85 | Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 86 | { |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 87 | BOOST_ASSERT(static_cast<bool>(pitEntry)); |
| 88 | BOOST_ASSERT(!static_cast<bool>(pitEntry->m_nameTreeEntry)); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 89 | |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 90 | m_pitEntries.push_back(pitEntry); |
| 91 | pitEntry->m_nameTreeEntry = this->shared_from_this(); |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 95 | Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 96 | { |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 97 | 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 | |
| 109 | void |
| 110 | Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry) |
| 111 | { |
| 112 | if (static_cast<bool>(measurementsEntry)) { |
| 113 | BOOST_ASSERT(!static_cast<bool>(measurementsEntry->m_nameTreeEntry)); |
| 114 | } |
| 115 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 116 | if (static_cast<bool>(m_measurementsEntry)) { |
| 117 | m_measurementsEntry->m_nameTreeEntry.reset(); |
| 118 | } |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 119 | m_measurementsEntry = measurementsEntry; |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 120 | if (static_cast<bool>(m_measurementsEntry)) { |
| 121 | m_measurementsEntry->m_nameTreeEntry = this->shared_from_this(); |
| 122 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 123 | } |
| 124 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 125 | void |
| 126 | Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry) |
| 127 | { |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 128 | if (static_cast<bool>(strategyChoiceEntry)) { |
| 129 | BOOST_ASSERT(!static_cast<bool>(strategyChoiceEntry->m_nameTreeEntry)); |
| 130 | } |
| 131 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 132 | if (static_cast<bool>(m_strategyChoiceEntry)) { |
| 133 | m_strategyChoiceEntry->m_nameTreeEntry.reset(); |
| 134 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 135 | m_strategyChoiceEntry = strategyChoiceEntry; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 136 | if (static_cast<bool>(m_strategyChoiceEntry)) { |
| 137 | m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this(); |
| 138 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 139 | } |
| 140 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 141 | } // namespace name_tree |
| 142 | } // namespace nfd |