tools: Fixing bugs in nfd-status

Also in this commit: implementing const_reverse_iterator in FaceTable.
It also would be good to have reverse iterator in Fib, but not strictly
necessary.

Change-Id: Ie9cf849b718f5db76db2957b4452790f9ae68fd3
Refs: #1378
diff --git a/daemon/core/map-value-iterator.hpp b/daemon/core/map-value-iterator.hpp
index c8d3df7..6d80887 100644
--- a/daemon/core/map-value-iterator.hpp
+++ b/daemon/core/map-value-iterator.hpp
@@ -17,13 +17,15 @@
  */
 template<typename Map>
 class MapValueIterator
-  : public boost::transform_iterator<function<const typename Map::mapped_type&(const typename Map::value_type&)>,
-                                     typename Map::const_iterator>
+  : public boost::transform_iterator<
+             function<const typename Map::mapped_type&(const typename Map::value_type&)>,
+             typename Map::const_iterator>
 {
 public:
   explicit
   MapValueIterator(typename Map::const_iterator it)
-    : boost::transform_iterator<function<const typename Map::mapped_type&(const typename Map::value_type&)>,
+    : boost::transform_iterator<
+        function<const typename Map::mapped_type&(const typename Map::value_type&)>,
         typename Map::const_iterator>(it, &takeSecond)
   {
   }
@@ -36,6 +38,32 @@
   }
 };
 
+/** \class MapValueReverseIterator
+ *  \brief ReverseIterator to iterator over map values
+ */
+template<typename Map>
+class MapValueReverseIterator
+  : public boost::transform_iterator<
+             function<const typename Map::mapped_type&(const typename Map::value_type&)>,
+             typename Map::const_reverse_iterator>
+{
+public:
+  explicit
+  MapValueReverseIterator(typename Map::const_reverse_iterator it)
+    : boost::transform_iterator<
+             function<const typename Map::mapped_type&(const typename Map::value_type&)>,
+             typename Map::const_reverse_iterator>(it, &takeSecond)
+  {
+  }
+
+private:
+  static const typename Map::mapped_type&
+  takeSecond(const typename Map::value_type& pair)
+  {
+    return pair.second;
+  }
+};
+
 } // namespace nfd
 
 #endif // NFD_CORE_MAP_VALUE_ITERATOR_H
diff --git a/daemon/fw/face-table.hpp b/daemon/fw/face-table.hpp
index 868cf9e..b806cad 100644
--- a/daemon/fw/face-table.hpp
+++ b/daemon/fw/face-table.hpp
@@ -38,16 +38,26 @@
 public: // enumeration
   typedef std::map<FaceId, shared_ptr<Face> > FaceMap;
 
-  /** \brief ForwarderIterator for shared_ptr<Face>
+  /** \brief ForwardIterator for shared_ptr<Face>
    */
   typedef MapValueIterator<FaceMap> const_iterator;
 
+  /** \brief ReverseIterator for shared_ptr<Face>
+   */
+  typedef MapValueReverseIterator<FaceMap> const_reverse_iterator;
+
   const_iterator
   begin() const;
 
   const_iterator
   end() const;
 
+  const_reverse_iterator
+  rbegin() const;
+
+  const_reverse_iterator
+  rend() const;
+
 public: // events
   /** \brief fires after a Face is added
    */
@@ -96,6 +106,18 @@
   return const_iterator(m_faces.end());
 }
 
+inline FaceTable::const_reverse_iterator
+FaceTable::rbegin() const
+{
+  return const_reverse_iterator(m_faces.rbegin());
+}
+
+inline FaceTable::const_reverse_iterator
+FaceTable::rend() const
+{
+  return const_reverse_iterator(m_faces.rend());
+}
+
 } // namespace nfd
 
 #endif // NFD_FW_FACE_TABLE_HPP
diff --git a/daemon/mgmt/face-status-publisher.cpp b/daemon/mgmt/face-status-publisher.cpp
index 2cf2603..6bc8c72 100644
--- a/daemon/mgmt/face-status-publisher.cpp
+++ b/daemon/mgmt/face-status-publisher.cpp
@@ -30,8 +30,8 @@
 {
   size_t totalLength = 0;
 
-  for (FaceTable::const_iterator i = m_faceTable.begin();
-       i != m_faceTable.end();
+  for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
+       i != m_faceTable.rend();
        ++i)
     {
       const shared_ptr<Face>& face = *i;
diff --git a/daemon/mgmt/fib-enumeration-publisher.cpp b/daemon/mgmt/fib-enumeration-publisher.cpp
index 89f0956..79532ba 100644
--- a/daemon/mgmt/fib-enumeration-publisher.cpp
+++ b/daemon/mgmt/fib-enumeration-publisher.cpp
@@ -31,8 +31,9 @@
 size_t
 FibEnumerationPublisher::generate(ndn::EncodingBuffer& outBuffer)
 {
-
   size_t totalLength = 0;
+
+  /// \todo Enable use of Fib::const_reverse_iterator (when it is available)
   for (Fib::const_iterator i = m_fib.begin(); i != m_fib.end(); ++i)
     {
       const fib::Entry& entry = *i;