Node* -> Ptr<Node>
authorRaj Bhattacharjea <raj.b@gatech.edu>
Wed, 09 May 2007 13:26:21 -0400
changeset 543 a730800a31d5
parent 542 00722b9a01b3
child 544 cbc4158d47c9
child 545 49c33ddf1683
Node* -> Ptr<Node>
examples/simple-p2p.cc
src/applications/application-list.cc
src/applications/application-list.h
src/applications/application.cc
src/applications/application.h
src/applications/onoff-application.cc
src/applications/onoff-application.h
src/core/ptr.cc
src/core/ptr.h
src/devices/p2p/p2p-net-device.cc
src/devices/p2p/p2p-net-device.h
src/devices/p2p/p2p-topology.cc
src/devices/p2p/p2p-topology.h
src/node/net-device.cc
src/node/net-device.h
--- a/examples/simple-p2p.cc	Tue May 08 11:44:04 2007 -0400
+++ b/examples/simple-p2p.cc	Wed May 09 13:26:21 2007 -0400
@@ -45,6 +45,7 @@
 #include "ns3/debug.h"
 #include "ns3/command-line.h"
 #include "ns3/default-value.h"
+#include "ns3/ptr.h"
 
 #include "ns3/simulator.h"
 #include "ns3/nstime.h"
@@ -100,10 +101,10 @@
 
   // Here, we will explicitly create four nodes.  In more sophisticated
   // topologies, we could configure a node factory.
-  Node* n0 = new InternetNode ();
-  Node* n1 = new InternetNode (); 
-  Node* n2 = new InternetNode (); 
-  Node* n3 = new InternetNode ();
+  Ptr<Node> n0 = new InternetNode ();
+  Ptr<Node> n1 = new InternetNode (); 
+  Ptr<Node> n2 = new InternetNode (); 
+  Ptr<Node> n3 = new InternetNode ();
 
   // We create the channels first without any IP addressing information
   PointToPointChannel *channel0 = 
--- a/src/applications/application-list.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/applications/application-list.cc	Wed May 09 13:26:21 2007 -0400
@@ -28,7 +28,7 @@
 
 const Iid ApplicationList::iid ("ApplicationList");
 
-ApplicationList::ApplicationList(Node* n)
+ApplicationList::ApplicationList(Ptr<Node> n)
   : NsUnknown (ApplicationList::iid)
 {}
 
@@ -49,7 +49,7 @@
 ApplicationList::~ApplicationList()
 {}
 
-ApplicationList* ApplicationList::Copy(Node * n) const 
+ApplicationList* ApplicationList::Copy(Ptr<Node> n) const 
 { // Copy this app list
   ApplicationList* r = new ApplicationList(n);
   return r;
@@ -62,7 +62,7 @@
   m_apps.push_back(a);
 }
 
-void ApplicationList::SetNode(Node * n)
+void ApplicationList::SetNode(Ptr<Node> n)
 {
   // Set the node pointer in each application
   for (std::vector<Application *>::const_iterator i = m_apps.begin();
--- a/src/applications/application-list.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/applications/application-list.h	Wed May 09 13:26:21 2007 -0400
@@ -34,12 +34,12 @@
 {
 public:
   static const Iid iid;
-  ApplicationList(Node*);
+  ApplicationList(Ptr<Node>);
   // Copy constructor not needed, default one is correct
   virtual ~ApplicationList();
   // Inherited from Capabilty
-  virtual ApplicationList* Copy(Node*) const;
-  virtual void SetNode(Node *);              // Sets the node for all apps
+  virtual ApplicationList* Copy(Ptr<Node>) const;
+  virtual void SetNode(Ptr<Node>);              // Sets the node for all apps
   virtual void Add(Application*);      // Add an already new'ed app
   // Manage the list
   template <typename T> T* AddCopy(const T& t)  // Add a new application
--- a/src/applications/application.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/applications/application.cc	Wed May 09 13:26:21 2007 -0400
@@ -34,7 +34,7 @@
 // Application Methods
 
 // \brief Application Constructor
-Application::Application(Node * n) 
+Application::Application(Ptr<Node> n) 
     : m_node (n),
       m_startVar(0), m_stopVar(0),
       m_start(false), m_stop(false)
@@ -147,7 +147,7 @@
 // \brief Assign this application to a given node
 // Called by the application manager capability when adding
 // an application to a node.
-void Application::SetNode(Node * n)
+void Application::SetNode(Ptr<Node> n)
 {
   if (m_node != 0)
     {
@@ -157,7 +157,7 @@
   m_node->Ref ();
 }
   
-Node* Application::PeekNode() const
+Ptr<Node> Application::PeekNode() const
 {
   return m_node;
 }
--- a/src/applications/application.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/applications/application.h	Wed May 09 13:26:21 2007 -0400
@@ -50,6 +50,8 @@
 #include "ns3/event-id.h"
 #include "ns3/nstime.h"
 #include "ns3/object.h"
+#include "ns3/ptr.h"
+#include "ns3/node.h"
 
 namespace ns3 {
 
@@ -59,7 +61,7 @@
 class Application : public Object
 {
 public:
-  Application(Node *);
+  Application(Ptr<Node>);
   Application(const Application&);  // Copy constructor
   Application& operator=(const Application&); // Assignment operator
   virtual ~Application();
@@ -100,13 +102,13 @@
   // \brief Attaches an application to a specific node
   // Specifies which node object this application is associated with.
   // \param Node object to associate with this application.
-  void SetNode(Node *);
+  void SetNode(Ptr<Node>);
 
   // \brief Returns the pointer to the attached node.
-  Node* PeekNode() const;
+  Ptr<Node> PeekNode() const;
   
   // Members
-  Node          * m_node;      // All applications have an associated node
+  Ptr<Node>       m_node;      // All applications have an associated node
   RandomVariable* m_startVar;  // Random variable for start time
   RandomVariable* m_stopVar;   // Random variable for stop time
   EventId         m_startEvent;// Event identifier for start event
--- a/src/applications/onoff-application.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/applications/onoff-application.cc	Wed May 09 13:26:21 2007 -0400
@@ -42,7 +42,7 @@
 
 // Constructors
 
-  OnOffApplication::OnOffApplication(Node * n, 
+  OnOffApplication::OnOffApplication(Ptr<Node> n, 
                                      const Ipv4Address  rip,   // Remote IP addr
                                      uint16_t       rport, // Remote port
                                      const  RandomVariable& ontime,
@@ -67,7 +67,7 @@
 {
 }
 
-OnOffApplication::OnOffApplication(Node * n, const OnOffApplication& c)
+OnOffApplication::OnOffApplication(Ptr<Node> n, const OnOffApplication& c)
   : Application(n), 
     m_socket(0),
     m_peerIP(c.m_peerIP),
--- a/src/applications/onoff-application.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/applications/onoff-application.h	Wed May 09 13:26:21 2007 -0400
@@ -29,6 +29,7 @@
 
 #include "application.h"
 #include "ns3/event-id.h"
+#include "ns3/ptr.h"
 
 namespace ns3 {
 
@@ -40,7 +41,7 @@
 class OnOffApplication : public Application {
 
 public:
-  OnOffApplication(Node * n,
+  OnOffApplication(Ptr<Node> n,
                    const Ipv4Address,  // Peer IP address
                    uint16_t,           // Peer port
                    const RandomVariable&,     // Random variable for On time
@@ -48,7 +49,7 @@
                    DataRate  = g_defaultRate,  // Data rate when on
                    uint32_t = g_defaultSize);  // Size of packets
 
-  OnOffApplication(Node * n, const OnOffApplication&); // Copy constructor
+  OnOffApplication(Ptr<Node> n, const OnOffApplication&); // Copy constructor
   virtual ~OnOffApplication();               // Destructor
   virtual void StartApplication();    // Called at time specified by Start
   virtual void StopApplication();     // Called at time specified by Stop
--- a/src/core/ptr.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/core/ptr.cc	Wed May 09 13:26:21 2007 -0400
@@ -254,8 +254,8 @@
   m_nDestroyed = 0;
   {
     Ptr<NoCount> p = new NoCount (cb);
-    NoCount const&v1 = *p;
-    NoCount v2 = *p;
+    NoCount const&v1 = p.Peek();
+    NoCount v2 = p.Peek();
     v1.Nothing ();
     v2.Nothing ();
   }
--- a/src/core/ptr.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/core/ptr.h	Wed May 09 13:26:21 2007 -0400
@@ -72,7 +72,8 @@
   Ptr (Ptr<U> const &o);
   ~Ptr () ;
   Ptr<T> &operator = (Ptr const& o);
-  T const& operator * () const;
+  T const& Peek () const;
+  T * Get () const;
   T *operator -> () const;
   T *operator -> ();
   // allow if (!sp)
@@ -172,12 +173,20 @@
 
 template <typename T>
 T const& 
-Ptr<T>::operator * () const
+Ptr<T>::Peek () const
 {
   return *m_ptr;
 }
 
 template <typename T>
+T * 
+Ptr<T>::Get () const
+{
+  m_ptr->Ref();
+  return m_ptr;
+}
+
+template <typename T>
 T *
 Ptr<T>::operator -> () 
 {
@@ -219,7 +228,7 @@
     }
   else
     {
-      NS_ASSERT (m_ptr->IsSingle());
+      //NS_ASSERT (m_ptr->IsSingle());
       T *retval = m_ptr;
       m_ptr = 0;
       return retval;
--- a/src/devices/p2p/p2p-net-device.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/devices/p2p/p2p-net-device.cc	Wed May 09 13:26:21 2007 -0400
@@ -32,7 +32,7 @@
 
 namespace ns3 {
 
-PointToPointNetDevice::PointToPointNetDevice (Node* node) 
+PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node) 
 : 
   NetDevice(node, MacAddress ("00:00:00:00:00:00")), 
   m_txMachineState (READY),
--- a/src/devices/p2p/p2p-net-device.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/devices/p2p/p2p-net-device.h	Wed May 09 13:26:21 2007 -0400
@@ -30,6 +30,7 @@
 #include "ns3/callback-trace-source.h"
 #include "ns3/nstime.h"
 #include "ns3/data-rate.h"
+#include "ns3/ptr.h"
 
 namespace ns3 {
 
@@ -79,7 +80,7 @@
    * @see PointToPointTopology::AddPointToPointLink ()
    * @param node the Node to which this device is connected.
    */
-  PointToPointNetDevice (Node* node);
+  PointToPointNetDevice (Ptr<Node> node);
   /**
    * Copy Construct a PointToPointNetDevice
    *
--- a/src/devices/p2p/p2p-topology.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/devices/p2p/p2p-topology.cc	Wed May 09 13:26:21 2007 -0400
@@ -40,8 +40,8 @@
 
 PointToPointChannel *
 PointToPointTopology::AddPointToPointLink(
-  Node* n1,
-  Node* n2,
+  Ptr<Node> n1,
+  Ptr<Node> n2,
   const DataRate& bps,
   const Time& delay)
 {
@@ -65,8 +65,8 @@
 bool
 PointToPointTopology::AddIpv4Addresses(
   const PointToPointChannel *chan,
-  Node* n1, const Ipv4Address& addr1,
-  Node* n2, const Ipv4Address& addr2)
+  Ptr<Node> n1, const Ipv4Address& addr1,
+  Ptr<Node> n2, const Ipv4Address& addr2)
 {
 
   // Duplex link is assumed to be subnetted as a /30
@@ -116,7 +116,7 @@
 // there are possibly multiple devices connecting n1 and n2 (for example
 // wireless with two devices on different channels) this will return
 // the first one found.
-PointToPointNetDevice* PointToPointTopology::GetNetDevice(Node* n1, Node* n2)
+PointToPointNetDevice* PointToPointTopology::GetNetDevice(Ptr<Node> n1, Ptr<Node> n2)
 {
   // First get the NetDeviceList capability from node 1
   NetDeviceList* ndl1 = n1->GetNetDeviceList();
@@ -136,8 +136,8 @@
   
 // Get the channel connecting node n1 to node n2
 PointToPointChannel* PointToPointTopology::GetChannel(
-  Node* n1, 
-  Node* n2
+  Ptr<Node> n1, 
+  Ptr<Node> n2
 )
 {
   NetDevice* nd = GetNetDevice(n1, n2);
@@ -145,14 +145,14 @@
   return nd->GetChannel();
 }
 
-Queue* PointToPointTopology::GetQueue(Node* n1, Node* n2)
+Queue* PointToPointTopology::GetQueue(Ptr<Node> n1, Ptr<Node> n2)
 {
   NetDevice* nd = GetNetDevice(n1, n2);
   if (!nd) return 0; // No net device, so in queue
   return nd->GetQueue();
 }
 
-Queue* PointToPointTopology::SetQueue(Node* n1, Node* n2, const Queue& q)
+Queue* PointToPointTopology::SetQueue(Ptr<Node> n1, Ptr<Node> n2, const Queue& q)
 {
   NetDevice* nd = GetNetDevice(n1, n2);
   if (!nd) return 0; // No net device, can't set queue
@@ -163,8 +163,8 @@
 #endif
 
 #ifdef GFR
-P2PChannel* Topology::AddDuplexLink(Node* n1, const IPAddr& ip1, 
-                                    Node* n2, const IPAddr& ip2,
+P2PChannel* Topology::AddDuplexLink(Ptr<Node> n1, const IPAddr& ip1, 
+                                    Ptr<Node> n2, const IPAddr& ip2,
                                     const Rate& rate, const Time& delay)
 {
   // First get the NetDeviceList capability from each node
@@ -195,21 +195,21 @@
 }
 
 // Get the channel connecting node n1 to node n2
-Channel* Topology::GetChannel(Node* n1, Node* n2)
+Channel* Topology::GetChannel(Ptr<Node> n1, Ptr<Node> n2)
 {
   NetDevice* nd = GetNetDevice(n1, n2);
   if (!nd) return 0; // No net device, so no channel
   return nd->GetChannel();
 }
 
-Queue* Topology::GetQueue(Node* n1, Node* n2)
+Queue* Topology::GetQueue(Ptr<Node> n1, Ptr<Node> n2)
 {
   NetDevice* nd = GetNetDevice(n1, n2);
   if (!nd) return 0; // No net device, so in queue
   return nd->GetQueue();
 }
 
-Queue* Topology::SetQueue(Node* n1, Node* n2, const Queue& q)
+Queue* Topology::SetQueue(Ptr<Node> n1, Ptr<Node> n2, const Queue& q)
 {
   NetDevice* nd = GetNetDevice(n1, n2);
   if (!nd) return 0; // No net device, can't set queue
--- a/src/devices/p2p/p2p-topology.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/devices/p2p/p2p-topology.h	Wed May 09 13:26:21 2007 -0400
@@ -19,7 +19,7 @@
 //
 // Topology helper for ns3.
 // George F. Riley, Georgia Tech, Spring 2007
-
+#include "ns3/ptr.h"
 #ifndef __POINT_TO_POINT_TOPOLOGY_H__
 #define __POINT_TO_POINT_TOPOLOGY_H__
 
@@ -51,29 +51,29 @@
    * and propagation delay.
    */
   static PointToPointChannel* AddPointToPointLink(
-    Node*, Node*, const DataRate&, const Time&);
+    Ptr<Node>, Ptr<Node>, const DataRate&, const Time&);
 
   static bool AddIpv4Addresses(
     const PointToPointChannel*,
-    Node*, const Ipv4Address&,
-    Node*, const Ipv4Address&);
+    Ptr<Node>, const Ipv4Address&,
+    Ptr<Node>, const Ipv4Address&);
 
   /**
    * Get the connecting node n1 to node n2
    */
-  static PointToPointChannel* GetChannel(Node*, Node*);
+  static PointToPointChannel* GetChannel(Ptr<Node>, Ptr<Node>);
   /**
    * Get the NetDevice connecting node n1 to n2
    */
-  static PointToPointNetDevice* GetNetDevice(Node*, Node*);
+  static PointToPointNetDevice* GetNetDevice(Ptr<Node>, Ptr<Node>);
   /**
    * Get the queue associated with a link between two nodes
    */
-  static Queue* GetQueue(Node*, Node*);
+  static Queue* GetQueue(Ptr<Node>, Ptr<Node>);
   /**
    * Set the queue associated with a link between two nodes
    */
-  static Queue* SetQueue(Node*, Node*, const Queue&);
+  static Queue* SetQueue(Ptr<Node>, Ptr<Node>, const Queue&);
 };
 
 } // namespace ns3
--- a/src/node/net-device.cc	Tue May 08 11:44:04 2007 -0400
+++ b/src/node/net-device.cc	Wed May 09 13:26:21 2007 -0400
@@ -29,7 +29,7 @@
 
 namespace ns3 {
 
-NetDevice::NetDevice(Node *node, const MacAddress& addr) : 
+NetDevice::NetDevice(Ptr<Node> node, const MacAddress& addr) : 
   m_node (node), 
   m_name(""), 
   m_ifIndex (0), 
@@ -228,7 +228,7 @@
     }
 }
 
-Node *
+Ptr<Node>
 NetDevice::PeekNode (void) const
 {
   return m_node;
--- a/src/node/net-device.h	Tue May 08 11:44:04 2007 -0400
+++ b/src/node/net-device.h	Wed May 09 13:26:21 2007 -0400
@@ -27,6 +27,7 @@
 #include "ns3/packet.h"
 #include "ns3/object.h"
 #include "mac-address.h"
+#include "ns3/ptr.h"
 
 namespace ns3 {
 
@@ -61,7 +62,7 @@
    * \param node base class node pointer of device's node 
    * \param addr MAC address of this device.
    */
-  NetDevice(Node* node, const MacAddress& addr);
+  NetDevice(Ptr<Node> node, const MacAddress& addr);
   virtual ~NetDevice();
 
   /**
@@ -169,7 +170,7 @@
    * base class to print the nodeid for example, it can invoke
    * this method.
    */
-  Node* PeekNode (void) const;
+  Ptr<Node> PeekNode (void) const;
 
   bool NeedsArp (void) const;
 
@@ -241,7 +242,7 @@
   virtual bool DoNeedsArp (void) const = 0;
   virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0;
   virtual Channel *DoGetChannel (void) const = 0;
-  Node*         m_node;
+  Ptr<Node>         m_node;
   std::string   m_name;
   uint16_t      m_ifIndex;
   MacAddress    m_address;