blob: 673be4777d49d873b02fb752a03043a36b92339d [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
49Entry::setFibEntry(shared_ptr<fib::Entry> fib)
50{
51 m_fibEntry = fib;
52}
53
54bool
55Entry::eraseFibEntry(shared_ptr<fib::Entry> fib)
56{
57 if (m_fibEntry != fib)
58 return false;
59 m_fibEntry.reset();
60 return true;
61}
62
63void
64Entry::insertPitEntry(shared_ptr<pit::Entry> pit)
65{
66 m_pitEntries.push_back(pit);
67}
68
69bool
70Entry::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
87void
88Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurements)
89{
90 m_measurementsEntry = measurements;
91}
92
93bool
94Entry::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 Shibb5105f2014-03-03 12:06:45 -0700102void
103Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
104{
105 m_strategyChoiceEntry = strategyChoiceEntry;
106}
107
HYuana9b85752014-02-26 02:32:30 -0600108} // namespace name_tree
109} // namespace nfd