From ecfcfa977d4413ae36e319024413daa2e2c26462 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Wed, 9 May 2007 13:26:21 -0400 Subject: [PATCH] Node* -> Ptr --- examples/simple-p2p.cc | 9 +++++---- src/applications/application-list.cc | 6 +++--- src/applications/application-list.h | 6 +++--- src/applications/application.cc | 6 +++--- src/applications/application.h | 10 ++++++---- src/applications/onoff-application.cc | 4 ++-- src/applications/onoff-application.h | 5 +++-- src/core/ptr.cc | 4 ++-- src/core/ptr.h | 15 +++++++++++--- src/devices/p2p/p2p-net-device.cc | 2 +- src/devices/p2p/p2p-net-device.h | 3 ++- src/devices/p2p/p2p-topology.cc | 28 +++++++++++++-------------- src/devices/p2p/p2p-topology.h | 16 +++++++-------- src/node/net-device.cc | 4 ++-- src/node/net-device.h | 7 ++++--- 15 files changed, 70 insertions(+), 55 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index fb4f91311..2ec17cf80 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -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 @@ int main (int argc, char *argv[]) // 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 n0 = new InternetNode (); + Ptr n1 = new InternetNode (); + Ptr n2 = new InternetNode (); + Ptr n3 = new InternetNode (); // We create the channels first without any IP addressing information PointToPointChannel *channel0 = diff --git a/src/applications/application-list.cc b/src/applications/application-list.cc index 068b29581..1c9059c8b 100644 --- a/src/applications/application-list.cc +++ b/src/applications/application-list.cc @@ -28,7 +28,7 @@ namespace ns3{ const Iid ApplicationList::iid ("ApplicationList"); -ApplicationList::ApplicationList(Node* n) +ApplicationList::ApplicationList(Ptr n) : NsUnknown (ApplicationList::iid) {} @@ -49,7 +49,7 @@ ApplicationList::DoDispose (void) ApplicationList::~ApplicationList() {} -ApplicationList* ApplicationList::Copy(Node * n) const +ApplicationList* ApplicationList::Copy(Ptr n) const { // Copy this app list ApplicationList* r = new ApplicationList(n); return r; @@ -62,7 +62,7 @@ ApplicationList::Add(Application* a) m_apps.push_back(a); } -void ApplicationList::SetNode(Node * n) +void ApplicationList::SetNode(Ptr n) { // Set the node pointer in each application for (std::vector::const_iterator i = m_apps.begin(); diff --git a/src/applications/application-list.h b/src/applications/application-list.h index 4e37f5aa0..8a30b2de5 100644 --- a/src/applications/application-list.h +++ b/src/applications/application-list.h @@ -34,12 +34,12 @@ class ApplicationList : public NsUnknown { public: static const Iid iid; - ApplicationList(Node*); + ApplicationList(Ptr); // 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) const; + virtual void SetNode(Ptr); // Sets the node for all apps virtual void Add(Application*); // Add an already new'ed app // Manage the list template T* AddCopy(const T& t) // Add a new application diff --git a/src/applications/application.cc b/src/applications/application.cc index c44075b27..9379c87e4 100644 --- a/src/applications/application.cc +++ b/src/applications/application.cc @@ -34,7 +34,7 @@ namespace ns3 { // Application Methods // \brief Application Constructor -Application::Application(Node * n) +Application::Application(Ptr n) : m_node (n), m_startVar(0), m_stopVar(0), m_start(false), m_stop(false) @@ -147,7 +147,7 @@ void Application::Stop(const RandomVariable& stopVar) // \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 n) { if (m_node != 0) { @@ -157,7 +157,7 @@ void Application::SetNode(Node * n) m_node->Ref (); } -Node* Application::PeekNode() const +Ptr Application::PeekNode() const { return m_node; } diff --git a/src/applications/application.h b/src/applications/application.h index 9d6c4cb4d..a85bfbf40 100644 --- a/src/applications/application.h +++ b/src/applications/application.h @@ -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 RandomVariable; class Application : public Object { public: - Application(Node *); + Application(Ptr); Application(const Application&); // Copy constructor Application& operator=(const Application&); // Assignment operator virtual ~Application(); @@ -100,13 +102,13 @@ void Start(const RandomVariable&); // \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); // \brief Returns the pointer to the attached node. - Node* PeekNode() const; + Ptr PeekNode() const; // Members - Node * m_node; // All applications have an associated node + Ptr 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 diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index 7682faa4b..ac74ef13e 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -42,7 +42,7 @@ uint32_t OnOffApplication::g_defaultSize = 512; // Constructors - OnOffApplication::OnOffApplication(Node * n, + OnOffApplication::OnOffApplication(Ptr n, const Ipv4Address rip, // Remote IP addr uint16_t rport, // Remote port const RandomVariable& ontime, @@ -67,7 +67,7 @@ uint32_t OnOffApplication::g_defaultSize = 512; { } -OnOffApplication::OnOffApplication(Node * n, const OnOffApplication& c) +OnOffApplication::OnOffApplication(Ptr n, const OnOffApplication& c) : Application(n), m_socket(0), m_peerIP(c.m_peerIP), diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index b259f7682..ff19e7458 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -29,6 +29,7 @@ #include "application.h" #include "ns3/event-id.h" +#include "ns3/ptr.h" namespace ns3 { @@ -40,7 +41,7 @@ class DataRate; class OnOffApplication : public Application { public: - OnOffApplication(Node * n, + OnOffApplication(Ptr n, const Ipv4Address, // Peer IP address uint16_t, // Peer port const RandomVariable&, // Random variable for On time @@ -48,7 +49,7 @@ public: DataRate = g_defaultRate, // Data rate when on uint32_t = g_defaultSize); // Size of packets - OnOffApplication(Node * n, const OnOffApplication&); // Copy constructor + OnOffApplication(Ptr 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 diff --git a/src/core/ptr.cc b/src/core/ptr.cc index 28608f62b..a0d37633c 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -254,8 +254,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p = new NoCount (cb); - NoCount const&v1 = *p; - NoCount v2 = *p; + NoCount const&v1 = p.Peek(); + NoCount v2 = p.Peek(); v1.Nothing (); v2.Nothing (); } diff --git a/src/core/ptr.h b/src/core/ptr.h index ce49f3a4b..7af3440bd 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -72,7 +72,8 @@ public: Ptr (Ptr const &o); ~Ptr () ; Ptr &operator = (Ptr const& o); - T const& operator * () const; + T const& Peek () const; + T * Get () const; T *operator -> () const; T *operator -> (); // allow if (!sp) @@ -172,11 +173,19 @@ Ptr::operator = (Ptr const& o) template T const& -Ptr::operator * () const +Ptr::Peek () const { return *m_ptr; } +template +T * +Ptr::Get () const +{ + m_ptr->Ref(); + return m_ptr; +} + template T * Ptr::operator -> () @@ -219,7 +228,7 @@ Ptr::Remove (void) } else { - NS_ASSERT (m_ptr->IsSingle()); + //NS_ASSERT (m_ptr->IsSingle()); T *retval = m_ptr; m_ptr = 0; return retval; diff --git a/src/devices/p2p/p2p-net-device.cc b/src/devices/p2p/p2p-net-device.cc index ae322c4fa..06d8fb269 100644 --- a/src/devices/p2p/p2p-net-device.cc +++ b/src/devices/p2p/p2p-net-device.cc @@ -32,7 +32,7 @@ NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice"); namespace ns3 { -PointToPointNetDevice::PointToPointNetDevice (Node* node) +PointToPointNetDevice::PointToPointNetDevice (Ptr node) : NetDevice(node, MacAddress ("00:00:00:00:00:00")), m_txMachineState (READY), diff --git a/src/devices/p2p/p2p-net-device.h b/src/devices/p2p/p2p-net-device.h index 2826f6f1b..2d27921c4 100644 --- a/src/devices/p2p/p2p-net-device.h +++ b/src/devices/p2p/p2p-net-device.h @@ -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 @@ public: * @see PointToPointTopology::AddPointToPointLink () * @param node the Node to which this device is connected. */ - PointToPointNetDevice (Node* node); + PointToPointNetDevice (Ptr node); /** * Copy Construct a PointToPointNetDevice * diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 6ff05eab9..ff4f9e3bf 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -40,8 +40,8 @@ namespace ns3 { PointToPointChannel * PointToPointTopology::AddPointToPointLink( - Node* n1, - Node* n2, + Ptr n1, + Ptr n2, const DataRate& bps, const Time& delay) { @@ -65,8 +65,8 @@ PointToPointTopology::AddPointToPointLink( bool PointToPointTopology::AddIpv4Addresses( const PointToPointChannel *chan, - Node* n1, const Ipv4Address& addr1, - Node* n2, const Ipv4Address& addr2) + Ptr n1, const Ipv4Address& addr1, + Ptr n2, const Ipv4Address& addr2) { // Duplex link is assumed to be subnetted as a /30 @@ -116,7 +116,7 @@ PointToPointTopology::AddIpv4Addresses( // 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 n1, Ptr n2) { // First get the NetDeviceList capability from node 1 NetDeviceList* ndl1 = n1->GetNetDeviceList(); @@ -136,8 +136,8 @@ PointToPointNetDevice* PointToPointTopology::GetNetDevice(Node* n1, Node* n2) // Get the channel connecting node n1 to node n2 PointToPointChannel* PointToPointTopology::GetChannel( - Node* n1, - Node* n2 + Ptr n1, + Ptr n2 ) { NetDevice* nd = GetNetDevice(n1, n2); @@ -145,14 +145,14 @@ PointToPointChannel* PointToPointTopology::GetChannel( return nd->GetChannel(); } -Queue* PointToPointTopology::GetQueue(Node* n1, Node* n2) +Queue* PointToPointTopology::GetQueue(Ptr n1, Ptr 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 n1, Ptr n2, const Queue& q) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue @@ -163,8 +163,8 @@ Queue* PointToPointTopology::SetQueue(Node* n1, Node* n2, const Queue& q) #endif #ifdef GFR -P2PChannel* Topology::AddDuplexLink(Node* n1, const IPAddr& ip1, - Node* n2, const IPAddr& ip2, +P2PChannel* Topology::AddDuplexLink(Ptr n1, const IPAddr& ip1, + Ptr n2, const IPAddr& ip2, const Rate& rate, const Time& delay) { // First get the NetDeviceList capability from each node @@ -195,21 +195,21 @@ P2PChannel* Topology::AddDuplexLink(Node* n1, const IPAddr& ip1, } // Get the channel connecting node n1 to node n2 -Channel* Topology::GetChannel(Node* n1, Node* n2) +Channel* Topology::GetChannel(Ptr n1, Ptr 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 n1, Ptr 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 n1, Ptr n2, const Queue& q) { NetDevice* nd = GetNetDevice(n1, n2); if (!nd) return 0; // No net device, can't set queue diff --git a/src/devices/p2p/p2p-topology.h b/src/devices/p2p/p2p-topology.h index dc8cbb88d..ac43f1918 100644 --- a/src/devices/p2p/p2p-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -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 @@ public: * and propagation delay. */ static PointToPointChannel* AddPointToPointLink( - Node*, Node*, const DataRate&, const Time&); + Ptr, Ptr, const DataRate&, const Time&); static bool AddIpv4Addresses( const PointToPointChannel*, - Node*, const Ipv4Address&, - Node*, const Ipv4Address&); + Ptr, const Ipv4Address&, + Ptr, const Ipv4Address&); /** * Get the connecting node n1 to node n2 */ - static PointToPointChannel* GetChannel(Node*, Node*); + static PointToPointChannel* GetChannel(Ptr, Ptr); /** * Get the NetDevice connecting node n1 to n2 */ - static PointToPointNetDevice* GetNetDevice(Node*, Node*); + static PointToPointNetDevice* GetNetDevice(Ptr, Ptr); /** * Get the queue associated with a link between two nodes */ - static Queue* GetQueue(Node*, Node*); + static Queue* GetQueue(Ptr, Ptr); /** * Set the queue associated with a link between two nodes */ - static Queue* SetQueue(Node*, Node*, const Queue&); + static Queue* SetQueue(Ptr, Ptr, const Queue&); }; } // namespace ns3 diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 40ecc59ae..401fb2a52 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -29,7 +29,7 @@ namespace ns3 { -NetDevice::NetDevice(Node *node, const MacAddress& addr) : +NetDevice::NetDevice(Ptr node, const MacAddress& addr) : m_node (node), m_name(""), m_ifIndex (0), @@ -228,7 +228,7 @@ NetDevice::NotifyLinkDown (void) } } -Node * +Ptr NetDevice::PeekNode (void) const { return m_node; diff --git a/src/node/net-device.h b/src/node/net-device.h index cfb4a40e9..a0414ee7d 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -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 @@ public: * \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, const MacAddress& addr); virtual ~NetDevice(); /** @@ -169,7 +170,7 @@ public: * base class to print the nodeid for example, it can invoke * this method. */ - Node* PeekNode (void) const; + Ptr PeekNode (void) const; bool NeedsArp (void) const; @@ -241,7 +242,7 @@ public: virtual bool DoNeedsArp (void) const = 0; virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context) = 0; virtual Channel *DoGetChannel (void) const = 0; - Node* m_node; + Ptr m_node; std::string m_name; uint16_t m_ifIndex; MacAddress m_address;