avoid using non-portable reverse iterator methods
authorTom Henderson <tomh@tomh.org>
Fri, 19 Jun 2009 14:12:59 -0700
changeset 4570 5c6e1f086a36
parent 4569 a84925c82581
child 4571 2c9c600270e0
avoid using non-portable reverse iterator methods
src/internet-stack/ipv4-list-routing.cc
src/internet-stack/ipv4-list-routing.h
--- a/src/internet-stack/ipv4-list-routing.cc	Fri Jun 19 07:51:57 2009 -0700
+++ b/src/internet-stack/ipv4-list-routing.cc	Fri Jun 19 14:12:59 2009 -0700
@@ -74,10 +74,8 @@
   NS_LOG_FUNCTION (this << header.GetDestination () << " " << header.GetSource () << " " << oif);
   Ptr<Ipv4Route> route;
 
-  // Sorted lists are stored in lowest to highest order, so since we
-  // want to iterate from highest to lowest, use a reverse iterator
-  for (Ipv4RoutingProtocolList::const_reverse_iterator i = m_routingProtocols.rbegin ();
-       i != m_routingProtocols.rend (); i++)
+  for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
+       i != m_routingProtocols.end (); i++)
     {
       NS_LOG_LOGIC ("Checking protocol " << (*i).second->GetInstanceTypeId () << " with priority " << (*i).first);
       NS_LOG_LOGIC ("Requesting source address for destination " << header.GetDestination ());
@@ -125,11 +123,8 @@
           // Fall through-- we may also need to forward this
           retVal = true;
         }
-      // Sorted lists are stored in lowest to highest order, so since we
-      // want to iterate from highest to lowest, use a reverse iterator
-      for (Ipv4RoutingProtocolList::const_reverse_iterator rprotoIter =
-         m_routingProtocols.rbegin ();
-           rprotoIter != m_routingProtocols.rend ();
+      for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
+         m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end ();
            rprotoIter++)
         {
           NS_LOG_LOGIC ("Multicast packet for me-- trying to forward");
@@ -183,11 +178,9 @@
         }
     }
   // Next, try to find a route
-  // Sorted lists are stored in lowest to highest order, so since we
-  // want to iterate from highest to lowest, use a reverse iterator
-  for (Ipv4RoutingProtocolList::const_reverse_iterator rprotoIter =
-         m_routingProtocols.rbegin ();
-       rprotoIter != m_routingProtocols.rend ();
+  for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
+         m_routingProtocols.begin ();
+       rprotoIter != m_routingProtocols.end ();
        rprotoIter++)
     {
       if ((*rprotoIter).second->RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
@@ -267,7 +260,7 @@
 {
   NS_LOG_FUNCTION (this << routingProtocol->GetInstanceTypeId () << priority);
   m_routingProtocols.push_back (std::make_pair (priority, routingProtocol));
-  m_routingProtocols.sort ();
+  m_routingProtocols.sort ( Compare );
   if (m_ipv4 != 0)
     {
       routingProtocol->SetIpv4 (m_ipv4);
@@ -290,10 +283,8 @@
       NS_FATAL_ERROR ("Ipv4ListRouting::GetRoutingProtocol():  index " << index << " out of range");
     }
   uint32_t i = 0;
-  // Sorted lists are stored in lowest to highest order, so since we
-  // want to iterate from highest to lowest, use a reverse iterator
-  for (Ipv4RoutingProtocolList::const_reverse_iterator rprotoIter = m_routingProtocols.rbegin ();
-       rprotoIter != m_routingProtocols.rend (); rprotoIter++, i++)
+  for (Ipv4RoutingProtocolList::const_iterator rprotoIter = m_routingProtocols.begin ();
+       rprotoIter != m_routingProtocols.end (); rprotoIter++, i++)
     {
       if (i == index)
         {
@@ -325,6 +316,13 @@
 
 }
 
+bool 
+Ipv4ListRouting::Compare (const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingProtocolEntry& b)
+{
+  return a.first > b.first;
+}
+
+
 } // namespace ns3
 
 #ifdef RUN_SELF_TESTS
--- a/src/internet-stack/ipv4-list-routing.h	Fri Jun 19 07:51:57 2009 -0700
+++ b/src/internet-stack/ipv4-list-routing.h	Fri Jun 19 14:12:59 2009 -0700
@@ -89,9 +89,12 @@
 protected:
   void DoDispose (void);
 private:
-  typedef std::list< std::pair< int16_t, Ptr<Ipv4RoutingProtocol> > > Ipv4RoutingProtocolList;
+  typedef std::pair<int16_t, Ptr<Ipv4RoutingProtocol> > Ipv4RoutingProtocolEntry;
+  typedef std::list<Ipv4RoutingProtocolEntry> Ipv4RoutingProtocolList;
   Ipv4RoutingProtocolList m_routingProtocols;
+  static bool Compare (const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingProtocolEntry& b);
   Ptr<Ipv4> m_ipv4;
+
 };
 
 } //namespace ns3