add ns3::Ptr<T>::operator * with a few tests
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 -> ()
|
||||
|
||||
Reference in New Issue
Block a user