From 041fcd17527320495224371f8e06c1e107776320 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 31 Jan 2007 20:14:23 +0100 Subject: [PATCH] add ns3::Ptr::operator * with a few tests --- src/core/ptr.cc | 18 ++++++++++++++++++ src/core/ptr.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/src/core/ptr.cc b/src/core/ptr.cc index 47f2829d5..a9ba89970 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -32,6 +32,7 @@ class NoCount public: NoCount (Callback cb); ~NoCount (); + void Nothing () const; private: Callback m_cb; }; @@ -42,6 +43,9 @@ NoCount::~NoCount () { m_cb (); } +void +NoCount::Nothing () const +{} class PtrTest : Test { @@ -244,6 +248,20 @@ PtrTest::RunTests (void) } delete raw; } + + + m_nDestroyed = 0; + { + Ptr p = new NoCount (cb); + NoCount const&v1 = *p; + NoCount v2 = *p; + v1.Nothing (); + v2.Nothing (); + } + if (m_nDestroyed != 2) + { + ok = false; + } return ok; diff --git a/src/core/ptr.h b/src/core/ptr.h index 4b4c9c202..06ea24c76 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -75,6 +75,7 @@ public: Ptr (Ptr const &o); ~Ptr () ; Ptr &operator = (Ptr const& o); + T const& operator * () const; T *operator -> () const; T *operator -> (); // allow if (!sp) @@ -202,6 +203,13 @@ Ptr::operator = (Ptr const& o) return *this; } +template +T const& +Ptr::operator * () const +{ + return *m_ptr; +} + template T * Ptr::operator -> ()