table: NameTree code style corrections

refs #3687

Change-Id: I25cfac1d8b11236c251c2ab717facb82b62dcb10
diff --git a/daemon/table/name-tree.hpp b/daemon/table/name-tree.hpp
index b047696..460e497 100644
--- a/daemon/table/name-tree.hpp
+++ b/daemon/table/name-tree.hpp
@@ -32,49 +32,46 @@
 namespace nfd {
 namespace name_tree {
 
-/**
- * \brief Compute the hash value of the given name prefix's WIRE FORMAT
+/** \brief Compute the hash value of the given name prefix's WIRE FORMAT
  */
 size_t
 computeHash(const Name& prefix);
 
-/**
- * \brief Incrementally compute hash values
- * \return Return a vector of hash values, starting from the root prefix
+/** \brief Incrementally compute hash values
+ *  \return Return a vector of hash values, starting from the root prefix
  */
 std::vector<size_t>
 computeHashSet(const Name& prefix);
 
-/// a predicate to accept or reject an Entry in find operations
-typedef function<bool (const Entry& entry)> EntrySelector;
-
-/**
- * \brief a predicate to accept or reject an Entry and its children
- * \return .first indicates whether entry should be accepted;
- *         .second indicates whether entry's children should be visited
+/** \brief a predicate to accept or reject an Entry in find operations
  */
-typedef function<std::pair<bool,bool> (const Entry& entry)> EntrySubTreeSelector;
+typedef function<bool(const Entry& entry)> EntrySelector;
 
-struct AnyEntry {
+/** \brief a predicate to accept or reject an Entry and its children
+ *  \return .first indicates whether entry should be accepted;
+ *          .second indicates whether entry's children should be visited
+ */
+typedef function<std::pair<bool,bool>(const Entry& entry)> EntrySubTreeSelector;
+
+struct AnyEntry
+{
   bool
-  operator()(const Entry& entry)
+  operator()(const Entry& entry) const
   {
     return true;
   }
 };
 
-struct AnyEntrySubTree {
+struct AnyEntrySubTree
+{
   std::pair<bool, bool>
-  operator()(const Entry& entry)
+  operator()(const Entry& entry) const
   {
-    return std::make_pair(true, true);
+    return {true, true};
   }
 };
 
-} // namespace name_tree
-
-/**
- * \brief Class Name Tree
+/** \brief shared name-based index for FIB, PIT, Measurements, and StrategyChoice
  */
 class NameTree : noncopyable
 {
@@ -87,16 +84,15 @@
   ~NameTree();
 
 public: // information
-  /**
-   * \brief Get the number of occupied entries in the Name Tree
+  /** \brief Get the number of occupied entries in the Name Tree
    */
   size_t
   size() const;
 
-  /**
-   * \brief Get the number of buckets in the Name Tree (NPHT)
-   * \details The number of buckets is the one that used to create the hash
-   * table, i.e., m_nBuckets.
+  /** \brief Get the number of buckets in the Name Tree (NPHT)
+   *
+   *  The number of buckets is the one that used to create the hash
+   *  table, i.e., m_nBuckets.
    */
   size_t
   getNBuckets() const;
@@ -104,97 +100,91 @@
   /** \return Name Tree Entry on which a table entry is attached
    */
   template<typename ENTRY>
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   getEntry(const ENTRY& tableEntry) const;
 
-  /**
-   * \brief Dump all the information stored in the Name Tree for debugging.
+  /** \brief Dump all the information stored in the Name Tree for debugging.
    */
   void
   dump(std::ostream& output) const;
 
 public: // mutation
-  /**
-   * \brief Look for the Name Tree Entry that contains this name prefix.
-   * \details Starts from the shortest name prefix, and then increase the
-   * number of name components by one each time. All non-existing Name Tree
-   * Entries will be created.
-   * \param prefix The querying name prefix.
-   * \return The pointer to the Name Tree Entry that contains this full name
-   * prefix.
-   * \note Existing iterators are unaffected.
+  /** \brief Look for the Name Tree Entry that contains this name prefix.
+   *
+   *  Starts from the shortest name prefix, and then increase the
+   *  number of name components by one each time. All non-existing Name Tree
+   *  Entries will be created.
+   *
+   *  \param prefix The querying name prefix.
+   *  \return The pointer to the Name Tree Entry that contains this full name prefix.
+   *  \note Existing iterators are unaffected.
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   lookup(const Name& prefix);
 
   /** \brief get NameTree entry from FIB entry
    *
    *  This is equivalent to .lookup(fibEntry.getPrefix())
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   lookup(const fib::Entry& fibEntry) const;
 
   /** \brief get NameTree entry from PIT entry
    *
    *  This is equivalent to .lookup(pitEntry.getName()).
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   lookup(const pit::Entry& pitEntry);
 
   /** \brief get NameTree entry from Measurements entry
    *
    *  This is equivalent to .lookup(measurementsEntry.getName())
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   lookup(const measurements::Entry& measurementsEntry) const;
 
   /** \brief get NameTree entry from StrategyChoice entry
    *
    *  This is equivalent to .lookup(strategyChoiceEntry.getName())
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   lookup(const strategy_choice::Entry& strategyChoiceEntry) const;
 
-  /**
-   * \brief Delete a Name Tree Entry if this entry is empty.
-   * \param entry The entry to be deleted if empty.
-   * \note This function must be called after a table entry is detached from Name Tree
-   *       entry. The function deletes a Name Tree entry if nothing is attached to it and
-   *       it has no children, then repeats the same process on its ancestors.
-   * \note Existing iterators, except those pointing to deleted entries, are unaffected.
+  /** \brief Delete a Name Tree Entry if this entry is empty.
+   *  \param entry The entry to be deleted if empty.
+   *  \note This function must be called after a table entry is detached from Name Tree
+   *        entry. The function deletes a Name Tree entry if nothing is attached to it and
+   *        it has no children, then repeats the same process on its ancestors.
+   *  \note Existing iterators, except those pointing to deleted entries, are unaffected.
    */
   bool
-  eraseEntryIfEmpty(shared_ptr<name_tree::Entry> entry);
+  eraseEntryIfEmpty(shared_ptr<Entry> entry);
 
 public: // matching
-  /**
-   * \brief Exact match lookup for the given name prefix.
-   * \return a null shared_ptr if this prefix is not found;
-   * otherwise return the Name Tree Entry address
+  /** \brief Exact match lookup for the given name prefix.
+   *  \return nullptr if this prefix is not found; otherwise return the Name Tree Entry address
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   findExactMatch(const Name& prefix) const;
 
-  /**
-   * \brief Longest prefix matching for the given name
-   * \details Starts from the full name string, reduce the number of name component
-   * by one each time, until an Entry is found.
+  /** \brief Longest prefix matching for the given name
+   *
+   *  Starts from the full name string, reduce the number of name component
+   *  by one each time, until an Entry is found.
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   findLongestPrefixMatch(const Name& prefix,
-                         const name_tree::EntrySelector& entrySelector =
-                         name_tree::AnyEntry()) const;
+                         const EntrySelector& entrySelector = AnyEntry()) const;
 
-  shared_ptr<name_tree::Entry>
-  findLongestPrefixMatch(shared_ptr<name_tree::Entry> entry,
-                         const name_tree::EntrySelector& entrySelector =
-                         name_tree::AnyEntry()) const;
+  shared_ptr<Entry>
+  findLongestPrefixMatch(shared_ptr<Entry> entry,
+                         const EntrySelector& entrySelector = AnyEntry()) const;
 
   /** \brief longest prefix matching for Interest name of the PIT entry
    *
    *  This is equivalent to .findLongestPrefixMatch(pitEntry.getName(), AnyEntry()).
    */
-  shared_ptr<name_tree::Entry>
+  shared_ptr<Entry>
   findLongestPrefixMatch(const pit::Entry& pitEntry) const;
 
   /** \brief Enumerate all the name prefixes that satisfy the prefix and entrySelector
@@ -204,7 +194,7 @@
    *  Example:
    *  \code{.cpp}
    *  auto&& allMatches = nt.findAllMatches(Name("/A/B/C"));
-   *  for (const name_tree::Entry& nte : allMatches) {
+   *  for (const Entry& nte : allMatches) {
    *    ...
    *  }
    *  \endcode
@@ -213,7 +203,7 @@
    */
   boost::iterator_range<const_iterator>
   findAllMatches(const Name& prefix,
-                 const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry()) const;
+                 const EntrySelector& entrySelector = AnyEntry()) const;
 
 public: // enumeration
   /** \brief Enumerate all entries, optionally filtered by an EntrySelector.
@@ -223,7 +213,7 @@
    *  Example:
    *  \code{.cpp}
    *  auto&& enumerable = nt.fullEnumerate();
-   *  for (const name_tree::Entry& nte : enumerable) {
+   *  for (const Entry& nte : enumerable) {
    *    ...
    *  }
    *  \endcode
@@ -231,7 +221,7 @@
    *  \note The returned iterator may get invalidated when NameTree is modified
    */
   boost::iterator_range<const_iterator>
-  fullEnumerate(const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry()) const;
+  fullEnumerate(const EntrySelector& entrySelector = AnyEntry()) const;
 
   /** \brief Enumerate all entries under a prefix, optionally filtered by an EntrySubTreeSelector.
    *  \return an unspecified type that have .begin() and .end() methods
@@ -240,7 +230,7 @@
    *  Example:
    *  \code{.cpp}
    *  auto&& enumerable = nt.partialEnumerate(Name("/A/B/C"));
-   *  for (const name_tree::Entry& nte : enumerable) {
+   *  for (const Entry& nte : enumerable) {
    *    ...
    *  }
    *  \endcode
@@ -249,8 +239,7 @@
    */
   boost::iterator_range<const_iterator>
   partialEnumerate(const Name& prefix,
-                   const name_tree::EntrySubTreeSelector& entrySubTreeSelector =
-                         name_tree::AnyEntrySubTree()) const;
+                   const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree()) const;
 
   /** \brief Get an iterator pointing to the first NameTree entry
    *  \note Iteration order is implementation-specific and is undefined
@@ -272,7 +261,7 @@
     FIND_ALL_MATCHES_TYPE
   };
 
-  class const_iterator : public std::iterator<std::forward_iterator_tag, const name_tree::Entry>
+  class const_iterator : public std::iterator<std::forward_iterator_tag, const Entry>
   {
   public:
     friend class NameTree;
@@ -280,17 +269,15 @@
     const_iterator();
 
     const_iterator(NameTree::IteratorType type,
-      const NameTree& nameTree,
-      shared_ptr<name_tree::Entry> entry,
-      const name_tree::EntrySelector& entrySelector = name_tree::AnyEntry(),
-      const name_tree::EntrySubTreeSelector& entrySubTreeSelector = name_tree::AnyEntrySubTree());
+                   const NameTree& nameTree,
+                   shared_ptr<Entry> entry,
+                   const EntrySelector& entrySelector = AnyEntry(),
+                   const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree());
 
-    ~const_iterator();
-
-    const name_tree::Entry&
+    const Entry&
     operator*() const;
 
-    shared_ptr<name_tree::Entry>
+    shared_ptr<Entry>
     operator->() const;
 
     const_iterator
@@ -306,56 +293,53 @@
     operator!=(const const_iterator& other) const;
 
   private:
-    const NameTree*                             m_nameTree;
-    shared_ptr<name_tree::Entry>                m_entry;
-    shared_ptr<name_tree::Entry>                m_subTreeRoot;
-    shared_ptr<name_tree::EntrySelector>        m_entrySelector;
-    shared_ptr<name_tree::EntrySubTreeSelector> m_entrySubTreeSelector;
-    NameTree::IteratorType                      m_type;
-    bool                                        m_shouldVisitChildren;
+    const NameTree* m_nameTree;
+    shared_ptr<Entry> m_entry;
+    shared_ptr<Entry> m_subTreeRoot;
+    shared_ptr<EntrySelector> m_entrySelector;
+    shared_ptr<EntrySubTreeSelector> m_entrySubTreeSelector;
+    NameTree::IteratorType m_type;
+    bool m_shouldVisitChildren;
   };
 
 private:
-  /**
-   * \brief Create a Name Tree Entry if it does not exist, or return the existing
-   * Name Tree Entry address.
-   * \details Called by lookup() only.
-   * \return The first item is the Name Tree Entry address, the second item is
-   * a bool value indicates whether this is an old entry (false) or a new
-   * entry (true).
+  /** \brief Create a Name Tree Entry if it does not exist, or return the existing
+   *         Name Tree Entry address.
+   *
+   *  Called by lookup() only.
+   *
+   *  \return The first item is the Name Tree Entry address, the second item is
+   *          a bool value indicates whether this is an old entry (false) or a new
+   *          entry (true).
    */
-  std::pair<shared_ptr<name_tree::Entry>, bool>
+  std::pair<shared_ptr<Entry>, bool>
   insert(const Name& prefix);
 
-  /**
-   * \brief Resize the hash table size when its load factor reaches a threshold.
-   * \details As we are currently using a hand-written hash table implementation
-   * for the Name Tree, the hash table resize() function should be kept in the
-   * name-tree.hpp file.
-   * \param newNBuckets The number of buckets for the new hash table.
+  /** \brief Resize the hash table size when its load factor reaches a threshold.
+   *
+   *  As we are currently using a hand-written hash table implementation
+   *  for the Name Tree, the hash table resize() function should be kept in the
+   *  name-tree.hpp file.
+   *  \param newNBuckets The number of buckets for the new hash table.
    */
   void
   resize(size_t newNBuckets);
 
 private:
-  size_t                        m_nItems;  // Number of items being stored
-  size_t                        m_nBuckets; // Number of hash buckets
-  size_t                        m_minNBuckets; // Minimum number of hash buckets
-  double                        m_enlargeLoadFactor;
-  size_t                        m_enlargeThreshold;
-  int                           m_enlargeFactor;
-  double                        m_shrinkLoadFactor;
-  size_t                        m_shrinkThreshold;
-  double                        m_shrinkFactor;
-  name_tree::Node**             m_buckets; // Name Tree Buckets in the NPHT
-  shared_ptr<name_tree::Entry>  m_end;
-  const_iterator                m_endIterator;
+  size_t m_nItems;  ///< Number of items being stored
+  size_t m_nBuckets; ///< Number of hash buckets
+  size_t m_minNBuckets; ///< Minimum number of hash buckets
+  double m_enlargeLoadFactor;
+  size_t m_enlargeThreshold;
+  int m_enlargeFactor;
+  double m_shrinkLoadFactor;
+  size_t m_shrinkThreshold;
+  double m_shrinkFactor;
+  Node** m_buckets; ///< Name Tree Buckets in the NPHT
+  shared_ptr<Entry> m_end;
+  const_iterator m_endIterator;
 };
 
-inline NameTree::const_iterator::~const_iterator()
-{
-}
-
 inline size_t
 NameTree::size() const
 {
@@ -369,7 +353,7 @@
 }
 
 template<typename ENTRY>
-inline shared_ptr<name_tree::Entry>
+inline shared_ptr<Entry>
 NameTree::getEntry(const ENTRY& tableEntry) const
 {
   return tableEntry.m_nameTreeEntry.lock();
@@ -387,13 +371,13 @@
   return m_endIterator;
 }
 
-inline const name_tree::Entry&
+inline const Entry&
 NameTree::const_iterator::operator*() const
 {
   return *m_entry;
 }
 
-inline shared_ptr<name_tree::Entry>
+inline shared_ptr<Entry>
 NameTree::const_iterator::operator->() const
 {
   return m_entry;
@@ -419,6 +403,10 @@
   return m_entry != other.m_entry;
 }
 
+} // namespace name_tree
+
+using name_tree::NameTree;
+
 } // namespace nfd
 
 #endif // NFD_DAEMON_TABLE_NAME_TREE_HPP