diff --git a/src/core/ptr.cc b/src/core/ptr.cc index feb09ad61..4ff6da941 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -23,49 +23,80 @@ #ifdef RUN_SELF_TESTS #include "test.h" -#include "callback.h" -#include "object.h" namespace ns3 { +class NoCount; + template void Foo (void) {} - -class NoCount : public Object -{ -public: - NoCount (void (*fn) (void)); - NoCount (Callback cb); - ~NoCount (); - void Nothing (void) const; -private: - Callback m_cb; -}; -NoCount::NoCount (Callback cb) - : m_cb (cb) -{} -NoCount::~NoCount () -{ - m_cb (); -} -void -NoCount::Nothing () const -{} - class PtrTest : Test { public: PtrTest (); virtual ~PtrTest (); virtual bool RunTests (void); -private: void DestroyNotify (void); +private: Ptr CallTest (Ptr p); Ptr const CallTestConst (Ptr const p); uint32_t m_nDestroyed; }; + +class Base +{ +public: + Base (); + virtual ~Base (); + void Ref (void) const; + void Unref (void) const; +private: + mutable uint32_t m_count; +}; + +class NoCount : public Base +{ +public: + NoCount (PtrTest *test); + ~NoCount (); + void Nothing (void) const; +private: + PtrTest *m_test; +}; + +Base::Base () + : m_count (1) +{} +Base::~Base () +{} +void +Base::Ref (void) const +{ + m_count++; +} +void +Base::Unref (void) const +{ + m_count--; + if (m_count == 0) + { + delete this; + } +} + +NoCount::NoCount (PtrTest *test) + : m_test (test) +{} +NoCount::~NoCount () +{ + m_test->DestroyNotify (); +} +void +NoCount::Nothing () const +{} + PtrTest::PtrTest () : Test ("Ptr") {} @@ -95,10 +126,9 @@ PtrTest::RunTests (void) { bool ok = true; - Callback cb = MakeCallback (&PtrTest::DestroyNotify, this); m_nDestroyed = false; { - Ptr p = CreateObject (cb); + Ptr p = Create (this); } if (m_nDestroyed != 1) { @@ -108,7 +138,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p; - p = CreateObject (cb); + p = Create (this); p = p; } if (m_nDestroyed != 1) @@ -119,7 +149,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = CreateObject (cb); + p1 = Create (this); Ptr p2 = p1; } if (m_nDestroyed != 1) @@ -130,7 +160,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = CreateObject (cb); + p1 = Create (this); Ptr p2; p2 = p1; } @@ -142,8 +172,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = CreateObject (cb); - Ptr p2 = CreateObject (cb); + p1 = Create (this); + Ptr p2 = Create (this); p2 = p1; } if (m_nDestroyed != 2) @@ -154,9 +184,9 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = CreateObject (cb); + p1 = Create (this); Ptr p2; - p2 = CreateObject (cb); + p2 = Create (this); p2 = p1; } if (m_nDestroyed != 2) @@ -167,8 +197,8 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { Ptr p1; - p1 = CreateObject (cb); - p1 = CreateObject (cb); + p1 = Create (this); + p1 = Create (this); } if (m_nDestroyed != 2) { @@ -180,8 +210,8 @@ PtrTest::RunTests (void) Ptr p1; { Ptr p2; - p1 = CreateObject (cb); - p2 = CreateObject (cb); + p1 = Create (this); + p2 = Create (this); p2 = p1; } if (m_nDestroyed != 1) @@ -199,8 +229,8 @@ PtrTest::RunTests (void) Ptr p1; { Ptr p2; - p1 = CreateObject (cb); - p2 = CreateObject (cb); + p1 = Create (this); + p2 = Create (this); p2 = CallTest (p1); } if (m_nDestroyed != 1) @@ -242,7 +272,7 @@ PtrTest::RunTests (void) { NoCount *raw; { - Ptr p = CreateObject (cb); + Ptr p = Create (this); { Ptr p1 = p; } @@ -259,7 +289,7 @@ PtrTest::RunTests (void) m_nDestroyed = 0; { - Ptr p = CreateObject (cb); + Ptr p = Create (this); const NoCount *v1 = PeekPointer (p); NoCount *v2 = PeekPointer (p); v1->Nothing (); @@ -271,8 +301,8 @@ PtrTest::RunTests (void) } { - Ptr p0 = CreateObject (cb); - Ptr p1 = CreateObject (cb); + Ptr p0 = Create (this); + Ptr p1 = Create (this); if (p0 == p1) { ok = false; @@ -285,7 +315,7 @@ PtrTest::RunTests (void) ok = false; } } - +#if 0 { Ptr p = CreateObject (cb); Callback callback = MakeCallback (&NoCount::Nothing, p); @@ -296,12 +326,12 @@ PtrTest::RunTests (void) Callback callback = MakeCallback (&NoCount::Nothing, p); callback (); } - +#endif #if 0 // as expected, fails compilation. { - Ptr p = CreateObject (cb); + Ptr p = Create (cb); Callback callback = MakeCallback (&NoCount::Nothing, p); } // local types are not allowed as arguments to a template. diff --git a/utils/mobility-visualizer-model.cc b/utils/mobility-visualizer-model.cc index aaa3fae63..2abec2202 100644 --- a/utils/mobility-visualizer-model.cc +++ b/utils/mobility-visualizer-model.cc @@ -14,6 +14,7 @@ #include "ns3/node.h" #include "ns3/node-list.h" #include "ns3/rectangle-default-value.h" +#include "ns3/type-id-default-value.h" #include "mobility-visualizer.h" @@ -100,7 +101,7 @@ int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, doub Simulator::Schedule (g_sampleInterval, Sample); - ClassId mobType = DefaultValueListGet ("RandomTopologyMobilityType")->GetValue (); + TypeId mobType = DefaultValueListGet ("RandomTopologyMobilityType")->GetValue (); if (mobType.GetName () == "RandomWalk2dMobilityModel") { Rectangle bounds = DefaultValueListGet ("RandomWalk2dBounds")->GetValue ();