blob: 60d570d2638b31edf1fa1aec55e3a241ff347388 [file] [log] [blame]
HYuana9b85752014-02-26 02:32:30 -06001/* -*- 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
11namespace nfd {
12namespace name_tree {
13
14Node::Node() : m_prev(0), m_next(0)
15{
16}
17
18Node::~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
28Entry::Entry(const Name& name) : m_hash(0), m_prefix(name)
29{
30}
31
32Entry::~Entry()
33{
34}
35
36void
37Entry::setHash(uint32_t hash)
38{
39 m_hash = hash;
40}
41
42void
43Entry::setParent(shared_ptr<Entry> parent)
44{
45 m_parent = parent;
46}
47
48void
Junxiao Shiefceadc2014-03-09 18:52:57 -070049Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
HYuana9b85752014-02-26 02:32:30 -060050{
Junxiao Shiefceadc2014-03-09 18:52:57 -070051 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 }
HYuana9b85752014-02-26 02:32:30 -060058}
59
60void
61Entry::insertPitEntry(shared_ptr<pit::Entry> pit)
62{
HangZhangcb4fc832014-03-11 16:57:11 +080063 if (static_cast<bool>(pit)) {
64 pit->m_nameTreeEntry = this->shared_from_this();
65 m_pitEntries.push_back(pit);
66 }
HYuana9b85752014-02-26 02:32:30 -060067}
68
69bool
70Entry::erasePitEntry(shared_ptr<pit::Entry> pit)
71{
HangZhangcb4fc832014-03-11 16:57:11 +080072 for (size_t i = 0; i < m_pitEntries.size(); i++) {
73 if (m_pitEntries[i] == pit) {
74 BOOST_ASSERT(pit->m_nameTreeEntry);
75
76 pit->m_nameTreeEntry.reset();
HYuana9b85752014-02-26 02:32:30 -060077 // copy the last item to the current position
78 m_pitEntries[i] = m_pitEntries[m_pitEntries.size() - 1];
79 // then erase the last item
80 m_pitEntries.pop_back();
81 return true; // success
HangZhangcb4fc832014-03-11 16:57:11 +080082 }
83 }
HYuana9b85752014-02-26 02:32:30 -060084 // not found this entry
85 return false; // failure
86}
87
88void
89Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements)
90{
HangZhangcb4fc832014-03-11 16:57:11 +080091 if (static_cast<bool>(m_measurementsEntry)) {
92 m_measurementsEntry->m_nameTreeEntry.reset();
93 }
HYuana9b85752014-02-26 02:32:30 -060094 m_measurementsEntry = measurements;
HangZhangcb4fc832014-03-11 16:57:11 +080095 if (static_cast<bool>(m_measurementsEntry)) {
96 m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
97 }
HYuana9b85752014-02-26 02:32:30 -060098}
99
Junxiao Shibb5105f2014-03-03 12:06:45 -0700100void
101Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
102{
Junxiao Shiefceadc2014-03-09 18:52:57 -0700103 if (static_cast<bool>(m_strategyChoiceEntry)) {
104 m_strategyChoiceEntry->m_nameTreeEntry.reset();
105 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700106 m_strategyChoiceEntry = strategyChoiceEntry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700107 if (static_cast<bool>(m_strategyChoiceEntry)) {
108 m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
109 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700110}
111
HYuana9b85752014-02-26 02:32:30 -0600112} // namespace name_tree
113} // namespace nfd