From e9ac335b78bd6800554fe7b2c01639af3bd89bfe Mon Sep 17 00:00:00 2001 From: Mitch Watrous Date: Fri, 28 Sep 2012 12:22:18 -0700 Subject: [PATCH] Make MobilityHelper use an output stream wrapper --- examples/routing/manet-routing-compare.cc | 5 ++--- examples/wireless/wifi-wired-bridging.cc | 5 ++--- src/mobility/helper/mobility-helper.cc | 15 ++++++++------- src/mobility/helper/mobility-helper.h | 15 ++++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/routing/manet-routing-compare.cc b/examples/routing/manet-routing-compare.cc index 24b725d80..5fadf3978 100644 --- a/examples/routing/manet-routing-compare.cc +++ b/examples/routing/manet-routing-compare.cc @@ -378,9 +378,8 @@ RoutingExperiment::Run (int nSinks, double txp, std::string CSVfileName) //AsciiTraceHelper ascii; //Ptr 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 flowmon; //FlowMonitorHelper flowmonHelper; diff --git a/examples/wireless/wifi-wired-bridging.cc b/examples/wireless/wifi-wired-bridging.cc index c004aa447..354a6e405 100644 --- a/examples/wireless/wifi-wired-bridging.cc +++ b/examples/wireless/wifi-wired-bridging.cc @@ -190,9 +190,8 @@ int main (int argc, char *argv[]) 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)); diff --git a/src/mobility/helper/mobility-helper.cc b/src/mobility/helper/mobility-helper.cc index 062ca4cb2..82b832967 100644 --- a/src/mobility/helper/mobility-helper.cc +++ b/src/mobility/helper/mobility-helper.cc @@ -200,8 +200,9 @@ DoRound (double v) } } void -MobilityHelper::CourseChanged (std::ostream *os, Ptr mobility) +MobilityHelper::CourseChanged (Ptr stream, Ptr mobility) { + std::ostream* os = stream->GetStream (); Ptr node = mobility->GetObject (); *os << "now=" << Simulator::Now () << " node=" << node->GetId (); @@ -225,25 +226,25 @@ MobilityHelper::CourseChanged (std::ostream *os, Ptr mobili } void -MobilityHelper::EnableAscii (std::ostream &os, uint32_t nodeid) +MobilityHelper::EnableAscii (Ptr 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 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 stream) { - EnableAscii (os, NodeContainer::GetGlobal ()); + EnableAscii (stream, NodeContainer::GetGlobal ()); } int64_t MobilityHelper::AssignStreams (NodeContainer c, int64_t stream) diff --git a/src/mobility/helper/mobility-helper.h b/src/mobility/helper/mobility-helper.h index 6de541a5a..0fcc32cf3 100644 --- a/src/mobility/helper/mobility-helper.h +++ b/src/mobility/helper/mobility-helper.h @@ -24,6 +24,7 @@ #include #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 @@ public: 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 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 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 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 @@ private: /** * \internal */ - static void CourseChanged (std::ostream *os, Ptr mobility); + static void CourseChanged (Ptr stream, Ptr mobility); std::vector > m_mobilityStack; ObjectFactory m_mobility; Ptr m_position;