From dc5d0f6d1455595e51d97ca26a000a7c6c450a85 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 26 Feb 2008 18:17:29 +0100 Subject: [PATCH] convert NodeList to Attributes. --- src/node/node-list.cc | 61 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/src/node/node-list.cc b/src/node/node-list.cc index 1accfa2be..efad2df66 100644 --- a/src/node/node-list.cc +++ b/src/node/node-list.cc @@ -22,7 +22,7 @@ #include "ns3/composite-trace-resolver.h" #include "ns3/simulator.h" -#include "ns3/simulation-singleton.h" +#include "ns3/object-vector.h" #include "node-list.h" #include "node.h" @@ -60,9 +60,10 @@ NodeListIndex::GetTypeName (void) const /** * The private node list used by the static-based API */ -class NodeListPriv +class NodeListPriv : public Object { public: + static TypeId GetTypeId (void); NodeListPriv (); ~NodeListPriv (); @@ -73,10 +74,50 @@ public: Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); + static Ptr Get (void); + private: + static Ptr *DoGet (void); + static void Delete (void); std::vector > m_nodes; }; +TypeId +NodeListPriv::GetTypeId (void) +{ + static TypeId tid = TypeId ("NodeListPriv") + .SetParent () + .AddAttribute ("NodeList", "The list of all nodes created during the simulation.", + ObjectVector (), + MakeObjectVectorAccessor (&NodeListPriv::m_nodes), + MakeObjectVectorChecker ()) + ; + return tid; +} + +Ptr +NodeListPriv::Get (void) +{ + return *DoGet (); +} +Ptr * +NodeListPriv::DoGet (void) +{ + static Ptr ptr = 0; + if (ptr == 0) + { + ptr = CreateObject (); + Simulator::ScheduleDestroy (&NodeListPriv::Delete); + } + return &ptr; +} +void +NodeListPriv::Delete (void) +{ + (*DoGet ()) = 0; +} + + NodeListPriv::NodeListPriv () {} NodeListPriv::~NodeListPriv () @@ -143,42 +184,42 @@ namespace ns3 { uint32_t NodeList::Add (Ptr node) { - return SimulationSingleton::Get ()->Add (node); + return NodeListPriv::Get ()->Add (node); } NodeList::Iterator NodeList::Begin (void) { - return SimulationSingleton::Get ()->Begin (); + return NodeListPriv::Get ()->Begin (); } NodeList::Iterator NodeList::End (void) { - return SimulationSingleton::Get ()->End (); + return NodeListPriv::Get ()->End (); } Ptr NodeList::GetNode (uint32_t n) { - return SimulationSingleton::Get ()->GetNode (n); + return NodeListPriv::Get ()->GetNode (n); } void NodeList::Connect (std::string name, const CallbackBase &cb) { - SimulationSingleton::Get ()->GetTraceResolver ()->Connect (name, cb, TraceContext ()); + NodeListPriv::Get ()->GetTraceResolver ()->Connect (name, cb, TraceContext ()); } void NodeList::Disconnect (std::string name, const CallbackBase &cb) { - SimulationSingleton::Get ()->GetTraceResolver ()->Disconnect (name, cb); + NodeListPriv::Get ()->GetTraceResolver ()->Disconnect (name, cb); } void NodeList::TraceAll (std::ostream &os) { - SimulationSingleton::Get ()->GetTraceResolver ()->TraceAll (os, TraceContext ()); + NodeListPriv::Get ()->GetTraceResolver ()->TraceAll (os, TraceContext ()); } Ptr NodeList::GetTraceResolver (void) { - return SimulationSingleton::Get ()->GetTraceResolver (); + return NodeListPriv::Get ()->GetTraceResolver (); } }//namespace ns3