--- a/samples/main-ptr.cc Wed May 09 13:26:21 2007 -0400
+++ b/samples/main-ptr.cc Wed May 09 19:48:33 2007 +0200
@@ -67,7 +67,8 @@
// remove the raw pointer from its smart pointer.
// we can do this because the refcount is exactly one
// here
- A *raw = prev.Remove ();
+ A *raw = prev.Get ();
+ prev = 0;
raw->Method ();
delete raw;
}
--- a/src/core/ptr.cc Wed May 09 13:26:21 2007 -0400
+++ b/src/core/ptr.cc Wed May 09 19:48:33 2007 +0200
@@ -241,7 +241,8 @@
{
Ptr<NoCount const> p1 = p;
}
- raw = p.Remove ();
+ raw = p.Get ();
+ p = 0;
}
if (m_nDestroyed != 0)
{
@@ -254,12 +255,12 @@
m_nDestroyed = 0;
{
Ptr<NoCount> p = new NoCount (cb);
- NoCount const&v1 = p.Peek();
- NoCount v2 = p.Peek();
- v1.Nothing ();
- v2.Nothing ();
+ const NoCount *v1 = p.Peek();
+ NoCount *v2 = p.Peek();
+ v1->Nothing ();
+ v2->Nothing ();
}
- if (m_nDestroyed != 2)
+ if (m_nDestroyed != 1)
{
ok = false;
}
--- a/src/core/ptr.h Wed May 09 13:26:21 2007 -0400
+++ b/src/core/ptr.h Wed May 09 19:48:33 2007 +0200
@@ -72,7 +72,23 @@
Ptr (Ptr<U> const &o);
~Ptr () ;
Ptr<T> &operator = (Ptr const& o);
- T const& Peek () const;
+
+ /**
+ * \return the pointer managed by this smart pointer.
+ *
+ * The underlying refcount is not incremented prior
+ * to returning to the caller so the caller is not
+ * responsible for calling Unref himself.
+ */
+ T * Peek () const;
+
+ /**
+ * \return the pointer managed by this smart pointer.
+ *
+ * The underlying refcount is incremented prior
+ * to returning to the caller so the caller is
+ * responsible for calling Unref himself.
+ */
T * Get () const;
T *operator -> () const;
T *operator -> ();
@@ -97,20 +113,6 @@
inline friend Ptr<T1> const_pointer_cast (Ptr<T2> const&p);
- /**
- * \returns raw pointer
- *
- * It is a programming error to invoke this method when
- * the reference count of the smart pointer is not one.
- * If you try to do it anyway, an assert will be triggered.
- * If asserts are disabled, bad things will happen.
- * Once you have successfully called Ptr<T>::Remove on
- * a smart pointer, the smart pointer will forget
- * about the raw pointer and will stop managing it. As such,
- * you, as the caller, become responsible for invoking
- * operator delete on the returned raw pointer.
- */
- T *Remove (void);
};
template <typename T>
@@ -172,10 +174,10 @@
}
template <typename T>
-T const&
+T *
Ptr<T>::Peek () const
{
- return *m_ptr;
+ return m_ptr;
}
template <typename T>
@@ -218,23 +220,6 @@
return &test;
}
-template <typename T>
-T *
-Ptr<T>::Remove (void)
-{
- if (m_ptr == 0)
- {
- return (T *) 0;
- }
- else
- {
- //NS_ASSERT (m_ptr->IsSingle());
- T *retval = m_ptr;
- m_ptr = 0;
- return retval;
- }
-}
-
// non-member friend functions.
template <typename T1, typename T2>
bool