Add nodes to NodeList in static Create method; cut over simple-serial.cc to use this node factory
authorTom Henderson <tomh@tomh.org>
Tue, 20 Mar 2007 06:28:24 -0700
changeset 358 cefde4f0d6b2
parent 357 e55173f9f564
child 359 91b7ad7fa784
Add nodes to NodeList in static Create method; cut over simple-serial.cc to use this node factory
examples/simple-serial.cc
src/node/node.cc
--- a/examples/simple-serial.cc	Mon Mar 19 22:27:22 2007 -0700
+++ b/examples/simple-serial.cc	Tue Mar 20 06:28:24 2007 -0700
@@ -209,7 +209,6 @@
 
   ObjectContainer container;
 
-#ifdef NOTYET
   // The node factory is designed to allow user specification
   // of the "type" of node desired for each node creation.  This
   // is done by creating a node object (the inNode below), configuring
@@ -225,30 +224,6 @@
   Node* n2 = Node::Create(); 
   Node* n3 = Node::Create(); 
 
-#else
-  // ** Here, some kind of factory or topology object will instantiates 
-  // ** four identical nodes; for now, we just explicitly create them
-  InternetNode *n0 = new InternetNode();
-  InternetNode *n1 = new InternetNode();
-  InternetNode *n2 = new InternetNode();
-  InternetNode *n3 = new InternetNode();
-
-  container.Acquire (n0);
-  container.Acquire (n1);
-  container.Acquire (n2);
-  container.Acquire (n3);
-
-  NodeList::Add (n0);
-  NodeList::Add (n1);
-  NodeList::Add (n2);
-  NodeList::Add (n3);
-
-  n0->SetName(std::string("Node 0"));
-  n1->SetName(std::string("Node 1"));
-  n2->SetName(std::string("Node 2"));
-  n3->SetName(std::string("Node 3"));
-#endif
-  
   SerialChannel* ch1;
   ch1 = SerialTopology::AddSerialLink (
       n0, Ipv4Address("10.1.1.1"), 
--- a/src/node/node.cc	Mon Mar 19 22:27:22 2007 -0700
+++ b/src/node/node.cc	Tue Mar 20 06:28:24 2007 -0700
@@ -24,6 +24,7 @@
 
 #include "node.h"
 #include "internet-node.h"
+#include "node-list.h"
 
 namespace ns3{
 
@@ -70,7 +71,8 @@
   if (g_prototypes.Empty()) CreateDefaultPrototype();
   Node* n = g_prototypes.Back()->Copy(); // Copy the top of the stack
   n->m_id = g_nextId++;                  // Set unique node id
-  g_nodes.Add(n);                        // Add to list of known nodes
+  g_nodes.Add(n);                        // Add to smart vector (mem mgmt)
+  NodeList::Add (n);                     // Add to global list of nodes
   return n;
 }