]> git.saurik.com Git - wxWidgets.git/commitdiff
Templatize wxScopedPtr
authorRobert Roebling <robert@roebling.de>
Mon, 7 Jan 2008 12:09:22 +0000 (12:09 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 7 Jan 2008 12:09:22 +0000 (12:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51070 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/category.tex
docs/latex/wx/classes.tex
docs/latex/wx/scpdptr.tex
docs/latex/wx/sharedptr.tex [new file with mode: 0644]
include/wx/ptr_scpd.h

index 81cad80b67abb752e2c351cc85fb8aa1205d8973..1af5871f2af25daadc6404e7380a87466c3871ae 100644 (file)
@@ -382,8 +382,9 @@ wxWidgets provides a few smart pointer class templates.
 
 \twocolwidtha{6cm}
 \begin{twocollist}\itemsep=0pt
-\twocolitem{\helpref{wxWeakRef<T>}{wxweakref}}{A weak reference}
 \twocolitem{\helpref{wxObjectDataPtr<T>}{wxobjectdataptr}}{A shared pointer using intrusive reference counting}
+\twocolitem{\helpref{wxScopedPtr<T>}{wxscopedptrtemplate}}{A scoped pointer}
+\twocolitem{\helpref{wxWeakRef<T>}{wxweakref}}{A weak reference}
 \end{twocollist}
 
 {\large {\bf Run-time class information system}}
index b15b8c5ad3b17eee18deea6294bd47baaf5d1238..055a5b330945cb9abc86fd258c7dbcaf376dd1fa 100644 (file)
 \input sashwin.tex
 \input scpdarry.tex
 \input scpdptr.tex
+\input scopedptr.tex
 \input screendc.tex
 \input scrolbar.tex
 \input scrolwin.tex
index 1a5b04bc25dc23968360bc2ce61cb07fdcc09812..47c36fcf5047e35ded4e18c818d238110032eb39 100644 (file)
@@ -4,6 +4,9 @@ This is a simple scoped smart pointer implementation that is similar to
 the \urlref{Boost}{http://www.boost.org/} smart pointers but rewritten to
 use macros instead.
 
+Since wxWidgets 2.9.0 there is also a templated version of this class
+with the same name. See \helpref{wxScopedPtr<T>}{wxscopedptrtemplate}.
+
 A smart pointer holds a pointer to an object. The memory used by the object is
 deleted when the smart pointer goes out of scope. This class is different from
 the \texttt{std::auto\_ptr<>} in so far as it doesn't provide copy constructor
diff --git a/docs/latex/wx/sharedptr.tex b/docs/latex/wx/sharedptr.tex
new file mode 100644 (file)
index 0000000..2a4c4cb
--- /dev/null
@@ -0,0 +1,71 @@
+\section{\class{wxSharedPtr<T>}}\label{wxsharedptr}
+
+A smart pointer with non-intrusive reference counting.
+
+\wxheading{Derived from}
+
+No base class
+
+\wxheading{Include files}
+
+<ptr\_shrd.h>
+
+\wxheading{Data structures}
+
+{\small \begin{verbatim}
+typedef T element\_type
+\end{verbatim}}
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+
+\membersection{wxSharedPtr<T>::wxSharedPtr<T>}\label{wxsharedptrwxsharedptr}
+
+\func{wxEXPLICIT}{wxSharedPtr<T>}{\param{T* }{ptr = NULL}}
+
+\func{}{wxSharedPtr<T>}{\param{const wxSharedPtr<T>\& }{tocopy}}
+
+Constructors.
+
+\membersection{wxSharedPtr<T>::\destruct{wxSharedPtr<T>}}\label{wxsharedptrdtor}
+
+\func{}{\destruct{wxSharedPtr<T>}}{\void}
+
+Destructor.
+
+\membersection{wxSharedPtr<T>::get}\label{wxsharedptrget}
+
+\constfunc{T*}{get}{\void}
+
+Returns pointer to its object or NULL.
+
+\membersection{wxSharedPtr<T>::operator*}\label{wxsharedptroperatorptrt}
+
+\constfunc{T\&}{operator*}{\void}
+
+Returns pointer to its object or NULL.
+
+\membersection{wxSharedPtr<T>::operator->}\label{wxsharedptroperatorderef}
+
+\constfunc{T*}{operator->}{\void}
+
+Returns pointer to its object or NULL.
+
+\membersection{wxSharedPtr<T>::operator=}\label{wxsharedptroperatorassign}
+
+\func{wxSharedPtr<T>\& operator}{operator=}{\param{const wxSharedPtr<T>\& }{tocopy}}
+
+Assignment operator.
+
+\membersection{wxSharedPtr<T>::unique}\label{wxsharedptrunique}
+
+\constfunc{bool}{unique}{\void}
+
+Returns true if this is the only pointer pointing to its object.
+
+\membersection{wxSharedPtr<T>::use\_count}\label{wxsharedptruse\_count}
+
+\constfunc{long}{use\_count}{\void}
+
+Returns the number of pointers pointing to its object.
+
index 2ebb6a67322782e0f4fcc5cddb44f508b880d1f3..100e6bdd0a97aee09e9aaebbe06fcc288843904d 100644 (file)
 
 #include "wx/defs.h"
 
+// ----------------------------------------------------------------------------
+// wxScopedPtr: A scoped pointer 
+// ----------------------------------------------------------------------------
+
+template <class T> 
+class wxScopedPtr
+{                                   
+private:                            
+    T * m_ptr;                      
+                                    
+    wxScopedPtr(wxScopedPtr const &);             
+    wxScopedPtr & operator=(wxScopedPtr const &); 
+                                    
+public:                             
+    typedef T element_type;
+    
+    wxEXPLICIT wxScopedPtr(T * ptr = NULL) 
+    : m_ptr(ptr) { }                
+                                    
+    ~wxScopedPtr()
+    {
+       if (m_ptr)
+           delete m_ptr;
+    }
+                                    
+    void reset(T * ptr = NULL)      
+    {                               
+        if (m_ptr != ptr)           
+        {                           
+            delete m_ptr;           
+            m_ptr = ptr;            
+        }                           
+    }                               
+                                    
+    T *release()                    
+    {                               
+        T *ptr = m_ptr;             
+        m_ptr = NULL;               
+        return ptr;                 
+    }                               
+                                    
+    T & operator*() const           
+    {                               
+        wxASSERT(m_ptr != NULL);    
+        return *m_ptr;              
+    }                               
+                                    
+    T * operator->() const          
+    {                               
+        wxASSERT(m_ptr != NULL);    
+        return m_ptr;               
+    }                               
+                                    
+    T * get() const                 
+    {                               
+        return m_ptr;               
+    }                               
+                                    
+    void swap(wxScopedPtr & ot)            
+    {                               
+        T * tmp = ot.m_ptr;         
+        ot.m_ptr = m_ptr;           
+        m_ptr = tmp;                
+    }                               
+};
+
+// ----------------------------------------------------------------------------
+// old macro based implementation
+// ----------------------------------------------------------------------------
+
 /*
    checked deleters are used to make sure that the type being deleted is really
    a complete type.: otherwise sizeof() would result in a compile-time error
         delete [] ptr;                                                        \
     } wxPOST_NO_WARNING_SCOPE(scope_var2)
 
-/* These scoped pointers are *not* assignable and cannot be used
-   within a container.  Look for wxDECLARE_SHARED_PTR for this
-   functionality.
-
-   In addition, the type being used *must* be complete at the time
+/* The type being used *must* be complete at the time
    that wxDEFINE_SCOPED_* is called or a compiler error will result.
    This is because the class checks for the completeness of the type
-   being used.
-*/
-
+   being used. */
 
 #define wxDECLARE_SCOPED_PTR(T, name) \
 class name                          \