table: refactor NameTree iterator

refs #3687

Change-Id: Icf5be98d79cfaa27597f62832fcd0189df2731d1
diff --git a/daemon/table/name-tree.hpp b/daemon/table/name-tree.hpp
index fa20034..91ec3fa 100644
--- a/daemon/table/name-tree.hpp
+++ b/daemon/table/name-tree.hpp
@@ -26,8 +26,7 @@
 #ifndef NFD_DAEMON_TABLE_NAME_TREE_HPP
 #define NFD_DAEMON_TABLE_NAME_TREE_HPP
 
-#include "core/common.hpp"
-#include "name-tree-entry.hpp"
+#include "name-tree-iterator.hpp"
 
 namespace nfd {
 namespace name_tree {
@@ -43,40 +42,12 @@
 std::vector<size_t>
 computeHashSet(const Name& prefix);
 
-/** \brief 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
- */
-typedef function<std::pair<bool,bool>(const Entry& entry)> EntrySubTreeSelector;
-
-struct AnyEntry
-{
-  bool
-  operator()(const Entry& entry) const
-  {
-    return true;
-  }
-};
-
-struct AnyEntrySubTree
-{
-  std::pair<bool, bool>
-  operator()(const Entry& entry) const
-  {
-    return {true, true};
-  }
-};
-
 /** \brief shared name-based index for FIB, PIT, Measurements, and StrategyChoice
  */
 class NameTree : noncopyable
 {
 public:
-  class const_iterator;
+  typedef Iterator const_iterator;
 
   explicit
   NameTree(size_t nBuckets = 1024);
@@ -255,53 +226,6 @@
   const_iterator
   end() const;
 
-  enum IteratorType {
-    FULL_ENUMERATE_TYPE,
-    PARTIAL_ENUMERATE_TYPE,
-    FIND_ALL_MATCHES_TYPE
-  };
-
-  class const_iterator : public std::iterator<std::forward_iterator_tag, const Entry>
-  {
-  public:
-    friend class NameTree;
-
-    const_iterator();
-
-    const_iterator(NameTree::IteratorType type,
-                   const NameTree& nameTree,
-                   shared_ptr<Entry> entry,
-                   const EntrySelector& entrySelector = AnyEntry(),
-                   const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree());
-
-    const Entry&
-    operator*() const;
-
-    shared_ptr<Entry>
-    operator->() const;
-
-    const_iterator
-    operator++();
-
-    const_iterator
-    operator++(int);
-
-    bool
-    operator==(const const_iterator& other) const;
-
-    bool
-    operator!=(const const_iterator& other) const;
-
-  private:
-    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.
@@ -336,8 +260,10 @@
   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;
+
+  friend class FullEnumerationImpl;
+  friend class PartialEnumerationImpl;
+  friend class PrefixMatchImpl;
 };
 
 inline size_t
@@ -368,39 +294,7 @@
 inline NameTree::const_iterator
 NameTree::end() const
 {
-  return m_endIterator;
-}
-
-inline const Entry&
-NameTree::const_iterator::operator*() const
-{
-  return *m_entry;
-}
-
-inline shared_ptr<Entry>
-NameTree::const_iterator::operator->() const
-{
-  return m_entry;
-}
-
-inline NameTree::const_iterator
-NameTree::const_iterator::operator++(int)
-{
-  NameTree::const_iterator temp(*this);
-  ++(*this);
-  return temp;
-}
-
-inline bool
-NameTree::const_iterator::operator==(const NameTree::const_iterator& other) const
-{
-  return m_entry == other.m_entry;
-}
-
-inline bool
-NameTree::const_iterator::operator!=(const NameTree::const_iterator& other) const
-{
-  return m_entry != other.m_entry;
+  return Iterator();
 }
 
 } // namespace name_tree