HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -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 | * The University of Memphis |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 24 | */ |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 25 | |
| 26 | #include "name-tree-entry.hpp" |
| 27 | |
| 28 | namespace nfd { |
| 29 | namespace name_tree { |
| 30 | |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 31 | Node::Node() |
| 32 | : m_prev(0) |
| 33 | , m_next(0) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
| 37 | Node::~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 Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 43 | if (m_next != 0) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 44 | delete m_next; |
| 45 | } |
| 46 | |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 47 | Entry::Entry(const Name& name) |
| 48 | : m_hash(0) |
| 49 | , m_prefix(name) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 50 | { |
| 51 | } |
| 52 | |
| 53 | Entry::~Entry() |
| 54 | { |
| 55 | } |
| 56 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 57 | bool |
| 58 | Entry::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 | |
| 67 | void |
| 68 | Entry::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 | |
| 83 | void |
| 84 | Entry::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 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 93 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 94 | Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 95 | { |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 96 | 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 Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 108 | void |
| 109 | Entry::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 | |
| 124 | void |
| 125 | Entry::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 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 140 | } // namespace name_tree |
| 141 | } // namespace nfd |