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 | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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() && |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 61 | m_fibEntry == nullptr && |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 62 | m_pitEntries.empty() && |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 63 | m_measurementsEntry == nullptr && |
| 64 | m_strategyChoiceEntry == nullptr; |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 68 | Entry::setFibEntry(unique_ptr<fib::Entry> fibEntry) |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 69 | { |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 70 | BOOST_ASSERT(fibEntry == nullptr || fibEntry->m_nameTreeEntry.expired()); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 71 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 72 | if (m_fibEntry != nullptr) { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 73 | m_fibEntry->m_nameTreeEntry.reset(); |
| 74 | } |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 75 | m_fibEntry = std::move(fibEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 76 | |
| 77 | if (m_fibEntry != nullptr) { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 78 | m_fibEntry->m_nameTreeEntry = this->shared_from_this(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry) |
| 84 | { |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 85 | BOOST_ASSERT(pitEntry != nullptr); |
| 86 | BOOST_ASSERT(pitEntry->m_nameTreeEntry.expired()); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 87 | |
| 88 | m_pitEntries.push_back(pitEntry); |
| 89 | pitEntry->m_nameTreeEntry = this->shared_from_this(); |
| 90 | } |
| 91 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 92 | void |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 93 | Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 94 | { |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 95 | BOOST_ASSERT(pitEntry != nullptr); |
| 96 | BOOST_ASSERT(pitEntry->m_nameTreeEntry.lock().get() == this); |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 98 | auto it = std::find(m_pitEntries.begin(), m_pitEntries.end(), pitEntry); |
Junxiao Shi | 9f7455b | 2014-04-07 21:02:16 -0700 | [diff] [blame] | 99 | BOOST_ASSERT(it != m_pitEntries.end()); |
| 100 | |
| 101 | *it = m_pitEntries.back(); |
| 102 | m_pitEntries.pop_back(); |
| 103 | pitEntry->m_nameTreeEntry.reset(); |
| 104 | } |
| 105 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 106 | void |
| 107 | Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry) |
| 108 | { |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 109 | BOOST_ASSERT(measurementsEntry == nullptr || measurementsEntry->m_nameTreeEntry.expired()); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 111 | if (m_measurementsEntry != nullptr) { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 112 | m_measurementsEntry->m_nameTreeEntry.reset(); |
| 113 | } |
| 114 | m_measurementsEntry = measurementsEntry; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 115 | |
| 116 | if (m_measurementsEntry != nullptr) { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 117 | m_measurementsEntry->m_nameTreeEntry = this->shared_from_this(); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void |
| 122 | Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry) |
| 123 | { |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 124 | BOOST_ASSERT(strategyChoiceEntry == nullptr || strategyChoiceEntry->m_nameTreeEntry.expired()); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 125 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 126 | if (m_strategyChoiceEntry != nullptr) { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 127 | m_strategyChoiceEntry->m_nameTreeEntry.reset(); |
| 128 | } |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 129 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 130 | m_strategyChoiceEntry = strategyChoiceEntry; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 131 | if (m_strategyChoiceEntry != nullptr) { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 132 | m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this(); |
| 133 | } |
| 134 | } |
| 135 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 136 | } // namespace name_tree |
| 137 | } // namespace nfd |