gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ./ChangeLog libbase/smart_ptr.h


From: Bastiaan Jacques
Subject: [Gnash-commit] gnash ./ChangeLog libbase/smart_ptr.h
Date: Mon, 24 Apr 2006 23:46:44 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Branch:         
Changes by:     Bastiaan Jacques <address@hidden>       06/04/24 23:46:44

Modified files:
        .              : ChangeLog 
        libbase        : smart_ptr.h 

Log message:
        * libbase/smart_ptr.h: Introduce noref_ptr, a smart pointer without 
reference
        counting.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.229&tr2=1.230&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/libbase/smart_ptr.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.229 gnash/ChangeLog:1.230
--- gnash/ChangeLog:1.229       Mon Apr 24 23:05:55 2006
+++ gnash/ChangeLog     Mon Apr 24 23:46:43 2006
@@ -1,3 +1,8 @@
+2006-04-25 Bastiaan Jacques <address@hidden>
+
+       * libbase/smart_ptr.h: Introduce noref_ptr, a smart pointer without
+       reference counting.
+
 2006-04-24  Rob Savoye  <address@hidden>
 
        * All GPL'd files: Update Mozilla copyright exemption to the
@@ -11,7 +16,7 @@
        correctly.
        * server/impl.cpp: Call read_jpeg() instead of read_swf_jpeg2().
 
-2006-04-23 <address@hidden>
+2006-04-23 Bastiaan Jacques <address@hidden>
 
        * server/Movie.cpp, server/Movie.h, server/Object.h,
        server/font.h, server/morph2.h, server/shape.h,
Index: gnash/libbase/smart_ptr.h
diff -u gnash/libbase/smart_ptr.h:1.2 gnash/libbase/smart_ptr.h:1.3
--- gnash/libbase/smart_ptr.h:1.2       Sun Jan 29 10:35:39 2006
+++ gnash/libbase/smart_ptr.h   Mon Apr 24 23:46:44 2006
@@ -220,6 +220,116 @@
 };
 
 
+
+/// \brief noref_ptr Pointer without ref counting
+/// noref_ptr does not count references; the pointer is deleted when the object
+/// goes out of scope.
+//
+// TODO: noref_ptr<classname> ptr = new classname(); currently throws a 
compiler
+//       error. Figure out why, and fix it!
+//
+// XXX:  When a function returns (by reference) a noref_ptr, if we choose to
+//       assign it like so:
+//         noref_ptr<classname> ptr = someclass.get_classname_norefptr();
+//       Does that mean the ownership of ptr.m_ptr will transfer to ptr?
+
+template<class T>
+    class noref_ptr
+{
+  public:
+    noref_ptr(T* ptr)
+    : m_ptr(ptr)
+    {
+    }
+
+    noref_ptr()
+    : m_ptr(NULL)
+    {
+    }
+
+    noref_ptr(noref_ptr<T>& s)
+    : m_ptr(s.disown())
+    {
+    }
+
+    ~noref_ptr()
+    {
+        delete m_ptr;
+    }
+
+    noref_ptr<T>&
+    disown()
+    {
+        T* tmp = m_ptr;
+        m_ptr  = NULL;
+
+        return tmp;
+    }
+
+    // Transfers "ownwership" of anoter pointer to |this|.
+    noref_ptr<T>&
+    operator=(noref_ptr<T>& s)
+    {
+        delete m_ptr;
+        m_ptr = s.m_ptr;
+
+        return s.disown();
+    }
+
+    noref_ptr<T>&
+    operator=(T* ptr)
+    {
+        delete m_ptr;
+        m_ptr = ptr;
+        return m_ptr;
+    }
+
+    T*
+    operator->() const
+    {
+        assert(m_ptr);
+        return m_ptr;
+    }
+    
+    operator T*() const
+    {
+        return operator->();
+    }
+
+    T*
+    get_ptr() const
+    {
+        return operator->();
+    }
+
+    bool
+    operator==(const noref_ptr<T>& p) const
+    {
+        return m_ptr == p.m_ptr;
+    }
+
+    bool
+    operator!=(const smart_ptr<T>& p) const
+    {
+        return m_ptr != p.m_ptr;
+    }
+
+    bool
+    operator==(T* p) const 
+    {
+        return m_ptr == p;
+    }
+
+    bool
+    operator!=(T* p) const
+    {
+        return m_ptr != p;
+    }
+
+  private:
+    T*  m_ptr;
+};
+
 // Example ref_counted class:
 // 
 #if 0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]