change signature of MobilityHelper::Layout and MobilityHelper::LayoutAll.
--- a/examples/wifi-adhoc.cc Mon Mar 24 10:41:44 2008 -0700
+++ b/examples/wifi-adhoc.cc Mon Mar 24 10:42:18 2008 -0700
@@ -142,7 +142,7 @@
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::StaticMobilityModel");
- mobility.Layout (c.Begin (), c.End ());
+ mobility.Layout (c);
PacketSocketAddress destination = PacketSocketAddress ();
destination.SetProtocol (1);
--- a/examples/wifi-ap.cc Mon Mar 24 10:41:44 2008 -0700
+++ b/examples/wifi-ap.cc Mon Mar 24 10:42:18 2008 -0700
@@ -161,8 +161,8 @@
wifi.Build (ap, channel);
// mobility.
- mobility.Layout (stas.Begin (), stas.End ());
- mobility.Layout (ap.Begin (), ap.End ());
+ mobility.Layout (stas);
+ mobility.Layout (ap);
Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0));
--- a/samples/main-grid-topology.cc Mon Mar 24 10:41:44 2008 -0700
+++ b/samples/main-grid-topology.cc Mon Mar 24 10:42:18 2008 -0700
@@ -16,13 +16,10 @@
CommandLine cmd;
cmd.Parse (argc, argv);
- std::vector<Ptr<Object> > nodes;
+ NodeContainer nodes;
// create an array of empty nodes for testing purposes
- for (uint32_t i = 0; i < 120; i++)
- {
- nodes.push_back (CreateObject<Node> ());
- }
+ nodes.Create (120);
MobilityHelper mobility;
// setup the grid itself: objects are layed out
@@ -44,13 +41,13 @@
// finalize the setup by attaching to each object
// in the input array a position and initializing
// this position with the calculated coordinates.
- mobility.Layout (nodes.begin (), nodes.end ());
+ mobility.Layout (nodes);
// iterate our nodes and print their position.
- for (std::vector<Ptr<Object> >::const_iterator j = nodes.begin ();
- j != nodes.end (); j++)
+ for (NodeContainer::Iterator j = nodes.Begin ();
+ j != nodes.End (); ++j)
{
- Ptr<Object> object = *j;
+ Ptr<Node> object = *j;
Ptr<MobilityModel> position = object->GetObject<MobilityModel> ();
NS_ASSERT (position != 0);
Vector pos = position->GetPosition ();
--- a/samples/main-random-topology.cc Mon Mar 24 10:41:44 2008 -0700
+++ b/samples/main-random-topology.cc Mon Mar 24 10:42:18 2008 -0700
@@ -29,11 +29,8 @@
cmd.Parse (argc, argv);
- std::vector<Ptr<Object> > objects;
- for (uint32_t i = 0; i < 10000; i++)
- {
- objects.push_back (CreateObject<Node> ());
- }
+ NodeContainer c;
+ c.Create (10000);
MobilityHelper mobility;
mobility.EnableNotifier ();
@@ -42,7 +39,7 @@
"Y", String ("100.0"),
"Rho", String ("Uniform:0:30"));
mobility.SetMobilityModel ("ns3::StaticMobilityModel");
- mobility.Layout (objects.begin (), objects.end ());
+ mobility.Layout (c);
Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange",
MakeCallback (&CourseChange));
--- a/samples/main-random-walk.cc Mon Mar 24 10:41:44 2008 -0700
+++ b/samples/main-random-walk.cc Mon Mar 24 10:42:18 2008 -0700
@@ -36,10 +36,8 @@
CommandLine cmd;
cmd.Parse (argc, argv);
- for (uint32_t i = 0; i < 100; i++)
- {
- Ptr<Node> node = CreateObject<Node> ();
- }
+ NodeContainer c;
+ c.Create (100);
MobilityHelper mobility;
mobility.EnableNotifier ();
@@ -52,7 +50,7 @@
"Time", String ("2s"),
"Speed", String ("Constant:1.0"),
"Bounds", String ("0:200:0:100"));
- mobility.Layout (NodeList::Begin (), NodeList::End ());
+ mobility.LayoutAll ();
Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange",
MakeCallback (&CourseChange));
--- a/src/helper/mobility-helper.cc Mon Mar 24 10:41:44 2008 -0700
+++ b/src/helper/mobility-helper.cc Mon Mar 24 10:42:18 2008 -0700
@@ -101,9 +101,9 @@
}
void
-MobilityHelper::Layout (const std::vector<Ptr<Object> > &objects)
+MobilityHelper::Layout (NodeContainer c)
{
- for (std::vector<Ptr<Object> >::const_iterator i = objects.begin (); i != objects.end (); i++)
+ for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
Ptr<Object> object = *i;
Ptr<MobilityModel> model = object->GetObject<MobilityModel> ();
@@ -145,4 +145,10 @@
}
}
+void
+MobilityHelper::LayoutAll (void)
+{
+ Layout (NodeContainer::GetGlobal ());
+}
+
} // namespace ns3
--- a/src/helper/mobility-helper.h Mon Mar 24 10:41:44 2008 -0700
+++ b/src/helper/mobility-helper.h Mon Mar 24 10:42:18 2008 -0700
@@ -4,13 +4,17 @@
#include <vector>
#include "ns3/object-factory.h"
#include "ns3/attribute.h"
-#include "position-allocator.h"
+#include "ns3/position-allocator.h"
+#include "node-container.h"
namespace ns3 {
class PositionAllocator;
class MobilityModel;
+/**
+ * \brief assign positions and mobility models to nodes.
+ */
class MobilityHelper
{
public:
@@ -48,10 +52,9 @@
std::string GetMobilityModelType (void) const;
- template <typename T>
- void Layout (T begin, T end);
+ void Layout (NodeContainer container);
+ void LayoutAll (void);
private:
- void Layout (const std::vector<Ptr<Object> > &objects);
std::vector<Ptr<MobilityModel> > m_mobilityStack;
bool m_notifierEnabled;
@@ -61,21 +64,4 @@
} // namespace ns3
-namespace ns3 {
-
-template <typename T>
-void
-MobilityHelper::Layout (T begin, T end)
-{
- std::vector<Ptr<Object> > objects;
- for (T i = begin; i != end; i++)
- {
- Ptr<Object> object = *i;
- objects.push_back (object);
- }
- Layout (objects);
-}
-
-} // namespace ns3
-
#endif /* MOBILITY_HELPER_H */