HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | // Name Tree Entry (i.e., Name Prefix Entry) |
| 8 | |
| 9 | #include "name-tree-entry.hpp" |
| 10 | |
| 11 | namespace nfd { |
| 12 | namespace name_tree { |
| 13 | |
| 14 | Node::Node() : m_prev(0), m_next(0) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | Node::~Node() |
| 19 | { |
| 20 | // erase the Name Tree Nodes that were created to |
| 21 | // resolve hash collisions |
| 22 | // So before erasing a single node, make sure its m_next == 0 |
| 23 | // See eraseEntryIfEmpty in name-tree.cpp |
| 24 | if (m_next) |
| 25 | delete m_next; |
| 26 | } |
| 27 | |
| 28 | Entry::Entry(const Name& name) : m_hash(0), m_prefix(name) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | Entry::~Entry() |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | Entry::setHash(uint32_t hash) |
| 38 | { |
| 39 | m_hash = hash; |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | Entry::setParent(shared_ptr<Entry> parent) |
| 44 | { |
| 45 | m_parent = parent; |
| 46 | } |
| 47 | |
| 48 | void |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 49 | Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry) |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 50 | { |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 51 | if (static_cast<bool>(m_fibEntry)) { |
| 52 | m_fibEntry->m_nameTreeEntry.reset(); |
| 53 | } |
| 54 | m_fibEntry = fibEntry; |
| 55 | if (static_cast<bool>(m_fibEntry)) { |
| 56 | m_fibEntry->m_nameTreeEntry = this->shared_from_this(); |
| 57 | } |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void |
| 61 | Entry::insertPitEntry(shared_ptr<pit::Entry> pit) |
| 62 | { |
| 63 | m_pitEntries.push_back(pit); |
| 64 | } |
| 65 | |
| 66 | bool |
| 67 | Entry::erasePitEntry(shared_ptr<pit::Entry> pit) |
| 68 | { |
| 69 | for (size_t i = 0; i < m_pitEntries.size(); i++) |
| 70 | { |
| 71 | if (m_pitEntries[i] == pit) |
| 72 | { |
| 73 | // copy the last item to the current position |
| 74 | m_pitEntries[i] = m_pitEntries[m_pitEntries.size() - 1]; |
| 75 | // then erase the last item |
| 76 | m_pitEntries.pop_back(); |
| 77 | return true; // success |
| 78 | } |
| 79 | } |
| 80 | // not found this entry |
| 81 | return false; // failure |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements) |
| 86 | { |
| 87 | m_measurementsEntry = measurements; |
| 88 | } |
| 89 | |
| 90 | bool |
| 91 | Entry::eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements) |
| 92 | { |
| 93 | if (m_measurementsEntry != measurements) |
| 94 | return false; |
| 95 | m_measurementsEntry.reset(); |
| 96 | return true; |
| 97 | } |
| 98 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 99 | void |
| 100 | Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry) |
| 101 | { |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 102 | if (static_cast<bool>(m_strategyChoiceEntry)) { |
| 103 | m_strategyChoiceEntry->m_nameTreeEntry.reset(); |
| 104 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 105 | m_strategyChoiceEntry = strategyChoiceEntry; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 106 | if (static_cast<bool>(m_strategyChoiceEntry)) { |
| 107 | m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this(); |
| 108 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 109 | } |
| 110 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 111 | } // namespace name_tree |
| 112 | } // namespace nfd |