table: simplify StrategyChoice iterator with Boost.Range

This commit also improves Doxygen in NameTree, Fib, and Pit enumeration.

refs #3738

Change-Id: Ibb56f958df4d1bc2564192d905cfc2e499a7875e
diff --git a/daemon/table/fib.hpp b/daemon/table/fib.hpp
index 73e0e21..fc5439f 100644
--- a/daemon/table/fib.hpp
+++ b/daemon/table/fib.hpp
@@ -105,10 +105,10 @@
   typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
   typedef boost::range_iterator<Range>::type const_iterator;
 
-  /** \brief returns an iterator pointing to the first FIB entry
-   *  \note Iteration order is implementation-specific and is undefined
-   *  \note The returned iterator may get invalidated if FIB or another NameTree-based
-   *        table is modified
+  /** \return an iterator to the beginning
+   *  \note Iteration order is implementation-defined.
+   *  \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
+   *           is inserted or erased during enumeration.
    */
   const_iterator
   begin() const
@@ -116,9 +116,8 @@
     return this->getRange().begin();
   }
 
-  /** \brief returns an iterator referring to the past-the-end FIB entry
-   *  \note The returned iterator may get invalidated if FIB or another NameTree-based
-   *        table is modified
+  /** \return an iterator to the end
+   *  \sa begin()
    */
   const_iterator
   end() const
diff --git a/daemon/table/name-tree.hpp b/daemon/table/name-tree.hpp
index 5c31103..c4b8b27 100644
--- a/daemon/table/name-tree.hpp
+++ b/daemon/table/name-tree.hpp
@@ -174,7 +174,7 @@
    *    ...
    *  }
    *  \endcode
-   *  \note Iteration order is implementation-specific and is undefined.
+   *  \note Iteration order is implementation-defined.
    *  \warning If a name tree entry whose name is a prefix of \p name is inserted
    *           during the enumeration, it may or may not be visited.
    *           If a name tree entry whose name is a prefix of \p name is deleted
@@ -197,7 +197,7 @@
    *    ...
    *  }
    *  \endcode
-   *  \note Iteration order is implementation-specific and is undefined.
+   *  \note Iteration order is implementation-defined.
    *  \warning If a name tree entry is inserted or deleted during the enumeration,
    *           it may cause the enumeration to skip entries or visit some entries twice.
    */
@@ -217,7 +217,7 @@
    *    ...
    *  }
    *  \endcode
-   *  \note Iteration order is implementation-specific and is undefined.
+   *  \note Iteration order is implementation-defined.
    *  \warning If a name tree entry under \p prefix is inserted or deleted during the enumeration,
    *           it may cause the enumeration to skip entries or visit some entries twice.
    */
@@ -225,7 +225,7 @@
   partialEnumerate(const Name& prefix,
                    const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree()) const;
 
-  /** \return an iterator to enumerate all entries
+  /** \return an iterator to the beginning
    *  \sa fullEnumerate
    */
   const_iterator
@@ -234,7 +234,8 @@
     return fullEnumerate().begin();
   }
 
-  /** \return a past-the-end iterator
+  /** \return an iterator to the end
+   *  \sa begin()
    */
   const_iterator
   end() const
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index 8e6c9f1..3f49737 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -101,9 +101,9 @@
   typedef Iterator const_iterator;
 
   /** \return an iterator to the beginning
-   *  \note Iteration order is implementation-specific and is undefined
-   *  \warning Undefine behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
-   *           is inserted or deleted during PIT enumeration.
+   *  \note Iteration order is implementation-defined.
+   *  \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
+   *           is inserted or erased during enumeration.
    */
   const_iterator
   begin() const;
diff --git a/daemon/table/strategy-choice.cpp b/daemon/table/strategy-choice.cpp
index be10945..c3d02e3 100644
--- a/daemon/table/strategy-choice.cpp
+++ b/daemon/table/strategy-choice.cpp
@@ -266,10 +266,12 @@
   }
 }
 
-StrategyChoice::const_iterator
-StrategyChoice::begin() const
+StrategyChoice::Range
+StrategyChoice::getRange() const
 {
-  return const_iterator(m_nameTree.fullEnumerate(&nteHasStrategyChoiceEntry).begin());
+  return m_nameTree.fullEnumerate(&nteHasStrategyChoiceEntry) |
+         boost::adaptors::transformed(name_tree::GetTableEntry<Entry>(
+                                      &name_tree::Entry::getStrategyChoiceEntry));
 }
 
 } // namespace strategy_choice
diff --git a/daemon/table/strategy-choice.hpp b/daemon/table/strategy-choice.hpp
index 75d3a47..1038cfb 100644
--- a/daemon/table/strategy-choice.hpp
+++ b/daemon/table/strategy-choice.hpp
@@ -29,6 +29,8 @@
 #include "strategy-choice-entry.hpp"
 #include "name-tree.hpp"
 
+#include <boost/range/adaptor/transformed.hpp>
+
 namespace nfd {
 namespace strategy_choice {
 
@@ -48,6 +50,12 @@
 public:
   StrategyChoice(NameTree& nameTree, unique_ptr<fw::Strategy> defaultStrategy);
 
+  size_t
+  size() const
+  {
+    return m_nItems;
+  }
+
 public: // available Strategy types
   /** \brief determines if a strategy is installed
    *  \param strategyName name of the strategy
@@ -99,57 +107,42 @@
   findEffectiveStrategy(const Name& prefix) const;
 
   /** \brief get effective strategy for pitEntry
+   *
+   *  This is equivalent to .findEffectiveStrategy(pitEntry.getName())
    */
   fw::Strategy&
   findEffectiveStrategy(const pit::Entry& pitEntry) const;
 
   /** \brief get effective strategy for measurementsEntry
+   *
+   *  This is equivalent to .findEffectiveStrategy(measurementsEntry.getName())
    */
   fw::Strategy&
   findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
 
 public: // enumeration
-  class const_iterator
-    : public std::iterator<std::forward_iterator_tag, const Entry>
-  {
-  public:
-    explicit
-    const_iterator(const NameTree::const_iterator& it);
+  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
+  typedef boost::range_iterator<Range>::type const_iterator;
 
-    ~const_iterator();
-
-    const Entry&
-    operator*() const;
-
-    const 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:
-    NameTree::const_iterator m_nameTreeIterator;
-  };
-
-  /** \return number of entries stored
+  /** \return an iterator to the beginning
+   *  \note Iteration order is implementation-defined.
+   *  \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
+   *           is inserted or erased during enumeration.
    */
-  size_t
-  size() const;
-
   const_iterator
-  begin() const;
+  begin() const
+  {
+    return this->getRange().begin();
+  }
 
+  /** \return an iterator to the end
+   *  \sa begin()
+   */
   const_iterator
-  end() const;
+  end() const
+  {
+    return this->getRange().end();
+  }
 
 private:
   /** \brief get Strategy instance by strategyName
@@ -172,6 +165,9 @@
   fw::Strategy&
   findEffectiveStrategyImpl(const K& key) const;
 
+  Range
+  getRange() const;
+
 private:
   NameTree& m_nameTree;
   size_t m_nItems;
@@ -180,69 +176,6 @@
   StrategyInstanceTable m_strategyInstances;
 };
 
-inline size_t
-StrategyChoice::size() const
-{
-  return m_nItems;
-}
-
-inline StrategyChoice::const_iterator
-StrategyChoice::end() const
-{
-  return const_iterator(m_nameTree.end());
-}
-
-inline
-StrategyChoice::const_iterator::const_iterator(const NameTree::const_iterator& it)
-  : m_nameTreeIterator(it)
-{
-}
-
-inline
-StrategyChoice::const_iterator::~const_iterator()
-{
-}
-
-inline
-StrategyChoice::const_iterator
-StrategyChoice::const_iterator::operator++(int)
-{
-  StrategyChoice::const_iterator temp(*this);
-  ++(*this);
-  return temp;
-}
-
-inline StrategyChoice::const_iterator&
-StrategyChoice::const_iterator::operator++()
-{
-  ++m_nameTreeIterator;
-  return *this;
-}
-
-inline const Entry&
-StrategyChoice::const_iterator::operator*() const
-{
-  return *(m_nameTreeIterator->getStrategyChoiceEntry());
-}
-
-inline const Entry*
-StrategyChoice::const_iterator::operator->() const
-{
-  return m_nameTreeIterator->getStrategyChoiceEntry();
-}
-
-inline bool
-StrategyChoice::const_iterator::operator==(const StrategyChoice::const_iterator& other) const
-{
-  return m_nameTreeIterator == other.m_nameTreeIterator;
-}
-
-inline bool
-StrategyChoice::const_iterator::operator!=(const StrategyChoice::const_iterator& other) const
-{
-  return m_nameTreeIterator != other.m_nameTreeIterator;
-}
-
 } // namespace strategy_choice
 
 using strategy_choice::StrategyChoice;