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 |
| 49 | Entry::setFibEntry(shared_ptr<fib::Entry> fib) |
| 50 | { |
| 51 | m_fibEntry = fib; |
| 52 | } |
| 53 | |
| 54 | bool |
| 55 | Entry::eraseFibEntry(shared_ptr<fib::Entry> fib) |
| 56 | { |
| 57 | if (m_fibEntry != fib) |
| 58 | return false; |
| 59 | m_fibEntry.reset(); |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | Entry::insertPitEntry(shared_ptr<pit::Entry> pit) |
| 65 | { |
| 66 | m_pitEntries.push_back(pit); |
| 67 | } |
| 68 | |
| 69 | bool |
| 70 | Entry::erasePitEntry(shared_ptr<pit::Entry> pit) |
| 71 | { |
| 72 | for (size_t i = 0; i < m_pitEntries.size(); i++) |
| 73 | { |
| 74 | if (m_pitEntries[i] == pit) |
| 75 | { |
| 76 | // copy the last item to the current position |
| 77 | m_pitEntries[i] = m_pitEntries[m_pitEntries.size() - 1]; |
| 78 | // then erase the last item |
| 79 | m_pitEntries.pop_back(); |
| 80 | return true; // success |
| 81 | } |
| 82 | } |
| 83 | // not found this entry |
| 84 | return false; // failure |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements) |
| 89 | { |
| 90 | m_measurementsEntry = measurements; |
| 91 | } |
| 92 | |
| 93 | bool |
| 94 | Entry::eraseMeasurementsEntry(shared_ptr<measurements::Entry> measurements) |
| 95 | { |
| 96 | if (m_measurementsEntry != measurements) |
| 97 | return false; |
| 98 | m_measurementsEntry.reset(); |
| 99 | return true; |
| 100 | } |
| 101 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 102 | void |
| 103 | Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry) |
| 104 | { |
| 105 | m_strategyChoiceEntry = strategyChoiceEntry; |
| 106 | } |
| 107 | |
HYuan | a9b8575 | 2014-02-26 02:32:30 -0600 | [diff] [blame] | 108 | } // namespace name_tree |
| 109 | } // namespace nfd |