NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
name-tree-entry.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "name-tree-entry.hpp"
27 
28 namespace nfd {
29 namespace name_tree {
30 
32  : m_prev(0)
33  , m_next(0)
34 {
35 }
36 
38 {
39  // erase the Name Tree Nodes that were created to
40  // resolve hash collisions
41  // So before erasing a single node, make sure its m_next == 0
42  // See eraseEntryIfEmpty in name-tree.cpp
43  if (m_next != 0)
44  delete m_next;
45 }
46 
47 Entry::Entry(const Name& name)
48  : m_hash(0)
49  , m_prefix(name)
50 {
51 }
52 
54 {
55 }
56 
57 bool
59 {
60  return m_children.empty() &&
61  !static_cast<bool>(m_fibEntry) &&
62  m_pitEntries.empty() &&
63  !static_cast<bool>(m_measurementsEntry) &&
64  !static_cast<bool>(m_strategyChoiceEntry);
65 }
66 
67 void
68 Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
69 {
70  if (static_cast<bool>(fibEntry)) {
71  BOOST_ASSERT(!static_cast<bool>(fibEntry->m_nameTreeEntry));
72  }
73 
74  if (static_cast<bool>(m_fibEntry)) {
75  m_fibEntry->m_nameTreeEntry.reset();
76  }
77  m_fibEntry = fibEntry;
78  if (static_cast<bool>(m_fibEntry)) {
79  m_fibEntry->m_nameTreeEntry = this->shared_from_this();
80  }
81 }
82 
83 void
84 Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry)
85 {
86  BOOST_ASSERT(static_cast<bool>(pitEntry));
87  BOOST_ASSERT(!static_cast<bool>(pitEntry->m_nameTreeEntry));
88 
89  m_pitEntries.push_back(pitEntry);
90  pitEntry->m_nameTreeEntry = this->shared_from_this();
91 }
92 
93 void
94 Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
95 {
96  BOOST_ASSERT(static_cast<bool>(pitEntry));
97  BOOST_ASSERT(pitEntry->m_nameTreeEntry.get() == this);
98 
99  std::vector<shared_ptr<pit::Entry> >::iterator it =
100  std::find(m_pitEntries.begin(), m_pitEntries.end(), pitEntry);
101  BOOST_ASSERT(it != m_pitEntries.end());
102 
103  *it = m_pitEntries.back();
104  m_pitEntries.pop_back();
105  pitEntry->m_nameTreeEntry.reset();
106 }
107 
108 void
109 Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry)
110 {
111  if (static_cast<bool>(measurementsEntry)) {
112  BOOST_ASSERT(!static_cast<bool>(measurementsEntry->m_nameTreeEntry));
113  }
114 
115  if (static_cast<bool>(m_measurementsEntry)) {
116  m_measurementsEntry->m_nameTreeEntry.reset();
117  }
118  m_measurementsEntry = measurementsEntry;
119  if (static_cast<bool>(m_measurementsEntry)) {
120  m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
121  }
122 }
123 
124 void
125 Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
126 {
127  if (static_cast<bool>(strategyChoiceEntry)) {
128  BOOST_ASSERT(!static_cast<bool>(strategyChoiceEntry->m_nameTreeEntry));
129  }
130 
131  if (static_cast<bool>(m_strategyChoiceEntry)) {
132  m_strategyChoiceEntry->m_nameTreeEntry.reset();
133  }
134  m_strategyChoiceEntry = strategyChoiceEntry;
135  if (static_cast<bool>(m_strategyChoiceEntry)) {
136  m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
137  }
138 }
139 
140 } // namespace name_tree
141 } // namespace nfd
void insertPitEntry(shared_ptr< pit::Entry > pitEntry)
void erasePitEntry(shared_ptr< pit::Entry > pitEntry)
void setStrategyChoiceEntry(shared_ptr< strategy_choice::Entry > strategyChoiceEntry)
void setFibEntry(shared_ptr< fib::Entry > fibEntry)
void setMeasurementsEntry(shared_ptr< measurements::Entry > measurementsEntry)
Entry(const Name &prefix)