remove Node::Copy, Node::Create and Node::*Prototype* methods.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 May 2007 12:34:53 +0200
changeset 482 f844579404cb
parent 481 508960b83d20
child 483 24c99e8ebaa2
remove Node::Copy, Node::Create and Node::*Prototype* methods.
examples/simple-p2p.cc
samples/main-simple.cc
src/node/internet-node.cc
src/node/internet-node.h
src/node/node.cc
src/node/node.h
--- a/examples/simple-p2p.cc	Wed May 02 12:12:55 2007 +0200
+++ b/examples/simple-p2p.cc	Wed May 02 12:34:53 2007 +0200
@@ -89,20 +89,10 @@
   // Specify limit of 30 in units of packets (not implemented).
   //  Queue::Default().SetLimitPackets(30);
 
-  // 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
-  // the object with the desired capabilities, and pushing the node
-  // object on the prototype stack.  In this simple example, the
-  // default behavior of an InternetNode is adequate, so we don't
-  // do any configuration in this simple example.
-  InternetNode inNode;
-  Node::PushNodePrototype(inNode);
-  // Next create the physical node topology using the node factory
-  Node* n0 = Node::Create(); 
-  Node* n1 = Node::Create(); 
-  Node* n2 = Node::Create(); 
-  Node* n3 = Node::Create(); 
+  Node* n0 = new InternetNode ();
+  Node* n1 = new InternetNode (); 
+  Node* n2 = new InternetNode (); 
+  Node* n3 = new InternetNode ();
 
   PointToPointChannel *channel0 = 
     PointToPointTopology::AddPointToPointLink (
@@ -178,6 +168,11 @@
   n1->Dispose ();
   n2->Dispose ();
   n3->Dispose ();
+
+  delete n0;
+  delete n1;
+  delete n2;
+  delete n3;
     
   Simulator::Destroy ();
 }
--- a/samples/main-simple.cc	Wed May 02 12:12:55 2007 +0200
+++ b/samples/main-simple.cc	Wed May 02 12:34:53 2007 +0200
@@ -8,29 +8,6 @@
 
 using namespace ns3;
 
-static void TestOne (void)
-{
-  InternetNode *a = new InternetNode ();
-
-  delete a;
-}
-
-static void TestTwo (void)
-{
-  InternetNode a = InternetNode ();
-
-  InternetNode *b = a.Copy ();
-
-  delete b;
-}
-
-static void
-SmallTests (void)
-{
-  TestOne ();
-  TestTwo ();
-}
-
 static void
 GenerateTraffic (Socket *socket, uint32_t size)
 {
@@ -56,8 +33,6 @@
 
 int main (int argc, char *argv[])
 {
-  SmallTests ();
-
   InternetNode *a = new InternetNode ();
 
   Socket *sink = a->GetUdp ()->CreateSocket ();
--- a/src/node/internet-node.cc	Wed May 02 12:12:55 2007 +0200
+++ b/src/node/internet-node.cc	Wed May 02 12:34:53 2007 +0200
@@ -34,12 +34,6 @@
 
 namespace ns3 {
 
-static class NodeStackInitializationClass {
-public:
-  NodeStackInitializationClass () {
-    Node::PushNodePrototype (InternetNode ());
-  }
-} node_stack_initialization_class;
 
 InternetNode::InternetNode()
 {
@@ -52,23 +46,6 @@
   m_ipv4L4Demux->Insert (Udp (this));
 }
 
-InternetNode::InternetNode (InternetNode const &o)
-{
-  m_applicationList = new ApplicationList();
-  m_l3Demux = o.m_l3Demux->Copy (this);
-  m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
-}
-InternetNode const &
-InternetNode::operator = (InternetNode const &o)
-{
-  delete m_applicationList;
-  delete m_l3Demux;
-  delete m_ipv4L4Demux;
-  m_l3Demux = o.m_l3Demux->Copy (this);
-  m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
-  return *this;
-}
-
 InternetNode::~InternetNode ()
 {
   delete m_applicationList;
@@ -82,13 +59,6 @@
   m_name = name;
 }
 
-// Copy this node
-InternetNode* 
-InternetNode::Copy() const
-{
-  InternetNode *copy = new InternetNode (*this);
-   return copy;
-}
 
 TraceResolver *
 InternetNode::CreateTraceResolver (TraceContext const &context)
--- a/src/node/internet-node.h	Wed May 02 12:12:55 2007 +0200
+++ b/src/node/internet-node.h	Wed May 02 12:34:53 2007 +0200
@@ -42,10 +42,7 @@
     ARP,
   };
   InternetNode();
-  InternetNode(const InternetNode&);
-  InternetNode const &operator = (InternetNode const &o);
   virtual ~InternetNode ();
-  virtual InternetNode* Copy() const;
   virtual TraceResolver *CreateTraceResolver (TraceContext const &context);
   virtual void Dispose();
   // Capability access
--- a/src/node/node.cc	Wed May 02 12:12:55 2007 +0200
+++ b/src/node/node.cc	Wed May 02 12:34:53 2007 +0200
@@ -99,90 +99,6 @@
   m_devices.erase (m_devices.begin (), m_devices.end ());
 }
 
-Node::SmartNodeVec_t **
-Node::GetNodeVector (void)
-{
-  static SmartNodeVec_t *vector = 0;
-  if (vector == 0)
-    {
-      vector = new SmartNodeVec_t ();
-      Simulator::ScheduleDestroy (&Node::DestroyNodes);
-    }
-  return &vector;
-}
-
-Node::SmartNodeVec_t **
-Node::GetPrototypeVector (void)
-{
-  static SmartNodeVec_t *vector = 0;
-  if (vector == 0)
-    {
-      vector = new SmartNodeVec_t ();
-      Simulator::ScheduleDestroy (&Node::DestroyPrototypes);
-    }
-  return &vector;
-}
-
-void
-Node::DestroyNodes (void)
-{
-  SmartNodeVec_t **vector = GetNodeVector ();
-  delete *vector;
-  *vector = 0;
-}
-void
-Node::DestroyPrototypes (void)
-{
-  SmartNodeVec_t **vector = GetPrototypeVector ();
-  delete *vector;
-  *vector = 0;
-}
-
-// Node stack creation and management routines.
-Node* Node::Create()
-{
-  Node* n = (*GetPrototypeVector ())->Back()->Copy(); // Copy the top of the stack
-  (*GetNodeVector ())->Add (n);
-  NodeList::Add (n);           // Add to global list of nodes
-  return n;
-}
-
-Node* Node::Create(uint32_t sid)
-{ // Create with distributed simulation systemid
-  // ! Need to check if sid matches DistributedSimulator system id,
-  // and create an empty (ghost) node if so.  Code this later
-  Node* n = Create(sid);
-  return n;
-}
-
-Node* Node::GetNodePrototype()
-{ // Get node* to top of prototypes stack
-  return (*GetPrototypeVector ())->Back();
-}
-
-Node* Node::PushNodePrototype(const Node& n)
-{ // Add a new node to the top of the prototypes stack
-  (*GetPrototypeVector ())->Add(n.Copy());
-  return (*GetPrototypeVector ())->Back();
-}
-
-Node* Node::PushNodePrototype() 
-{ // Replicate the top of the prototype stack
-  (*GetPrototypeVector ())->Add(GetNodePrototype()->Copy());
-  return (*GetPrototypeVector ())->Back();
-}
-
-void Node::PopNodePrototype()
-{ 
-  if (!(*GetPrototypeVector ())->Empty()) (*GetPrototypeVector ())->Remove();
-}
-
-void Node::ClearAll()
-{ // Delete all nodes for memory leak checking, including prototypes
-  (*GetNodeVector ())->Clear ();
-  (*GetPrototypeVector ())->Clear();
-}
-
 L3Demux*
 Node::GetL3Demux() const
 {
--- a/src/node/node.h	Wed May 02 12:12:55 2007 +0200
+++ b/src/node/node.h	Wed May 02 12:34:53 2007 +0200
@@ -22,66 +22,12 @@
 // Define the basic Node object for ns3.
 // George F. Riley, Georgia Tech, Fall 2006
 
-// The Node class is the building block for all network element definitions
-// in ns3.  The design approach is to create a node object by including
-// one or mode "node capabilities", selecting the capabilities based on
-// the desired features and behavior of a node.  For example, an
-// "InternetNode" has capabilities for a list of network devices, a layer 3
-// protocol list, a layer 4 protocol list, and a list of processs.
-// A "SensorNode" has a list of network devices, a list of "Sensors", and
-// an energy model.  
-// 
-// To create a new node class, perform the following steps.
-// 
-// 1) Create your node subclass as a direct descendent of the Node base class.
-// 2) Add members to your node subclass that are pointers to each of the
-//    node capabilities you need.  We use pointers here rather than direct
-//    objects, since you might want a SensorNode with a specific energy
-//    model that derives from the base EnergyModel capability.
-// 3) Override each of the "Get*" virtual member functions of the Node base
-//    class to return the appropriate pointer to each capability.
-// 4) Implement a copy constructor that calls the "Copy" method on each
-//    capability in your class.  Do NOT just copy the pointers, as this will
-//    result in "double delete".
-// 5) Implement a destructor that deletes each of your capabilities.
-// 6) Implement a Copy() method that returns a copy of your node.  This
-//    is usually just one line of code, calling "new" and specifying the
-//    copy constructor. See the Copy method in InternetNode for an example.
-// 
-// To implement a new Capability, perform the following steps:
-// 
-// 1) Create your new capability class as a direct descendent of the
-//    NodeCapability base class.
-// 2) If needed, implement a copy constructor.  This is typically only
-//    needed if your capability does dynamic memory management (ie. new
-//    and delete).
-// 3) If needed, implement a destructor.  Again, this is typically only
-//    needed if you use dynamic memory.
-// 4) Implement a Copy() method that returns a copy of your capability.
-// 5) Implement a "Get*" virtual method in the node base that returns
-//    the null capability.
-//
-// To implement a variation on an existing capability, perform
-// the following steps:
-//
-// 1) Create your new capability as a subclass of an existing capability.
-// 2) Override the capability members as needed to implement the desired
-//    behavior.
-// 3) Override the Copy() method to create a copy of your capability
-//    subclass.
-//
-// The design team for ns3 expects that the number of different node
-// capabilities will remain relatively small over time.  Contributors
-// and those modifying ns3 for their own uses are encouraged to subclass
-// an existing capability where possible.
-
 #ifndef __NODE_H__
 #define __NODE_H__
 
 #include <vector>
 #include <list>
 
-#include "ns3/smartvector.h"
 #include "ns3/smartset.h"
 
 namespace ns3 {
@@ -101,17 +47,14 @@
 class TraceResolver;
 class NetDevice;
 
-class Node {
+class Node  {
 friend class NodeList;
-friend class SmartVector<Node*>;
 friend class SmartSet<Node*>;
 
 public:
-  typedef SmartVector<Node*> SmartNodeVec_t;
   Node();
   Node(uint32_t); // Specify which system for a distributed simulation
   virtual ~Node();
-  virtual Node* Copy() const = 0;// Make a copy of this node
 
   virtual TraceResolver *CreateTraceResolver (TraceContext const &context) = 0;
 
@@ -123,54 +66,11 @@
   NetDevice *GetDevice (uint32_t index) const;
   uint32_t GetNDevices (void) const;
   
-  virtual void Dispose();
+  virtual void Dispose (void);
 
 private:
   virtual void DoAddDevice (NetDevice *device) const = 0;
 
-#ifdef REMOVE_FOR_NOW
-  // Define a protected delete operator. This will prevent users
-  // from attempting to delete Node objects.  The deletion of
-  // Nodes is completely the responsibility of the Node class,
-  // and in no case should be deleted by users.
-protected:
-  void operator delete(void* a)
-  { // Just call the normal delete
-    ::delete (Node*)a;
-  }
-#endif
-public:
-  // Static methods for creating nodes and managing the node stack
-
-  // Create a new node.  The node will be a copy of the top of the
-  // node prototype list
-  static Node* Create();
-  // Create with a uint32_t is used by distributed simulations to
-  // indicate system ownership of the new node.
-  static Node* Create(uint32_t);
-  static Node* GetNodePrototype(); // Get the current node prototype
-  // Specifies the type of node to be returned by Create()
-  // This version specifies a pre-configured node to use as the prototype
-  // Of course the passed object can be any subclass of Node.
-  static Node* PushNodePrototype(const Node&); 
-  // THis version replicates the top of the prototype stack
-  static Node* PushNodePrototype();
-  // Remove the top of the prototype stack
-  static void PopNodePrototype();
-  // Node access
-  static const SmartNodeVec_t& Nodes(); // Get a vector of all nodes
-  static void  ClearAll();          // Delete all nodes for memory leak checking
-  static void  ClearAllPrototypes();// Delete the prototype stack
-
-  // Global static variables
-private: 
-  static uint32_t       g_nextId;     // Next available ID
-
-  static Node::SmartNodeVec_t **GetNodeVector (void);
-  static Node::SmartNodeVec_t **GetPrototypeVector (void);
-  static void DestroyNodes (void);
-  static void DestroyPrototypes (void);
-
 protected:
   void SetId(uint32_t);            // NodeList::Add() calls this
 
@@ -190,6 +90,7 @@
   virtual Arp *            GetArp (void) const;
   
 private:
+  static uint32_t       g_nextId;     // Next available ID
   uint32_t    m_id;         // Node id for this node
   uint32_t    m_sid;        // System id for this node
   std::vector<NetDevice *> m_devices;