NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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 
31 Entry::Entry(const Name& name, Node* node)
32  : m_name(name)
33  , m_node(node)
34  , m_parent(nullptr)
35 {
36  BOOST_ASSERT(node != nullptr);
37 }
38 
39 void
41 {
42  BOOST_ASSERT(this->getParent() == nullptr);
43  BOOST_ASSERT(!this->getName().empty());
44  BOOST_ASSERT(entry.getName() == this->getName().getPrefix(-1));
45 
46  m_parent = &entry;
47 
48  m_parent->m_children.push_back(this);
49 }
50 
51 void
53 {
54  BOOST_ASSERT(this->getParent() != nullptr);
55 
56  auto i = std::find(m_parent->m_children.begin(), m_parent->m_children.end(), this);
57  BOOST_ASSERT(i != m_parent->m_children.end());
58  m_parent->m_children.erase(i);
59 
60  m_parent = nullptr;
61 }
62 
63 bool
65 {
66  return m_fibEntry != nullptr ||
67  !m_pitEntries.empty() ||
68  m_measurementsEntry != nullptr ||
69  m_strategyChoiceEntry != nullptr;
70 }
71 
72 void
73 Entry::setFibEntry(unique_ptr<fib::Entry> fibEntry)
74 {
75  BOOST_ASSERT(fibEntry == nullptr || fibEntry->m_nameTreeEntry == nullptr);
76 
77  if (m_fibEntry != nullptr) {
78  m_fibEntry->m_nameTreeEntry = nullptr;
79  }
80  m_fibEntry = std::move(fibEntry);
81 
82  if (m_fibEntry != nullptr) {
83  m_fibEntry->m_nameTreeEntry = this;
84  }
85 }
86 
87 void
88 Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry)
89 {
90  BOOST_ASSERT(pitEntry != nullptr);
91  BOOST_ASSERT(pitEntry->m_nameTreeEntry == nullptr);
92 
93  m_pitEntries.push_back(pitEntry);
94  pitEntry->m_nameTreeEntry = this;
95 }
96 
97 void
99 {
100  BOOST_ASSERT(pitEntry != nullptr);
101  BOOST_ASSERT(pitEntry->m_nameTreeEntry == this);
102 
103  auto it = std::find_if(m_pitEntries.begin(), m_pitEntries.end(),
104  [pitEntry] (const shared_ptr<pit::Entry>& pitEntry2) { return pitEntry2.get() == pitEntry; });
105  BOOST_ASSERT(it != m_pitEntries.end());
106 
107  pitEntry->m_nameTreeEntry = nullptr; // must be done before pitEntry is deallocated
108  *it = m_pitEntries.back(); // may deallocate pitEntry
109  m_pitEntries.pop_back();
110 }
111 
112 void
113 Entry::setMeasurementsEntry(unique_ptr<measurements::Entry> measurementsEntry)
114 {
115  BOOST_ASSERT(measurementsEntry == nullptr || measurementsEntry->m_nameTreeEntry == nullptr);
116 
117  if (m_measurementsEntry != nullptr) {
118  m_measurementsEntry->m_nameTreeEntry = nullptr;
119  }
120  m_measurementsEntry = std::move(measurementsEntry);
121 
122  if (m_measurementsEntry != nullptr) {
123  m_measurementsEntry->m_nameTreeEntry = this;
124  }
125 }
126 
127 void
128 Entry::setStrategyChoiceEntry(unique_ptr<strategy_choice::Entry> strategyChoiceEntry)
129 {
130  BOOST_ASSERT(strategyChoiceEntry == nullptr || strategyChoiceEntry->m_nameTreeEntry == nullptr);
131 
132  if (m_strategyChoiceEntry != nullptr) {
133  m_strategyChoiceEntry->m_nameTreeEntry = nullptr;
134  }
135  m_strategyChoiceEntry = std::move(strategyChoiceEntry);
136 
137  if (m_strategyChoiceEntry != nullptr) {
138  m_strategyChoiceEntry->m_nameTreeEntry = this;
139  }
140 }
141 
142 } // namespace name_tree
143 } // namespace nfd
void insertPitEntry(shared_ptr< pit::Entry > pitEntry)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Definition: name.hpp:241
void erasePitEntry(pit::Entry *pitEntry)
Entry(const Name &prefix, Node *node)
void setParent(Entry &entry)
set parent of this entry
void setMeasurementsEntry(unique_ptr< measurements::Entry > measurementsEntry)
bool hasTableEntries() const
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:57
Name abstraction to represent an absolute name.
Definition: name.hpp:46
void unsetParent()
unset parent of this entry
Entry * getParent() const
const Name & getName() const
void setFibEntry(unique_ptr< fib::Entry > fibEntry)
void setStrategyChoiceEntry(unique_ptr< strategy_choice::Entry > strategyChoiceEntry)
an entry in the name tree