Make MobilityHelper use an output stream wrapper
authorMitch Watrous <watrous@u.washington.edu>
Fri, 28 Sep 2012 12:22:18 -0700
changeset 9096 94215be61edf
parent 9095 8462a1160246
child 9097 4d2b28c310db
Make MobilityHelper use an output stream wrapper
examples/routing/manet-routing-compare.cc
examples/wireless/wifi-wired-bridging.cc
src/mobility/helper/mobility-helper.cc
src/mobility/helper/mobility-helper.h
--- a/examples/routing/manet-routing-compare.cc	Thu Sep 27 13:29:03 2012 -0400
+++ b/examples/routing/manet-routing-compare.cc	Fri Sep 28 12:22:18 2012 -0700
@@ -378,9 +378,8 @@
   //AsciiTraceHelper ascii;
   //Ptr<OutputStreamWrapper> osw = ascii.CreateFileStream ( (tr_name + ".tr").c_str());
   //wifiPhy.EnableAsciiAll (osw);
-  std::ofstream os;
-  os.open ((tr_name + ".mob").c_str ());
-  MobilityHelper::EnableAsciiAll (os);
+  AsciiTraceHelper ascii;
+  MobilityHelper::EnableAsciiAll (ascii.CreateFileStream (tr_name + ".mob"));
 
   //Ptr<FlowMonitor> flowmon;
   //FlowMonitorHelper flowmonHelper;
--- a/examples/wireless/wifi-wired-bridging.cc	Thu Sep 27 13:29:03 2012 -0400
+++ b/examples/wireless/wifi-wired-bridging.cc	Fri Sep 28 12:22:18 2012 -0700
@@ -190,9 +190,8 @@
 
   if (writeMobility)
     {
-      std::ofstream os;
-      os.open ("wifi-wired-bridging.mob");
-      MobilityHelper::EnableAsciiAll (os);
+      AsciiTraceHelper ascii;
+      MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob"));
     }
 
   Simulator::Stop (Seconds (5.0));
--- a/src/mobility/helper/mobility-helper.cc	Thu Sep 27 13:29:03 2012 -0400
+++ b/src/mobility/helper/mobility-helper.cc	Fri Sep 28 12:22:18 2012 -0700
@@ -200,8 +200,9 @@
     }
 }
 void
-MobilityHelper::CourseChanged (std::ostream *os, Ptr<const MobilityModel> mobility)
+MobilityHelper::CourseChanged (Ptr<OutputStreamWrapper> stream, Ptr<const MobilityModel> mobility)
 {
+  std::ostream* os = stream->GetStream ();
   Ptr<Node> node = mobility->GetObject<Node> ();
   *os << "now=" << Simulator::Now ()
       << " node=" << node->GetId ();
@@ -225,25 +226,25 @@
 }
 
 void 
-MobilityHelper::EnableAscii (std::ostream &os, uint32_t nodeid)
+MobilityHelper::EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid)
 {
   std::ostringstream oss;
   oss << "/NodeList/" << nodeid << "/$ns3::MobilityModel/CourseChange";
   Config::ConnectWithoutContext (oss.str (), 
-                                 MakeBoundCallback (&MobilityHelper::CourseChanged, &os));
+                                 MakeBoundCallback (&MobilityHelper::CourseChanged, stream));
 }
 void 
-MobilityHelper::EnableAscii (std::ostream &os, NodeContainer n)
+MobilityHelper::EnableAscii (Ptr<OutputStreamWrapper> stream, NodeContainer n)
 {
   for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
     {
-      EnableAscii (os, (*i)->GetId ());
+      EnableAscii (stream, (*i)->GetId ());
     }
 }
 void 
-MobilityHelper::EnableAsciiAll (std::ostream &os)
+MobilityHelper::EnableAsciiAll (Ptr<OutputStreamWrapper> stream)
 {
-  EnableAscii (os, NodeContainer::GetGlobal ());
+  EnableAscii (stream, NodeContainer::GetGlobal ());
 }
 int64_t
 MobilityHelper::AssignStreams (NodeContainer c, int64_t stream)
--- a/src/mobility/helper/mobility-helper.h	Thu Sep 27 13:29:03 2012 -0400
+++ b/src/mobility/helper/mobility-helper.h	Fri Sep 28 12:22:18 2012 -0700
@@ -24,6 +24,7 @@
 #include <vector>
 #include "ns3/object-factory.h"
 #include "ns3/attribute.h"
+#include "ns3/output-stream-wrapper.h"
 #include "ns3/position-allocator.h"
 #include "node-container.h"
 
@@ -221,31 +222,31 @@
   void InstallAll (void);
 
   /**
-   * \param os output stream
+   * \param stream an output stream wrapper
    * \param nodeid the id of the node to generate ascii output for.
    *
    * Enable ascii output on the mobility model associated to the
    * specified nodeid and dump that to the specified stdc++ output 
    * stream.
    */
-  static void EnableAscii (std::ostream &os, uint32_t nodeid);
+  static void EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid);
   /**
-   * \param os output stream
+   * \param stream an output stream wrapper
    * \param n node container
    *
    * Enable ascii output on the mobility model associated each of
    * the nodes in the input container and dump that to the 
    * specified stdc++ output stream.
    */
-  static void EnableAscii (std::ostream &os, NodeContainer n);
+  static void EnableAscii (Ptr<OutputStreamWrapper> stream, NodeContainer n);
   /**
-   * \param os output stream
+   * \param stream an output stream wrapper
    *
    * Enable ascii output on the mobility model associated
    * every node in the system and dump that to the specified 
    * stdc++ output stream.
    */
-  static void EnableAsciiAll (std::ostream &os);
+  static void EnableAsciiAll (Ptr<OutputStreamWrapper> stream);
   /**
    * Assign a fixed random variable stream number to the random variables
    * used by the mobility models (including any position allocators assigned
@@ -264,7 +265,7 @@
   /**
    * \internal
    */
-  static void CourseChanged (std::ostream *os, Ptr<const MobilityModel> mobility);
+  static void CourseChanged (Ptr<OutputStreamWrapper> stream, Ptr<const MobilityModel> mobility);
   std::vector<Ptr<MobilityModel> > m_mobilityStack;
   ObjectFactory m_mobility;
   Ptr<PositionAllocator> m_position;