add ns3::Ptr<T>::operator * with a few tests

This commit is contained in:
Mathieu Lacage
2007-01-31 20:14:23 +01:00
parent b37a9d44e8
commit 041fcd1752
2 changed files with 26 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ class NoCount
public:
NoCount (Callback<void> cb);
~NoCount ();
void Nothing () const;
private:
Callback<void> 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<NoCount> p = new NoCount (cb);
NoCount const&v1 = *p;
NoCount v2 = *p;
v1.Nothing ();
v2.Nothing ();
}
if (m_nDestroyed != 2)
{
ok = false;
}
return ok;

View File

@@ -75,6 +75,7 @@ public:
Ptr (Ptr<U> const &o);
~Ptr () ;
Ptr<T> &operator = (Ptr const& o);
T const& operator * () const;
T *operator -> () const;
T *operator -> ();
// allow if (!sp)
@@ -202,6 +203,13 @@ Ptr<T>::operator = (Ptr const& o)
return *this;
}
template <typename T>
T const&
Ptr<T>::operator * () const
{
return *m_ptr;
}
template <typename T>
T *
Ptr<T>::operator -> ()