rework the refcounting framework to use the MakeNewObject function

This commit is contained in:
Mathieu Lacage
2007-05-11 08:59:49 +02:00
parent d82a6d11f9
commit 720fae1bbe
9 changed files with 34 additions and 34 deletions

View File

@@ -101,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.
Ptr<Node> n0 = new InternetNode ();
Ptr<Node> n1 = new InternetNode ();
Ptr<Node> n2 = new InternetNode ();
Ptr<Node> n3 = new InternetNode ();
Ptr<Node> n0 = MakeNewObject<InternetNode> ();
Ptr<Node> n1 = MakeNewObject<InternetNode> ();
Ptr<Node> n2 = MakeNewObject<InternetNode> ();
Ptr<Node> n3 = MakeNewObject<InternetNode> ();
// We create the channels first without any IP addressing information
Ptr<PointToPointChannel> channel0 =
@@ -134,7 +134,7 @@ int main (int argc, char *argv[])
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
Ptr<OnOffApplication> ooff0 = new OnOffApplication(
Ptr<OnOffApplication> ooff0 = MakeNewObject<OnOffApplication> (
n0,
Ipv4Address("10.1.3.2"),
80,
@@ -151,7 +151,7 @@ int main (int argc, char *argv[])
ooff0->Stop (Seconds(10.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
Ptr<OnOffApplication> ooff1 = new OnOffApplication(
Ptr<OnOffApplication> ooff1 = MakeNewObject<OnOffApplication> (
n3,
Ipv4Address("10.1.2.1"),
80,

View File

@@ -38,7 +38,7 @@ PrintTraffic (Ptr<Socket> socket)
void
RunSimulation (void)
{
Ptr<InternetNode> a = new InternetNode ();
Ptr<InternetNode> a = MakeNewObject<InternetNode> ();
Ptr<IUdp> udp = a->QueryInterface<IUdp> (IUdp::iid);

View File

@@ -141,7 +141,7 @@ A::A ()
m_oneBoolInvoked (false),
m_oneUi32Invoked (false)
{
ns3::Ptr<B> b = new B ();
ns3::Ptr<B> b = ns3::MakeNewObject<B> ();
AddInterface (b);
}
@@ -152,7 +152,7 @@ A::A (bool bo)
m_oneUi32Invoked (false),
m_bool (bo)
{
ns3::Ptr<B> b = new B ();
ns3::Ptr<B> b = ns3::MakeNewObject<B> ();
AddInterface (b);
}
@@ -163,7 +163,7 @@ A::A (uint32_t i)
m_oneUi32Invoked (true),
m_ui32 (i)
{
ns3::Ptr<B> b = new B ();
ns3::Ptr<B> b = ns3::MakeNewObject<B> ();
AddInterface (b);
}

View File

@@ -259,19 +259,19 @@ template <typename T>
Ptr<NsUnknown>
NsUnknownManager::MakeObjectZero (void)
{
return new T ();
return MakeNewObject<T> ();
}
template <typename T, typename T1>
Ptr<NsUnknown>
NsUnknownManager::MakeObjectOne (T1 a1)
{
return new T (a1);
return MakeNewObject<T> (a1);
}
template <typename T, typename T1, typename T2>
Ptr<NsUnknown>
NsUnknownManager::MakeObjectTwo (T1 a1, T2 a2)
{
return new T (a1, a2);
return MakeNewObject<T> (a1, a2);
}
} // namespace ns3

View File

@@ -65,7 +65,7 @@ private:
};
NsUnknownImpl::NsUnknownImpl (Iid iid, NsUnknown * interface)
: m_ref (0),
: m_ref (1),
m_disposed (false)
{
NS_DEBUG ("new " << this << " ref=" << m_ref);
@@ -316,9 +316,9 @@ InterfaceTest::RunTests (void)
//DerivedAB *derivedAB;
Ptr<A> a = new A ();
Ptr<A> a = MakeNewObject<A> ();
a = new A ();
a = MakeNewObject<A> ();
Ptr<A> a1 = a->QueryInterface<A> (A::iid);
if (a1 == 0 || a1 != a)
{
@@ -330,14 +330,14 @@ InterfaceTest::RunTests (void)
ok = false;
}
Ptr<B> b = new B ();
Ptr<B> b = MakeNewObject<B> ();
Ptr<B> b1 = b->QueryInterface<B> (B::iid);
if (b1 == 0 || b1 != b)
{
ok = false;
}
a = new A ();
a = MakeNewObject<A> ();
a->AddInterface (b);
b1 = b->QueryInterface<B> (B::iid);
if (b1 == 0 || b1 != b)
@@ -360,7 +360,7 @@ InterfaceTest::RunTests (void)
ok = false;
}
Ptr<Derived> derived = new Derived ();
Ptr<Derived> derived = MakeNewObject<Derived> ();
Ptr<Base> base = derived->QueryInterface<Base> (Base::iid);
if (base == 0)
{

View File

@@ -27,7 +27,7 @@ NS_DEBUG_COMPONENT_DEFINE ("Object");
namespace ns3 {
Object::Object ()
: m_count (0),
: m_count (1),
m_disposed (false)
{
NS_DEBUG ("Object::Object: m_count=0");

View File

@@ -45,15 +45,15 @@ PointToPointTopology::AddPointToPointLink(
const DataRate& bps,
const Time& delay)
{
Ptr<PointToPointChannel> channel = new PointToPointChannel(bps, delay);
Ptr<PointToPointChannel> channel = MakeNewObject<PointToPointChannel> (bps, delay);
Ptr<PointToPointNetDevice> net1 = new PointToPointNetDevice(n1);
Ptr<PointToPointNetDevice> net1 = MakeNewObject<PointToPointNetDevice> (n1);
net1->AddQueue(Queue::Default().Copy());
n1->AddDevice (net1);
net1->Attach (channel);
Ptr<PointToPointNetDevice> net2 = new PointToPointNetDevice(n2);
Ptr<PointToPointNetDevice> net2 = MakeNewObject<PointToPointNetDevice> (n2);
net2->AddQueue(Queue::Default().Copy());
n2->AddDevice (net2);

View File

@@ -41,22 +41,22 @@ namespace ns3 {
InternetNode::InternetNode()
{
Ptr<Ipv4> ipv4 = new Ipv4 (this);
Ptr<Arp> arp = new Arp (this);
Ptr<Udp> udp = new Udp (this);
Ptr<Ipv4> ipv4 = MakeNewObject<Ipv4> (this);
Ptr<Arp> arp = MakeNewObject<Arp> (this);
Ptr<Udp> udp = MakeNewObject<Udp> (this);
Ptr<ApplicationList> applicationList = new ApplicationList(this);
Ptr<L3Demux> l3Demux = new L3Demux(this);
Ptr<Ipv4L4Demux> ipv4L4Demux = new Ipv4L4Demux(this);
Ptr<ApplicationList> applicationList = MakeNewObject<ApplicationList> (this);
Ptr<L3Demux> l3Demux = MakeNewObject<L3Demux> (this);
Ptr<Ipv4L4Demux> ipv4L4Demux = MakeNewObject<Ipv4L4Demux> (this);
l3Demux->Insert (ipv4);
l3Demux->Insert (arp);
ipv4L4Demux->Insert (udp);
Ptr<IUdpImpl> udpImpl = new IUdpImpl (udp);
Ptr<IArpPrivate> arpPrivate = new IArpPrivate (arp);
Ptr<IIpv4Impl> ipv4Impl = new IIpv4Impl (ipv4);
Ptr<IIpv4Private> ipv4Private = new IIpv4Private (ipv4);
Ptr<IUdpImpl> udpImpl = MakeNewObject<IUdpImpl> (udp);
Ptr<IArpPrivate> arpPrivate = MakeNewObject<IArpPrivate> (arp);
Ptr<IIpv4Impl> ipv4Impl = MakeNewObject<IIpv4Impl> (ipv4);
Ptr<IIpv4Private> ipv4Private = MakeNewObject<IIpv4Private> (ipv4);
NsUnknown::AddInterface (ipv4Private);
NsUnknown::AddInterface (ipv4Impl);

View File

@@ -68,7 +68,7 @@ Udp::DoDispose (void)
Ptr<Socket>
Udp::CreateSocket (void)
{
Ptr<Socket> socket = new UdpSocket (m_node, this);
Ptr<Socket> socket = MakeNewObject<UdpSocket> (m_node, this);
return socket;
}