table: don't use shared_ptr in FIB
refs #3164
Change-Id: I5b5eb47d60f6bf5b6389c32ac840f793767e4334
diff --git a/daemon/table/fib.hpp b/daemon/table/fib.hpp
index bde7428..bfe6684 100644
--- a/daemon/table/fib.hpp
+++ b/daemon/table/fib.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,13 +33,14 @@
namespace measurements {
class Entry;
-}
+} // namespace measurements
namespace pit {
class Entry;
-}
+} // namespace pit
-/** \class Fib
- * \brief represents the FIB
+namespace fib {
+
+/** \brief represents the Forwarding Information Base (FIB)
*/
class Fib : noncopyable
{
@@ -53,44 +54,54 @@
size() const;
public: // lookup
- /// performs a longest prefix match
- shared_ptr<fib::Entry>
+ /** \brief performs a longest prefix match
+ */
+ const Entry&
findLongestPrefixMatch(const Name& prefix) const;
- /// performs a longest prefix match
- shared_ptr<fib::Entry>
+ /** \brief performs a longest prefix match
+ *
+ * This is equivalent to .findLongestPrefixMatch(pitEntry.getName())
+ */
+ const Entry&
findLongestPrefixMatch(const pit::Entry& pitEntry) const;
- /// performs a longest prefix match
- shared_ptr<fib::Entry>
+ /** \brief performs a longest prefix match
+ *
+ * This is equivalent to .findLongestPrefixMatch(measurementsEntry.getName())
+ */
+ const Entry&
findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;
- shared_ptr<fib::Entry>
- findExactMatch(const Name& prefix) const;
+ /** \brief performs an exact match lookup
+ */
+ Entry*
+ findExactMatch(const Name& prefix);
public: // mutation
/** \brief inserts a FIB entry for prefix
+ *
* If an entry for exact same prefix exists, that entry is returned.
- * \return{ the entry, and true for new entry, false for existing entry }
+ * \return the entry, and true for new entry or false for existing entry
*/
- std::pair<shared_ptr<fib::Entry>, bool>
+ std::pair<Entry*, bool>
insert(const Name& prefix);
void
erase(const Name& prefix);
void
- erase(const fib::Entry& entry);
+ erase(const Entry& entry);
- /** \brief removes the NextHop record for face in all entrites
+ /** \brief removes the NextHop record for face in all entries
*
- * This is usually invoked when face goes away.
+ * This is usually invoked when face is destroyed.
* Removing the last NextHop in a FIB entry will erase the FIB entry.
*
* \todo change parameter type to Face&
*/
void
- removeNextHopFromAllEntries(shared_ptr<Face> face);
+ removeNextHopFromAllEntries(const Face& face);
public: // enumeration
class const_iterator;
@@ -110,7 +121,7 @@
const_iterator
end() const;
- class const_iterator : public std::iterator<std::forward_iterator_tag, const fib::Entry>
+ class const_iterator : public std::iterator<std::forward_iterator_tag, const Entry>
{
public:
const_iterator() = default;
@@ -120,10 +131,10 @@
~const_iterator();
- const fib::Entry&
+ const Entry&
operator*() const;
- shared_ptr<fib::Entry>
+ const Entry*
operator->() const;
const_iterator&
@@ -143,8 +154,8 @@
};
private:
- shared_ptr<fib::Entry>
- findLongestPrefixMatch(shared_ptr<name_tree::Entry> nameTreeEntry) const;
+ const Entry&
+ findLongestPrefixMatch(shared_ptr<name_tree::Entry> nte) const;
void
erase(shared_ptr<name_tree::Entry> nameTreeEntry);
@@ -153,13 +164,12 @@
NameTree& m_nameTree;
size_t m_nItems;
- /** \brief The empty FIB entry.
+ /** \brief the empty FIB entry.
*
* This entry has no nexthops.
* It is returned by findLongestPrefixMatch if nothing is matched.
- * Returning empty entry instead of nullptr makes forwarding and strategy implementation easier.
*/
- static const shared_ptr<fib::Entry> s_emptyEntry;
+ static const unique_ptr<Entry> s_emptyEntry;
};
inline size_t
@@ -189,7 +199,7 @@
Fib::const_iterator
Fib::const_iterator::operator++(int)
{
- Fib::const_iterator temp(*this);
+ const_iterator temp(*this);
++(*this);
return temp;
}
@@ -201,30 +211,34 @@
return *this;
}
-inline const fib::Entry&
+inline const Entry&
Fib::const_iterator::operator*() const
{
- return *this->operator->();
+ return *m_nameTreeIterator->getFibEntry();
}
-inline shared_ptr<fib::Entry>
+inline const Entry*
Fib::const_iterator::operator->() const
{
return m_nameTreeIterator->getFibEntry();
}
inline bool
-Fib::const_iterator::operator==(const Fib::const_iterator& other) const
+Fib::const_iterator::operator==(const const_iterator& other) const
{
return m_nameTreeIterator == other.m_nameTreeIterator;
}
inline bool
-Fib::const_iterator::operator!=(const Fib::const_iterator& other) const
+Fib::const_iterator::operator!=(const const_iterator& other) const
{
return m_nameTreeIterator != other.m_nameTreeIterator;
}
+} // namespace fib
+
+using fib::Fib;
+
} // namespace nfd
#endif // NFD_DAEMON_TABLE_FIB_HPP