blob: dd7bf4b806291f8c1d888cabfd4251179c3b1b13 [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{
63 m_pitEntries.push_back(pit);
64}
65
66bool
67Entry::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
84void
85Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements)
86{
87 m_measurementsEntry = measurements;
88}
89
90bool
91Entry::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 Shibb5105f2014-03-03 12:06:45 -070099void
100Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
101{
Junxiao Shiefceadc2014-03-09 18:52:57 -0700102 if (static_cast<bool>(m_strategyChoiceEntry)) {
103 m_strategyChoiceEntry->m_nameTreeEntry.reset();
104 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700105 m_strategyChoiceEntry = strategyChoiceEntry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700106 if (static_cast<bool>(m_strategyChoiceEntry)) {
107 m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
108 }
Junxiao Shibb5105f2014-03-03 12:06:45 -0700109}
110
HYuana9b85752014-02-26 02:32:30 -0600111} // namespace name_tree
112} // namespace nfd