wx/buffer.h \
wx/build.h \
wx/chartype.h \
+ wx/checkeddelete.h \
wx/chkconf.h \
wx/clntdata.h \
wx/cmdargs.h \
wx/ptr_shrd.h \
wx/recguard.h \
wx/regex.h \
+ wx/scopedarray.h \
+ wx/scopedptr.h \
wx/scopeguard.h \
+ wx/sharedptr.h \
wx/snglinst.h \
wx/sstream.h \
wx/stack.h \
wx/buffer.h \
wx/build.h \
wx/chartype.h \
+ wx/checkeddelete.h \
wx/chkconf.h \
wx/clntdata.h \
wx/cmdargs.h \
wx/ptr_shrd.h \
wx/recguard.h \
wx/regex.h \
+ wx/scopedarray.h \
+ wx/scopedptr.h \
wx/scopeguard.h \
+ wx/sharedptr.h \
wx/snglinst.h \
wx/sstream.h \
wx/stack.h \
wx/buffer.h
wx/build.h
wx/chartype.h
+ wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/ptr_shrd.h
wx/recguard.h
wx/regex.h
+ wx/scopedarray.h
+ wx/scopedptr.h
wx/scopeguard.h
+ wx/sharedptr.h
wx/snglinst.h
wx/sstream.h
wx/stack.h
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\include\wx\checkeddelete.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\include\wx\chkconf.h\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\include\wx\scopedarray.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\include\wx\scopedptr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\include\wx\scopeguard.h\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\include\wx\sharedptr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\include\wx\snglinst.h\r
# End Source File\r
# Begin Source File\r
<File\r
RelativePath="..\..\include\wx\chartype.h">\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\checkeddelete.h">\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\chkconf.h">\r
</File>\r
<File\r
RelativePath="..\..\include\wx\regex.h">\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\scopedarray.h">\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\include\wx\scopedptr.h">\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\scopeguard.h">\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\sharedptr.h">\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\snglinst.h">\r
</File>\r
RelativePath="..\..\include\wx\chartype.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\checkeddelete.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\chkconf.h"\r
>\r
RelativePath="..\..\include\wx\regex.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\scopedarray.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\include\wx\scopedptr.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\scopeguard.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\sharedptr.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\snglinst.h"\r
>\r
RelativePath="..\..\include\wx\chartype.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\checkeddelete.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\chkconf.h"\r
>\r
RelativePath="..\..\include\wx\regex.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\scopedarray.h"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\include\wx\scopedptr.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\scopeguard.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\include\wx\sharedptr.h"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\include\wx\snglinst.h"\r
>\r
Linnakangas).
- wxVariant::Unshare allows exclusive allocation of data that must be shared,
if the wxVariantData::Clone function is implemented.
-- Added wxWeakRef<T>, wxScopedPtr<T>, wxScopedArray<T>, wxSharedPtr<T> templates.
+- Added wxWeakRef<T>, wxScopedPtr<T>, wxScopedArray<T>, wxSharedPtr<T> templates
+ and renamed old wx/ptr_{scpd,shrd}.h headers to wx/scoped{ptr,array}.h and
+ wx/sharedptr.h (but old headers are still provided for compatibility).
- Added wxVector<T> class templates
- Added wxON_BLOCK_EXIT_SET() and wxON_BLOCK_EXIT_NULL() to wx/scopeguard.h.
- Added wxEvtHandler::QueueEvent() replacing AddPendingEvent() and
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: wx/checkeddelete.h
+// Purpose: wxCHECKED_DELETE() macro
+// Author: Vadim Zeitlin
+// Created: 2009-02-03
+// RCS-ID: $Id$
+// Copyright: (c) 2002-2009 wxWidgets dev team
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_CHECKEDDELETE_H_
+#define _WX_CHECKEDDELETE_H_
+
+// TODO: provide wxCheckedDelete[Array]() template functions too
+
+// ----------------------------------------------------------------------------
+// wxCHECKED_DELETE and wxCHECKED_DELETE_ARRAY macros
+// ----------------------------------------------------------------------------
+
+/*
+ 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
+
+ do { ... } while ( 0 ) construct is used to have an anonymous scope
+ (otherwise we could have name clashes between different "complete"s) but
+ still force a semicolon after the macro
+*/
+
+#ifdef __WATCOMC__
+ #define wxFOR_ONCE(name) for(int name=0; name<1; name++)
+ #define wxPRE_NO_WARNING_SCOPE(name) wxFOR_ONCE(wxMAKE_UNIQUE_NAME(name))
+ #define wxPOST_NO_WARNING_SCOPE(name)
+#else
+ #define wxPRE_NO_WARNING_SCOPE(name) do
+ #define wxPOST_NO_WARNING_SCOPE(name) while ( wxFalse )
+#endif
+
+#define wxCHECKED_DELETE(ptr) \
+ wxPRE_NO_WARNING_SCOPE(scope_var1) \
+ { \
+ typedef char complete[sizeof(*ptr)]; \
+ delete ptr; \
+ } wxPOST_NO_WARNING_SCOPE(scope_var1)
+
+#define wxCHECKED_DELETE_ARRAY(ptr) \
+ wxPRE_NO_WARNING_SCOPE(scope_var2) \
+ { \
+ typedef char complete[sizeof(*ptr)]; \
+ delete [] ptr; \
+ } wxPOST_NO_WARNING_SCOPE(scope_var2)
+
+
+#endif // _WX_CHECKEDDELETE_H_
+
// For drag operations
void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; }
wxDataObject *GetDataObject() const { return m_dataObject; }
-#endif // wxUSE_DRAG_AND_DROP
// For drop operations
void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; }
size_t GetDataSize() const { return m_dataSize; }
void SetDataBuffer( void* buf ) { m_dataBuffer = buf;}
void *GetDataBuffer() const { return m_dataBuffer; }
+#endif // wxUSE_DRAG_AND_DROP
virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: wx/ptr_scpd.h
-// Purpose: scoped smart pointer class
-// Author: Jesse Lovelace <jllovela@eos.ncsu.edu>
-// Modified by: Vadim Zeitlin to add template wxScopedArray
-// Created: 06/01/02
-// RCS-ID: $Id$
-// Copyright: (c) Jesse Lovelace and original Boost authors (see below)
-// (c) 2009 Vadim Zeitlin
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-// This class closely follows the implementation of the boost
-// library scoped_ptr and is an adaption for c++ macro's in
-// the wxWidgets project. The original authors of the boost
-// scoped_ptr are given below with their respective copyrights.
-
-// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
-// Copyright (c) 2001, 2002 Peter Dimov
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-// See http://www.boost.org/libs/smart_ptr/scoped_ptr.htm for documentation.
-//
-
-#ifndef __WX_SCOPED_POINTER__
-#define __WX_SCOPED_POINTER__
-
-#include "wx/defs.h"
-
-// ----------------------------------------------------------------------------
-// wxScopedPtr: A scoped pointer
-// ----------------------------------------------------------------------------
-
-template <class T>
-class wxScopedPtr
-{
-public:
- typedef T element_type;
-
- wxEXPLICIT wxScopedPtr(T * ptr = NULL) : m_ptr(ptr) { }
-
- ~wxScopedPtr() { delete m_ptr; }
-
- // test for pointer validity: defining conversion to unspecified_bool_type
- // and not more obvious bool to avoid implicit conversions to integer types
- typedef T *(wxScopedPtr<T>::*unspecified_bool_type)() const;
- operator unspecified_bool_type() const
- {
- return m_ptr ? &wxScopedPtr<T>::get : NULL;
- }
-
- void reset(T * ptr = NULL)
- {
- if ( ptr != m_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& other)
- {
- T * const tmp = other.m_ptr;
- other.m_ptr = m_ptr;
- m_ptr = tmp;
- }
-
-private:
- T * m_ptr;
-
- DECLARE_NO_COPY_TEMPLATE_CLASS(wxScopedPtr, T)
-};
-
-// ----------------------------------------------------------------------------
-// wxScopedArray: A scoped array
-// ----------------------------------------------------------------------------
-
-template <class T>
-class wxScopedArray
-{
-public:
- typedef T element_type;
-
- wxEXPLICIT wxScopedArray(T * array = NULL) : m_array(array) { }
-
- ~wxScopedArray() { delete [] m_array; }
-
- // test for pointer validity: defining conversion to unspecified_bool_type
- // and not more obvious bool to avoid implicit conversions to integer types
- typedef T *(wxScopedArray<T>::*unspecified_bool_type)() const;
- operator unspecified_bool_type() const
- {
- return m_array ? &wxScopedArray<T>::get : NULL;
- }
-
- void reset(T *array = NULL)
- {
- if ( array != m_array )
- {
- delete m_array;
- m_array = array;
- }
- }
-
- T& operator[](size_t n) const { return m_array[n]; }
-
- T *get() const { return m_array; }
-
- void swap(wxScopedArray &other)
- {
- T * const tmp = other.m_array;
- other.m_array = m_array;
- m_array = tmp;
- }
-
-private:
- T *m_array;
-
- DECLARE_NO_COPY_TEMPLATE_CLASS(wxScopedArray, T)
-};
-
-// ----------------------------------------------------------------------------
-// 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
-
- do { ... } while ( 0 ) construct is used to have an anonymous scope
- (otherwise we could have name clashes between different "complete"s) but
- still force a semicolon after the macro
-*/
-
-#ifdef __WATCOMC__
- #define wxFOR_ONCE(name) for(int name=0; name<1; name++)
- #define wxPRE_NO_WARNING_SCOPE(name) wxFOR_ONCE(wxMAKE_UNIQUE_NAME(name))
- #define wxPOST_NO_WARNING_SCOPE(name)
-#else
- #define wxPRE_NO_WARNING_SCOPE(name) do
- #define wxPOST_NO_WARNING_SCOPE(name) while ( wxFalse )
-#endif
-
-#define wxCHECKED_DELETE(ptr) \
- wxPRE_NO_WARNING_SCOPE(scope_var1) \
- { \
- typedef char complete[sizeof(*ptr)]; \
- delete ptr; \
- } wxPOST_NO_WARNING_SCOPE(scope_var1)
-
-#define wxCHECKED_DELETE_ARRAY(ptr) \
- wxPRE_NO_WARNING_SCOPE(scope_var2) \
- { \
- typedef char complete[sizeof(*ptr)]; \
- delete [] ptr; \
- } wxPOST_NO_WARNING_SCOPE(scope_var2)
-
-/* 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. */
-
-#define wxDECLARE_SCOPED_PTR(T, name) \
-class name \
-{ \
-private: \
- T * m_ptr; \
- \
- name(name const &); \
- name & operator=(name const &); \
- \
-public: \
- wxEXPLICIT name(T * ptr = NULL) \
- : m_ptr(ptr) { } \
- \
- ~name(); \
- \
- 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(name & ot) \
- { \
- T * tmp = ot.m_ptr; \
- ot.m_ptr = m_ptr; \
- m_ptr = tmp; \
- } \
-};
-
-#define wxDEFINE_SCOPED_PTR(T, name)\
-name::~name() \
-{ \
- wxCHECKED_DELETE(m_ptr); \
-}
-
-// this macro can be used for the most common case when you want to declare and
-// define the scoped pointer at the same time and want to use the standard
-// naming convention: auto pointer to Foo is called FooPtr
-#define wxDEFINE_SCOPED_PTR_TYPE(T) \
- wxDECLARE_SCOPED_PTR(T, T ## Ptr) \
- wxDEFINE_SCOPED_PTR(T, T ## Ptr)
-
-// the same but for arrays instead of simple pointers
-#define wxDECLARE_SCOPED_ARRAY(T, name)\
-class name \
-{ \
-private: \
- T * m_ptr; \
- name(name const &); \
- name & operator=(name const &); \
- \
-public: \
- wxEXPLICIT name(T * p = NULL) : m_ptr(p) \
- {} \
- \
- ~name(); \
- void reset(T * p = NULL); \
- \
- T & operator[](long int i) const\
- { \
- wxASSERT(m_ptr != NULL); \
- wxASSERT(i >= 0); \
- return m_ptr[i]; \
- } \
- \
- T * get() const \
- { \
- return m_ptr; \
- } \
- \
- void swap(name & ot) \
- { \
- T * tmp = ot.m_ptr; \
- ot.m_ptr = m_ptr; \
- m_ptr = tmp; \
- } \
-};
-
-#define wxDEFINE_SCOPED_ARRAY(T, name) \
-name::~name() \
-{ \
- wxCHECKED_DELETE_ARRAY(m_ptr); \
-} \
-void name::reset(T * p){ \
- if (m_ptr != p) \
- { \
- wxCHECKED_DELETE_ARRAY(m_ptr); \
- m_ptr = p; \
- } \
-}
-
-// ----------------------------------------------------------------------------
-// "Tied" scoped pointer: same as normal one but also sets the value of
-// some other variable to the pointer value
-// ----------------------------------------------------------------------------
-
-#define wxDEFINE_TIED_SCOPED_PTR_TYPE(T) \
- wxDEFINE_SCOPED_PTR_TYPE(T) \
- class T ## TiedPtr : public T ## Ptr \
- { \
- public: \
- T ## TiedPtr(T **pp, T *p) \
- : T ## Ptr(p), m_pp(pp) \
- { \
- m_pOld = *pp; \
- *pp = p; \
- } \
- \
- ~ T ## TiedPtr() \
- { \
- *m_pp = m_pOld; \
- } \
- \
- private: \
- T **m_pp; \
- T *m_pOld; \
- };
-
-#endif // __WX_SCOPED_POINTER__
-
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: wx/ptr_shrd.h
-// Purpose: Shared pointer based on the counted_ptr<> template, which
-// is in the public domain
-// Author: Robert Roebling, Yonat Sharon
-// RCS-ID: $Id: object.h 47254 2007-07-09 10:09:52Z VS $
-// Copyright: Robert Roebling
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef _WX_SHARED_PTRH__
-#define _WX_SHARED_PTRH__
-
-#include "wx/defs.h"
-#include "wx/atomic.h"
-
-// ----------------------------------------------------------------------------
-// wxSharedPtr: A smart pointer with non-intrusive reference counting.
-// ----------------------------------------------------------------------------
-
-template <class T>
-class wxSharedPtr
-{
-public:
- typedef T element_type;
-
- wxEXPLICIT wxSharedPtr( T* ptr = NULL )
- : m_ref(NULL)
- {
- if (ptr)
- m_ref = new reftype(ptr);
- }
-
- ~wxSharedPtr() { Release(); }
- wxSharedPtr(const wxSharedPtr& tocopy) { Acquire(tocopy.m_ref); }
-
- wxSharedPtr& operator=( const wxSharedPtr& tocopy )
- {
- if (this != &tocopy)
- {
- Release();
- Acquire(tocopy.m_ref);
- }
- return *this;
- }
-
- wxSharedPtr& operator=( T* ptr )
- {
- if (get() != ptr)
- {
- Release();
- if (ptr)
- m_ref = new reftype(ptr);
- }
- return *this;
- }
-
- // test for pointer validity: defining conversion to unspecified_bool_type
- // and not more obvious bool to avoid implicit conversions to integer types
- typedef T *(wxSharedPtr<T>::*unspecified_bool_type)() const;
- operator unspecified_bool_type() const
- {
- if (m_ref && m_ref->m_ptr)
- return &wxSharedPtr<T>::get;
- else
- return NULL;
- }
-
- T& operator*() const
- {
- wxASSERT(m_ref != NULL);
- wxASSERT(m_ref->m_ptr != NULL);
- return *(m_ref->m_ptr);
- }
-
- T* operator->() const
- {
- wxASSERT(m_ref != NULL);
- wxASSERT(m_ref->m_ptr != NULL);
- return m_ref->m_ptr;
- }
-
- T* get() const
- {
- return m_ref ? m_ref->m_ptr : NULL;
- }
-
- void reset( T* ptr = NULL )
- {
- Release();
- if (ptr)
- m_ref = new reftype(ptr);
- }
-
- bool unique() const { return (m_ref ? m_ref->m_count == 1 : true); }
- long use_count() const { return (m_ref ? (long)m_ref->m_count : 0); }
-
-private:
-
- struct reftype
- {
- reftype( T* ptr = NULL, unsigned count = 1 ) : m_ptr(ptr), m_count(count) {}
- T* m_ptr;
- wxAtomicInt m_count;
- }* m_ref;
-
- void Acquire(reftype* ref)
- {
- m_ref = ref;
- if (ref)
- wxAtomicInc( ref->m_count );
- }
-
- void Release()
- {
- if (m_ref)
- {
- wxAtomicDec( m_ref->m_count );
- if (m_ref->m_count == 0)
- {
- delete m_ref->m_ptr;
- delete m_ref;
- }
- m_ref = NULL;
- }
- }
-};
-
-template <class T, class U>
-bool operator == (wxSharedPtr<T> const &a, wxSharedPtr<U> const &b )
-{
- return a.get() == b.get();
-}
-
-template <class T, class U>
-bool operator != (wxSharedPtr<T> const &a, wxSharedPtr<U> const &b )
-{
- return a.get() != b.get();
-}
-
-
-
-#endif // _WX_SHARED_PTRH__
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/scopedarray.h
+// Purpose: scoped smart pointer class
+// Author: Vadim Zeitlin
+// Created: 2009-02-03
+// RCS-ID: $Id$
+// Copyright: (c) Jesse Lovelace and original Boost authors (see below)
+// (c) 2009 Vadim Zeitlin
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_SCOPED_ARRAY_H_
+#define _WX_SCOPED_ARRAY_H_
+
+#include "wx/defs.h"
+#include "wx/checkeddelete.h"
+
+// ----------------------------------------------------------------------------
+// wxScopedArray: A scoped array
+// ----------------------------------------------------------------------------
+
+template <class T>
+class wxScopedArray
+{
+public:
+ typedef T element_type;
+
+ wxEXPLICIT wxScopedArray(T * array = NULL) : m_array(array) { }
+
+ ~wxScopedArray() { delete [] m_array; }
+
+ // test for pointer validity: defining conversion to unspecified_bool_type
+ // and not more obvious bool to avoid implicit conversions to integer types
+ typedef T *(wxScopedArray<T>::*unspecified_bool_type)() const;
+ operator unspecified_bool_type() const
+ {
+ return m_array ? &wxScopedArray<T>::get : NULL;
+ }
+
+ void reset(T *array = NULL)
+ {
+ if ( array != m_array )
+ {
+ delete m_array;
+ m_array = array;
+ }
+ }
+
+ T& operator[](size_t n) const { return m_array[n]; }
+
+ T *get() const { return m_array; }
+
+ void swap(wxScopedArray &other)
+ {
+ T * const tmp = other.m_array;
+ other.m_array = m_array;
+ m_array = tmp;
+ }
+
+private:
+ T *m_array;
+
+ DECLARE_NO_COPY_TEMPLATE_CLASS(wxScopedArray, T)
+};
+
+// ----------------------------------------------------------------------------
+// old macro based implementation
+// ----------------------------------------------------------------------------
+
+// the same but for arrays instead of simple pointers
+#define wxDECLARE_SCOPED_ARRAY(T, name)\
+class name \
+{ \
+private: \
+ T * m_ptr; \
+ name(name const &); \
+ name & operator=(name const &); \
+ \
+public: \
+ wxEXPLICIT name(T * p = NULL) : m_ptr(p) \
+ {} \
+ \
+ ~name(); \
+ void reset(T * p = NULL); \
+ \
+ T & operator[](long int i) const\
+ { \
+ wxASSERT(m_ptr != NULL); \
+ wxASSERT(i >= 0); \
+ return m_ptr[i]; \
+ } \
+ \
+ T * get() const \
+ { \
+ return m_ptr; \
+ } \
+ \
+ void swap(name & ot) \
+ { \
+ T * tmp = ot.m_ptr; \
+ ot.m_ptr = m_ptr; \
+ m_ptr = tmp; \
+ } \
+};
+
+#define wxDEFINE_SCOPED_ARRAY(T, name) \
+name::~name() \
+{ \
+ wxCHECKED_DELETE_ARRAY(m_ptr); \
+} \
+void name::reset(T * p){ \
+ if (m_ptr != p) \
+ { \
+ wxCHECKED_DELETE_ARRAY(m_ptr); \
+ m_ptr = p; \
+ } \
+}
+
+#endif // _WX_SCOPED_ARRAY_H_
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/scopedptr.h
+// Purpose: scoped smart pointer class
+// Author: Jesse Lovelace <jllovela@eos.ncsu.edu>
+// Created: 06/01/02
+// RCS-ID: $Id$
+// Copyright: (c) Jesse Lovelace and original Boost authors (see below)
+// (c) 2009 Vadim Zeitlin
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// This class closely follows the implementation of the boost
+// library scoped_ptr and is an adaption for c++ macro's in
+// the wxWidgets project. The original authors of the boost
+// scoped_ptr are given below with their respective copyrights.
+
+// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
+// Copyright (c) 2001, 2002 Peter Dimov
+//
+// Permission to copy, use, modify, sell and distribute this software
+// is granted provided this copyright notice appears in all copies.
+// This software is provided "as is" without express or implied
+// warranty, and with no claim as to its suitability for any purpose.
+//
+// See http://www.boost.org/libs/smart_ptr/scoped_ptr.htm for documentation.
+//
+
+#ifndef _WX_SCOPED_PTR_H_
+#define _WX_SCOPED_PTR_H_
+
+#include "wx/defs.h"
+#include "wx/checkeddelete.h"
+
+// ----------------------------------------------------------------------------
+// wxScopedPtr: A scoped pointer
+// ----------------------------------------------------------------------------
+
+template <class T>
+class wxScopedPtr
+{
+public:
+ typedef T element_type;
+
+ wxEXPLICIT wxScopedPtr(T * ptr = NULL) : m_ptr(ptr) { }
+
+ ~wxScopedPtr() { delete m_ptr; }
+
+ // test for pointer validity: defining conversion to unspecified_bool_type
+ // and not more obvious bool to avoid implicit conversions to integer types
+ typedef T *(wxScopedPtr<T>::*unspecified_bool_type)() const;
+ operator unspecified_bool_type() const
+ {
+ return m_ptr ? &wxScopedPtr<T>::get : NULL;
+ }
+
+ void reset(T * ptr = NULL)
+ {
+ if ( ptr != m_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& other)
+ {
+ T * const tmp = other.m_ptr;
+ other.m_ptr = m_ptr;
+ m_ptr = tmp;
+ }
+
+private:
+ T * m_ptr;
+
+ DECLARE_NO_COPY_TEMPLATE_CLASS(wxScopedPtr, T)
+};
+
+// ----------------------------------------------------------------------------
+// old macro based implementation
+// ----------------------------------------------------------------------------
+
+/* 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. */
+
+#define wxDECLARE_SCOPED_PTR(T, name) \
+class name \
+{ \
+private: \
+ T * m_ptr; \
+ \
+ name(name const &); \
+ name & operator=(name const &); \
+ \
+public: \
+ wxEXPLICIT name(T * ptr = NULL) \
+ : m_ptr(ptr) { } \
+ \
+ ~name(); \
+ \
+ 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(name & ot) \
+ { \
+ T * tmp = ot.m_ptr; \
+ ot.m_ptr = m_ptr; \
+ m_ptr = tmp; \
+ } \
+};
+
+#define wxDEFINE_SCOPED_PTR(T, name)\
+name::~name() \
+{ \
+ wxCHECKED_DELETE(m_ptr); \
+}
+
+// this macro can be used for the most common case when you want to declare and
+// define the scoped pointer at the same time and want to use the standard
+// naming convention: auto pointer to Foo is called FooPtr
+#define wxDEFINE_SCOPED_PTR_TYPE(T) \
+ wxDECLARE_SCOPED_PTR(T, T ## Ptr) \
+ wxDEFINE_SCOPED_PTR(T, T ## Ptr)
+
+// ----------------------------------------------------------------------------
+// "Tied" scoped pointer: same as normal one but also sets the value of
+// some other variable to the pointer value
+// ----------------------------------------------------------------------------
+
+#define wxDEFINE_TIED_SCOPED_PTR_TYPE(T) \
+ wxDEFINE_SCOPED_PTR_TYPE(T) \
+ class T ## TiedPtr : public T ## Ptr \
+ { \
+ public: \
+ T ## TiedPtr(T **pp, T *p) \
+ : T ## Ptr(p), m_pp(pp) \
+ { \
+ m_pOld = *pp; \
+ *pp = p; \
+ } \
+ \
+ ~ T ## TiedPtr() \
+ { \
+ *m_pp = m_pOld; \
+ } \
+ \
+ private: \
+ T **m_pp; \
+ T *m_pOld; \
+ };
+
+#endif // _WX_SCOPED_PTR_H_
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/sharedptr.h
+// Purpose: Shared pointer based on the counted_ptr<> template, which
+// is in the public domain
+// Author: Robert Roebling, Yonat Sharon
+// RCS-ID: $Id: object.h 47254 2007-07-09 10:09:52Z VS $
+// Copyright: Robert Roebling
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_SHAREDPTR_H_
+#define _WX_SHAREDPTR_H_
+
+#include "wx/defs.h"
+#include "wx/atomic.h"
+
+// ----------------------------------------------------------------------------
+// wxSharedPtr: A smart pointer with non-intrusive reference counting.
+// ----------------------------------------------------------------------------
+
+template <class T>
+class wxSharedPtr
+{
+public:
+ typedef T element_type;
+
+ wxEXPLICIT wxSharedPtr( T* ptr = NULL )
+ : m_ref(NULL)
+ {
+ if (ptr)
+ m_ref = new reftype(ptr);
+ }
+
+ ~wxSharedPtr() { Release(); }
+ wxSharedPtr(const wxSharedPtr& tocopy) { Acquire(tocopy.m_ref); }
+
+ wxSharedPtr& operator=( const wxSharedPtr& tocopy )
+ {
+ if (this != &tocopy)
+ {
+ Release();
+ Acquire(tocopy.m_ref);
+ }
+ return *this;
+ }
+
+ wxSharedPtr& operator=( T* ptr )
+ {
+ if (get() != ptr)
+ {
+ Release();
+ if (ptr)
+ m_ref = new reftype(ptr);
+ }
+ return *this;
+ }
+
+ // test for pointer validity: defining conversion to unspecified_bool_type
+ // and not more obvious bool to avoid implicit conversions to integer types
+ typedef T *(wxSharedPtr<T>::*unspecified_bool_type)() const;
+ operator unspecified_bool_type() const
+ {
+ if (m_ref && m_ref->m_ptr)
+ return &wxSharedPtr<T>::get;
+ else
+ return NULL;
+ }
+
+ T& operator*() const
+ {
+ wxASSERT(m_ref != NULL);
+ wxASSERT(m_ref->m_ptr != NULL);
+ return *(m_ref->m_ptr);
+ }
+
+ T* operator->() const
+ {
+ wxASSERT(m_ref != NULL);
+ wxASSERT(m_ref->m_ptr != NULL);
+ return m_ref->m_ptr;
+ }
+
+ T* get() const
+ {
+ return m_ref ? m_ref->m_ptr : NULL;
+ }
+
+ void reset( T* ptr = NULL )
+ {
+ Release();
+ if (ptr)
+ m_ref = new reftype(ptr);
+ }
+
+ bool unique() const { return (m_ref ? m_ref->m_count == 1 : true); }
+ long use_count() const { return (m_ref ? (long)m_ref->m_count : 0); }
+
+private:
+
+ struct reftype
+ {
+ reftype( T* ptr = NULL, unsigned count = 1 ) : m_ptr(ptr), m_count(count) {}
+ T* m_ptr;
+ wxAtomicInt m_count;
+ }* m_ref;
+
+ void Acquire(reftype* ref)
+ {
+ m_ref = ref;
+ if (ref)
+ wxAtomicInc( ref->m_count );
+ }
+
+ void Release()
+ {
+ if (m_ref)
+ {
+ wxAtomicDec( m_ref->m_count );
+ if (m_ref->m_count == 0)
+ {
+ delete m_ref->m_ptr;
+ delete m_ref;
+ }
+ m_ref = NULL;
+ }
+ }
+};
+
+template <class T, class U>
+bool operator == (wxSharedPtr<T> const &a, wxSharedPtr<U> const &b )
+{
+ return a.get() == b.get();
+}
+
+template <class T, class U>
+bool operator != (wxSharedPtr<T> const &a, wxSharedPtr<U> const &b )
+{
+ return a.get() != b.get();
+}
+
+#endif // _WX_SHAREDPTR_H_
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: ptr_scpd.h
-// Purpose: interface of wxScopedPtr
-// Author: wxWidgets team
-// RCS-ID: $Id$
-// Licence: wxWindows license
-/////////////////////////////////////////////////////////////////////////////
-
-/**
- @class wxScopedPtr
-
- This is a simple scoped smart pointer implementation that is similar to
- the Boost smart pointers (see http://www.boost.org) 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 wxScopedPtr<T>.
-
- 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 @c std::auto_ptr<> in so far as it doesn't provide copy constructor
- nor assignment operator. This limits what you can do with it but is much less
- surprizing than the "destructive copy" behaviour of the standard class.
-
- @b Example:
-
- Below is an example of using a wxWidgets scoped smart pointer and pointer array.
-
- @code
- class MyClass{ ... };
-
- // declare a smart pointer to a MyClass called wxMyClassPtr
- wxDECLARE_SCOPED_PTR(MyClass, wxMyClassPtr)
- // declare a smart pointer to an array of chars
- wxDECLARE_SCOPED_ARRAY(char, wxCharArray)
-
- ...
-
- // define the first pointer class, must be complete
- wxDEFINE_SCOPED_PTR(MyClass, wxMyClassPtr)
- // define the second pointer class
- wxDEFINE_SCOPED_ARRAY(char, wxCharArray)
-
- // create an object with a new pointer to MyClass
- wxMyClassPtr theObj(new MyClass());
- // reset the pointer (deletes the previous one)
- theObj.reset(new MyClass());
-
- // access the pointer
- theObj->MyFunc();
-
- // create an object with a new array of chars
- wxCharArray theCharObj(new char[100]);
-
- // access the array
- theCharObj[0] = "!";
- @endcode
-
- @section scopedptr_newpointers Declaring new smart pointer types
-
- To declare the smart pointer class @c CLASSNAME containing pointes to
- a (possibly incomplete) type @c TYPE you should use
- @code
- wxDECLARE_SCOPED_PTR( TYPE, // type of the values
- CLASSNAME ); // name of the class
- @endcode
- And later, when @c TYPE is fully defined, you must also use
- @code
- wxDEFINE_SCOPED_PTR( TYPE, CLASSNAME );
- @endcode
- to implement the scoped pointer class.
-
- The first argument of these macro is the pointer type, the second is the name
- of the new smart pointer class being created. Below we will use wxScopedPtr
- to represent the scoped pointer class, but the user may create the class with
- any legal name.
-
- Alternatively, if you don't have to separate the point of declaration and
- definition of this class and if you accept the standard naming convention,
- that is that the scoped pointer for the class @c Foo is called @c FooPtr,
- you can use a single macro which replaces two macros above:
- @code
- wxDEFINE_SCOPED_PTR_TYPE( TYPE );
- @endcode
- Once again, in this cass @c CLASSNAME will be @c TYPEPtr.
-
- @library{wxbase}
- @category{smartpointers}
-
- @see wxScopedArray
-*/
-class wxScopedPtr
-{
-public:
- /**
- Creates the smart pointer with the given pointer or none if @NULL.
-
- On compilers that support it, this uses the explicit keyword.
- */
- explicit wxScopedPtr(type* T = NULL);
-
- /**
- Destructor frees the pointer help by this object if it is not @NULL.
- */
- ~wxScopedPtr();
-
- /**
- This operator gets the pointer stored in the smart pointer or returns
- @NULL if there is none.
- */
- const T* get();
-
- /**
- This operator works like the standard C++ pointer operator to return the object
- being pointed to by the pointer.
-
- @note
- If the pointer is @NULL or invalid this will crash.
- */
- const T& operator *();
-
- /**
- This operator works like the standard C++ pointer operator to return the pointer
- in the smart pointer or @NULL if it is empty.
- */
- const T* operator ->();
-
- /**
- Returns the currently hold pointer and resets the smart pointer object to
- @NULL.
-
- @remarks
- After a call to this function the caller is responsible for deleting the
- pointer.
- */
- T* release();
-
- /**
- Deletes the currently held pointer and sets it to @a p or to @NULL if no
- arguments are specified.
-
- @note
- This function does check to make sure that the pointer you are assigning
- is not the same pointer that is already stored.
- */
- reset(T* p = NULL);
-
- /**
- Swap the pointer inside the smart pointer with @a other. The pointer being
- swapped must be of the same type (hence the same class name).
- */
- swap(wxScopedPtr& other);
-};
-
-
-
-/**
- @class wxScopedArray
-
- This is a simple scoped smart pointer array implementation that is similar to
- the Boost smart pointers (see http://www.boost.org/) but rewritten to
- use macros instead.
-
- @b Example:
-
- Below is an example of using a wxWidgets scoped smart pointer and pointer array.
-
- @code
- class MyClass { ... };
-
- // declare a smart pointer to a MyClass called wxMyClassPtr
- wxDECLARE_SCOPED_PTR(MyClass, wxMyClassPtr)
- // declare a smart pointer to an array of chars
- wxDECLARE_SCOPED_ARRAY(char, wxCharArray)
-
- ...
-
- // define the first pointer class, must be complete
- wxDEFINE_SCOPED_PTR(MyClass, wxMyClassPtr)
- // define the second pointer class
- wxDEFINE_SCOPED_ARRAY(char, wxCharArray)
-
- // create an object with a new pointer to MyClass
- wxMyClassPtr theObj(new MyClass());
- // reset the pointer (deletes the previous one)
- theObj.reset(new MyClass());
-
- // access the pointer
- theObj->MyFunc();
-
- // create an object with a new array of chars
- wxCharArray theCharObj(new char[100]);
-
- // access the array
- theCharObj[0] = "!";
- @endcode
-
- <b>Declaring new smart pointer types:</b>
- @code
- wxDECLAR_SCOPED_ARRAY( TYPE, // type of the values
- CLASSNAME ); // name of the class
- @endcode
-
- A smart pointer holds a pointer to an object (which must be complete when
- wxDEFINE_SCOPED_ARRAY() is called).
-
- The memory used by the object is deleted when the smart pointer goes out of
- scope. The first argument of the macro is the pointer type, the second is the
- name of the new smart pointer class being created. Below we will use wxScopedArray
- to represent the scoped pointer array class, but the user may create the class with
- any legal name.
-
- @library{wxbase}
- @category{smartpointers}
-
- @see wxScopedPtr
-*/
-class wxScopedArray
-{
-public:
- /**
- Creates the smart pointer with the given pointer or none if @NULL. On
- compilers that support it, this uses the explicit keyword.
- */
- wxScopedArray(type* T = NULL);
-
- /**
- This operator gets the pointer stored in the smart pointer or returns @NULL if
- there is none.
- */
- const T* get();
-
- /**
- This operator acts like the standard [] indexing operator for C++ arrays. The
- function does not do bounds checking.
- */
- const T& operator [](long int i);
-
- /**
- Deletes the currently held pointer and sets it to 'p' or to @NULL if no
- arguments are specified. This function does check to make sure that the
- pointer you are assigning is not the same pointer that is already stored.
- */
- reset(T* p = NULL);
-
- /**
- Swap the pointer inside the smart pointer with @a ot. The pointer being swapped
- must be of the same type (hence the same class name).
- */
- swap(wxScopedPtr& ot);
-};
-
-
-
-/**
- @class wxScopedTiedPtr
-
- This is a variation on the topic of wxScopedPtr. This class is also a smart pointer
- but in addition it "ties" the pointer value to another variable. In other words,
- during the life time of this class the value of that variable is set to be the same
- as the value of the pointer itself and it is reset to its old value when the object
- is destroyed. This class is especially useful when converting the existing code
- (which may already store the pointers value in some variable) to the smart pointers.
-
- @library{wxbase}
- @category{smartpointers}
-*/
-class wxScopedTiedPtr : public wxScopedPtr
-{
-public:
- /**
- Constructor creates a smart pointer initialized with @a ptr and stores
- @a ptr in the location specified by @a ppTie which must not be @NULL.
- */
- wxScopedTiedPtr(T** ppTie, T* ptr);
-
- /**
- Destructor frees the pointer help by this object and restores the value
- stored at the tied location (as specified in the @ref wxScopedTiedPtr() constructor)
- to the old value.
-
- @warning
- This location may now contain an uninitialized value if it hadn't been
- initialized previously, in particular don't count on it magically being @NULL!
- */
- ~wxScopedTiedPtr();
-};
-
-
-
-/**
-
- A scoped pointer template class.
-
- It is the template version of the old-style @ref wxScopedPtr "scoped pointer macros".
-
- Notice that objects of this class intentionally cannot be copied.
-
- @library{wxbase}
- @category{smartpointers}
-
- @see wxSharedPtr<T>, wxWeakRef<T>
-*/
-template<typename T>
-class wxScopedPtr<T>
-{
-public:
- /**
- Constructor takes ownership of the pointer.
-
- @param ptr
- Pointer allocated with @c new or @NULL.
- */
- wxScopedPtr(T* ptr = NULL);
-
- /**
- Destructor deletes the pointer.
- */
- ~wxScopedPtr();
-
- /**
- Returns pointer to object or @NULL.
- */
- T* get() const;
-
- /**
- Conversion to a boolean expression (in a variant which is not
- convertible to anything but a boolean expression).
-
- If this class contains a valid pointer it will return @true, if it contains
- a @NULL pointer it will return @false.
- */
- operator unspecified_bool_type() const;
-
- /**
- Returns a reference to the object.
-
- @note
- If the internal pointer is @NULL this method will cause an assert
- in debug mode.
- */
- T operator*() const;
-
- /**
- Returns pointer to object. If the pointer is @NULL this method will
- cause an assert in debug mode.
- */
- T* operator->() const;
-
- /**
- Releases the current pointer and returns it.
-
- @remarks
- Afterwards the caller is responsible for deleting
- the data contained in the scoped pointer before.
- */
- T* release();
-
- /**
- Reset pointer to the value of @a ptr.
- The previous pointer will be deleted.
- */
- void reset(T* ptr = NULL);
-
- /**
- Swaps pointers.
- */
- void swap(wxScopedPtr<T>& ot);
-};
-
-/**
- A scoped array template class.
-
- This class is similar to boost scoped_array class:
- http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/scoped_array.htm
-
- Notice that objects of this class intentionally cannot be copied.
-
- @library{wxbase}
- @category{smartpointers}
- */
-template <class T>
-class wxScopedArray
-{
-public:
- /// The type of the array elements.
- typedef T element_type;
-
- /**
- Constructor takes ownership of the given array.
-
- If @a array is @NULL, reset() must presumably be called later.
-
- @param array
- An array allocated using @c new[] or @NULL.
- */
- explicit wxScopedArray(T * array = NULL);
-
- /// Destructor destroy the array.
- ~wxScopedArray();
-
- /**
- Conversion to a boolean expression (in a variant which is not
- convertible to anything but a boolean expression).
-
- If this class contains a valid array it will return @true, if it contains
- a @NULL pointer it will return @false.
- */
- operator unspecified_bool_type() const;
-
- /**
- Change the array pointer stored.
-
- The previously stored array is deleted.
-
- @param array
- An array allocated using @c new[] or @NULL.
- */
- void reset(T *array = NULL);
-
- /**
- Return the n-th element of the array.
-
- Must not be called if the array has no valid pointer.
- */
- T& operator[](size_t n) const;
-
- /**
- Return the array pointer.
-
- The returned pointer may be @NULL. It must not be deleted by the
- caller, call @c reset(NULL) instead.
- */
- T *get() const;
-
- /// Swaps the contents of this array with another one.
- void swap(wxScopedArray &other);
-};
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: ptr_shrd.h
-// Purpose: interface of wxSharedPtr<T>
-// Author: wxWidgets team
-// RCS-ID: $Id$
-// Licence: wxWindows license
-/////////////////////////////////////////////////////////////////////////////
-
-/**
-
- A smart pointer with non-intrusive reference counting. It is modeled after
- @c boost::shared_ptr<> and can be used with STL containers and wxVector<T> -
- unlike @c std::auto_ptr<> and wxScopedPtr<T>.
-
- @library{wxbase}
- @category{smartpointers}
-
- @see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
-*/
-
-template<typename T>
-class wxSharedPtr<T>
-{
-public:
- /**
- Constructor.
-
- Creates shared pointer from the raw pointer @a ptr and takes ownership
- of it.
- */
- wxEXPLICIT wxSharedPtr(T* ptr = NULL);
-
- /**
- Copy constructor.
- */
- wxSharedPtr(const wxSharedPtr<T>& tocopy);
-
- /**
- Destructor.
- */
- ~wxSharedPtr();
-
- /**
- Returns pointer to its object or @NULL.
- */
- T* get() const;
-
- /**
- Conversion to a boolean expression (in a variant which is not
- convertable to anything but a boolean expression).
-
- If this class contains a valid pointer it will return @true, if it contains
- a @NULL pointer it will return @false.
- */
- operator unspecified_bool_type() const;
-
- /**
- Returns a reference to the object.
-
- If the internal pointer is @NULL this method will cause an assert in debug mode.
- */
- T operator*() const;
-
- /**
- Returns pointer to its object or @NULL.
- */
- T* operator->() const;
-
- /**
- Assignment operator.
-
- Releases any previously held pointer and creates a reference to @a ptr.
- */
- wxSharedPtr<T>& operator=(T* ptr);
-
- /**
- Assignment operator.
-
- Releases any previously held pointer and creates a reference to the
- same object as @a topcopy.
- */
- wxSharedPtr<T>& operator=(const wxSharedPtr<T>& tocopy);
-
- /**
- Reset pointer to @a ptr.
-
- If the reference count of the previously owned pointer was 1 it will be deleted.
- */
- void reset(T* ptr = NULL);
-
- /**
- Returns @true if this is the only pointer pointing to its object.
- */
- bool unique() const;
-
- /**
- Returns the number of pointers pointing to its object.
- */
- long use_count() const;
-};
-
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/scopedarray.h
+// Purpose: interface of wxScopedArray
+// Author: wxWidgets team
+// RCS-ID: $Id$
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ @class wxScopedArray
+
+ This is a simple scoped smart pointer array implementation that is similar to
+ the Boost smart pointers (see http://www.boost.org/) but rewritten to
+ use macros instead.
+
+ @b Example:
+
+ Below is an example of using a wxWidgets scoped smart pointer and pointer array.
+
+ @code
+ class MyClass { ... };
+
+ // declare a smart pointer to a MyClass called wxMyClassPtr
+ wxDECLARE_SCOPED_PTR(MyClass, wxMyClassPtr)
+ // declare a smart pointer to an array of chars
+ wxDECLARE_SCOPED_ARRAY(char, wxCharArray)
+
+ ...
+
+ // define the first pointer class, must be complete
+ wxDEFINE_SCOPED_PTR(MyClass, wxMyClassPtr)
+ // define the second pointer class
+ wxDEFINE_SCOPED_ARRAY(char, wxCharArray)
+
+ // create an object with a new pointer to MyClass
+ wxMyClassPtr theObj(new MyClass());
+ // reset the pointer (deletes the previous one)
+ theObj.reset(new MyClass());
+
+ // access the pointer
+ theObj->MyFunc();
+
+ // create an object with a new array of chars
+ wxCharArray theCharObj(new char[100]);
+
+ // access the array
+ theCharObj[0] = "!";
+ @endcode
+
+ <b>Declaring new smart pointer types:</b>
+ @code
+ wxDECLAR_SCOPED_ARRAY( TYPE, // type of the values
+ CLASSNAME ); // name of the class
+ @endcode
+
+ A smart pointer holds a pointer to an object (which must be complete when
+ wxDEFINE_SCOPED_ARRAY() is called).
+
+ The memory used by the object is deleted when the smart pointer goes out of
+ scope. The first argument of the macro is the pointer type, the second is the
+ name of the new smart pointer class being created. Below we will use wxScopedArray
+ to represent the scoped pointer array class, but the user may create the class with
+ any legal name.
+
+ @library{wxbase}
+ @category{smartpointers}
+
+ @see wxScopedPtr
+*/
+class wxScopedArray
+{
+public:
+ /**
+ Creates the smart pointer with the given pointer or none if @NULL. On
+ compilers that support it, this uses the explicit keyword.
+ */
+ wxScopedArray(type* T = NULL);
+
+ /**
+ This operator gets the pointer stored in the smart pointer or returns @NULL if
+ there is none.
+ */
+ const T* get();
+
+ /**
+ This operator acts like the standard [] indexing operator for C++ arrays. The
+ function does not do bounds checking.
+ */
+ const T& operator [](long int i);
+
+ /**
+ Deletes the currently held pointer and sets it to 'p' or to @NULL if no
+ arguments are specified. This function does check to make sure that the
+ pointer you are assigning is not the same pointer that is already stored.
+ */
+ reset(T* p = NULL);
+
+ /**
+ Swap the pointer inside the smart pointer with @a ot. The pointer being swapped
+ must be of the same type (hence the same class name).
+ */
+ swap(wxScopedArray& ot);
+};
+
+/**
+ A scoped array template class.
+
+ This class is similar to boost scoped_array class:
+ http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/scoped_array.htm
+
+ Notice that objects of this class intentionally cannot be copied.
+
+ @library{wxbase}
+ @category{smartpointers}
+ */
+template <class T>
+class wxScopedArray
+{
+public:
+ /// The type of the array elements.
+ typedef T element_type;
+
+ /**
+ Constructor takes ownership of the given array.
+
+ If @a array is @NULL, reset() must presumably be called later.
+
+ @param array
+ An array allocated using @c new[] or @NULL.
+ */
+ explicit wxScopedArray(T * array = NULL);
+
+ /// Destructor destroy the array.
+ ~wxScopedArray();
+
+ /**
+ Conversion to a boolean expression (in a variant which is not
+ convertible to anything but a boolean expression).
+
+ If this class contains a valid array it will return @true, if it contains
+ a @NULL pointer it will return @false.
+ */
+ operator unspecified_bool_type() const;
+
+ /**
+ Change the array pointer stored.
+
+ The previously stored array is deleted.
+
+ @param array
+ An array allocated using @c new[] or @NULL.
+ */
+ void reset(T *array = NULL);
+
+ /**
+ Return the n-th element of the array.
+
+ Must not be called if the array has no valid pointer.
+ */
+ T& operator[](size_t n) const;
+
+ /**
+ Return the array pointer.
+
+ The returned pointer may be @NULL. It must not be deleted by the
+ caller, call @c reset(NULL) instead.
+ */
+ T *get() const;
+
+ /// Swaps the contents of this array with another one.
+ void swap(wxScopedArray &other);
+};
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/scopedptr.h
+// Purpose: interface of wxScopedPtr
+// Author: wxWidgets team
+// RCS-ID: $Id$
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ @class wxScopedPtr
+
+ This is a simple scoped smart pointer implementation that is similar to
+ the Boost smart pointers (see http://www.boost.org) 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 wxScopedPtr<T>.
+
+ 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 @c std::auto_ptr<> in so far as it doesn't provide copy constructor
+ nor assignment operator. This limits what you can do with it but is much less
+ surprizing than the "destructive copy" behaviour of the standard class.
+
+ @b Example:
+
+ Below is an example of using a wxWidgets scoped smart pointer and pointer array.
+
+ @code
+ class MyClass{ ... };
+
+ // declare a smart pointer to a MyClass called wxMyClassPtr
+ wxDECLARE_SCOPED_PTR(MyClass, wxMyClassPtr)
+ // declare a smart pointer to an array of chars
+ wxDECLARE_SCOPED_ARRAY(char, wxCharArray)
+
+ ...
+
+ // define the first pointer class, must be complete
+ wxDEFINE_SCOPED_PTR(MyClass, wxMyClassPtr)
+ // define the second pointer class
+ wxDEFINE_SCOPED_ARRAY(char, wxCharArray)
+
+ // create an object with a new pointer to MyClass
+ wxMyClassPtr theObj(new MyClass());
+ // reset the pointer (deletes the previous one)
+ theObj.reset(new MyClass());
+
+ // access the pointer
+ theObj->MyFunc();
+
+ // create an object with a new array of chars
+ wxCharArray theCharObj(new char[100]);
+
+ // access the array
+ theCharObj[0] = "!";
+ @endcode
+
+ @section scopedptr_newpointers Declaring new smart pointer types
+
+ To declare the smart pointer class @c CLASSNAME containing pointes to
+ a (possibly incomplete) type @c TYPE you should use
+ @code
+ wxDECLARE_SCOPED_PTR( TYPE, // type of the values
+ CLASSNAME ); // name of the class
+ @endcode
+ And later, when @c TYPE is fully defined, you must also use
+ @code
+ wxDEFINE_SCOPED_PTR( TYPE, CLASSNAME );
+ @endcode
+ to implement the scoped pointer class.
+
+ The first argument of these macro is the pointer type, the second is the name
+ of the new smart pointer class being created. Below we will use wxScopedPtr
+ to represent the scoped pointer class, but the user may create the class with
+ any legal name.
+
+ Alternatively, if you don't have to separate the point of declaration and
+ definition of this class and if you accept the standard naming convention,
+ that is that the scoped pointer for the class @c Foo is called @c FooPtr,
+ you can use a single macro which replaces two macros above:
+ @code
+ wxDEFINE_SCOPED_PTR_TYPE( TYPE );
+ @endcode
+ Once again, in this cass @c CLASSNAME will be @c TYPEPtr.
+
+ @library{wxbase}
+ @category{smartpointers}
+
+ @see wxScopedArray
+*/
+class wxScopedPtr
+{
+public:
+ /**
+ Creates the smart pointer with the given pointer or none if @NULL.
+
+ On compilers that support it, this uses the explicit keyword.
+ */
+ explicit wxScopedPtr(type* T = NULL);
+
+ /**
+ Destructor frees the pointer help by this object if it is not @NULL.
+ */
+ ~wxScopedPtr();
+
+ /**
+ This operator gets the pointer stored in the smart pointer or returns
+ @NULL if there is none.
+ */
+ const T* get();
+
+ /**
+ This operator works like the standard C++ pointer operator to return the object
+ being pointed to by the pointer.
+
+ @note
+ If the pointer is @NULL or invalid this will crash.
+ */
+ const T& operator *();
+
+ /**
+ This operator works like the standard C++ pointer operator to return the pointer
+ in the smart pointer or @NULL if it is empty.
+ */
+ const T* operator ->();
+
+ /**
+ Returns the currently hold pointer and resets the smart pointer object to
+ @NULL.
+
+ @remarks
+ After a call to this function the caller is responsible for deleting the
+ pointer.
+ */
+ T* release();
+
+ /**
+ Deletes the currently held pointer and sets it to @a p or to @NULL if no
+ arguments are specified.
+
+ @note
+ This function does check to make sure that the pointer you are assigning
+ is not the same pointer that is already stored.
+ */
+ reset(T* p = NULL);
+
+ /**
+ Swap the pointer inside the smart pointer with @a other. The pointer being
+ swapped must be of the same type (hence the same class name).
+ */
+ swap(wxScopedPtr& other);
+};
+
+/**
+ @class wxScopedTiedPtr
+
+ This is a variation on the topic of wxScopedPtr. This class is also a smart pointer
+ but in addition it "ties" the pointer value to another variable. In other words,
+ during the life time of this class the value of that variable is set to be the same
+ as the value of the pointer itself and it is reset to its old value when the object
+ is destroyed. This class is especially useful when converting the existing code
+ (which may already store the pointers value in some variable) to the smart pointers.
+
+ @library{wxbase}
+ @category{smartpointers}
+*/
+class wxScopedTiedPtr : public wxScopedPtr
+{
+public:
+ /**
+ Constructor creates a smart pointer initialized with @a ptr and stores
+ @a ptr in the location specified by @a ppTie which must not be @NULL.
+ */
+ wxScopedTiedPtr(T** ppTie, T* ptr);
+
+ /**
+ Destructor frees the pointer help by this object and restores the value
+ stored at the tied location (as specified in the @ref wxScopedTiedPtr() constructor)
+ to the old value.
+
+ @warning
+ This location may now contain an uninitialized value if it hadn't been
+ initialized previously, in particular don't count on it magically being @NULL!
+ */
+ ~wxScopedTiedPtr();
+};
+
+
+
+/**
+ A scoped pointer template class.
+
+ It is the template version of the old-style @ref wxScopedPtr "scoped pointer macros".
+
+ Notice that objects of this class intentionally cannot be copied.
+
+ @library{wxbase}
+ @category{smartpointers}
+
+ @see wxSharedPtr<T>, wxWeakRef<T>
+*/
+template<typename T>
+class wxScopedPtr<T>
+{
+public:
+ /**
+ Constructor takes ownership of the pointer.
+
+ @param ptr
+ Pointer allocated with @c new or @NULL.
+ */
+ wxScopedPtr(T* ptr = NULL);
+
+ /**
+ Destructor deletes the pointer.
+ */
+ ~wxScopedPtr();
+
+ /**
+ Returns pointer to object or @NULL.
+ */
+ T* get() const;
+
+ /**
+ Conversion to a boolean expression (in a variant which is not
+ convertible to anything but a boolean expression).
+
+ If this class contains a valid pointer it will return @true, if it contains
+ a @NULL pointer it will return @false.
+ */
+ operator unspecified_bool_type() const;
+
+ /**
+ Returns a reference to the object.
+
+ @note
+ If the internal pointer is @NULL this method will cause an assert
+ in debug mode.
+ */
+ T operator*() const;
+
+ /**
+ Returns pointer to object. If the pointer is @NULL this method will
+ cause an assert in debug mode.
+ */
+ T* operator->() const;
+
+ /**
+ Releases the current pointer and returns it.
+
+ @remarks
+ Afterwards the caller is responsible for deleting
+ the data contained in the scoped pointer before.
+ */
+ T* release();
+
+ /**
+ Reset pointer to the value of @a ptr.
+ The previous pointer will be deleted.
+ */
+ void reset(T* ptr = NULL);
+
+ /**
+ Swaps pointers.
+ */
+ void swap(wxScopedPtr<T>& ot);
+};
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: sharedptr.h
+// Purpose: interface of wxSharedPtr<T>
+// Author: wxWidgets team
+// RCS-ID: $Id$
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ A smart pointer with non-intrusive reference counting.
+
+ It is modeled after @c boost::shared_ptr<> and can be used with STL
+ containers and wxVector<T> unlike @c std::auto_ptr<> and wxScopedPtr<T>.
+
+ @library{wxbase}
+ @category{smartpointers}
+
+ @see wxScopedPtr<T>, wxWeakRef<T>, wxObjectDataPtr<T>
+*/
+template<typename T>
+class wxSharedPtr<T>
+{
+public:
+ /**
+ Constructor.
+
+ Creates shared pointer from the raw pointer @a ptr and takes ownership
+ of it.
+ */
+ wxEXPLICIT wxSharedPtr(T* ptr = NULL);
+
+ /**
+ Copy constructor.
+ */
+ wxSharedPtr(const wxSharedPtr<T>& tocopy);
+
+ /**
+ Destructor.
+ */
+ ~wxSharedPtr();
+
+ /**
+ Returns pointer to its object or @NULL.
+ */
+ T* get() const;
+
+ /**
+ Conversion to a boolean expression (in a variant which is not
+ convertible to anything but a boolean expression).
+
+ If this class contains a valid pointer it will return @true, if it contains
+ a @NULL pointer it will return @false.
+ */
+ operator unspecified_bool_type() const;
+
+ /**
+ Returns a reference to the object.
+
+ If the internal pointer is @NULL this method will cause an assert in debug mode.
+ */
+ T operator*() const;
+
+ /**
+ Returns pointer to its object or @NULL.
+ */
+ T* operator->() const;
+
+ /**
+ Assignment operator.
+
+ Releases any previously held pointer and creates a reference to @a ptr.
+ */
+ wxSharedPtr<T>& operator=(T* ptr);
+
+ /**
+ Assignment operator.
+
+ Releases any previously held pointer and creates a reference to the
+ same object as @a topcopy.
+ */
+ wxSharedPtr<T>& operator=(const wxSharedPtr<T>& tocopy);
+
+ /**
+ Reset pointer to @a ptr.
+
+ If the reference count of the previously owned pointer was 1 it will be deleted.
+ */
+ void reset(T* ptr = NULL);
+
+ /**
+ Returns @true if this is the only pointer pointing to its object.
+ */
+ bool unique() const;
+
+ /**
+ Returns the number of pointers pointing to its object.
+ */
+ long use_count() const;
+};
+
#include "wx/evtloop.h"
#include "wx/filename.h"
#include "wx/msgout.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/tokenzr.h"
#include "wx/thread.h"
#include "wx/filename.h"
#include "wx/stdpaths.h"
#include "wx/vector.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedarray.h"
+#include "wx/scopedptr.h"
#if wxUSE_STD_IOSTREAM
#include "wx/ioswrap.h"
#include "wx/thread.h"
#if wxUSE_BASE
- #include "wx/ptr_scpd.h"
+ #include "wx/scopedptr.h"
wxDECLARE_SCOPED_PTR(wxEvent, wxEventPtr)
wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr)
#ifndef WX_PRECOMP
#endif
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
wxDEFINE_SCOPED_PTR_TYPE(wxFSFile)
wxDEFINE_SCOPED_PTR_TYPE(wxInputStream)
#include <stdlib.h>
#include <string.h>
#include "wx/gifdecod.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/scopeguard.h"
#include "wx/init.h"
#include "wx/thread.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/except.h"
#if defined(__WXMSW__) && defined(__WXDEBUG__)
#include "wx/tokenzr.h"
#include "wx/fontmap.h"
#include "wx/encconv.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/apptrait.h"
#include "wx/stdpaths.h"
#include "wx/hashset.h"
#include "wx/apptrait.h"
#include "wx/renderer.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#if wxUSE_DYNLIB_CLASS
#include "wx/dynlib.h"
#include "wx/buffer.h"
#include "wx/datetime.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/filename.h"
#include "wx/thread.h"
#include "wx/datstrm.h"
#include "wx/zstream.h"
#include "wx/mstream.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/wfstream.h"
#include "zlib.h"
#include "wx/dataobj.h"
#endif
-#include "wx/ptr_scpd.h"
+#include "wx/scopedarray.h"
#include "wx/scopeguard.h"
#include "wx/gtk/private.h"
-wxDECLARE_SCOPED_ARRAY(wxDataFormat, wxDataFormatArray)
-wxDEFINE_SCOPED_ARRAY(wxDataFormat, wxDataFormatArray)
+typedef wxScopedArray<wxDataFormat> wxDataFormatArray;
// ----------------------------------------------------------------------------
// data
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include <gtk/gtk.h>
#include "wx/dataobj.h"
#endif
-#include "wx/ptr_scpd.h"
+#include "wx/scopedarray.h"
+
+typedef wxScopedArray<wxDataFormat> wxDataFormatScopedArray;
#ifdef __VMS__
#pragma message disable nosimpint
return AddData( data );
}
-wxDECLARE_SCOPED_ARRAY( wxDataFormat, wxDataFormatScopedArray )
-wxDEFINE_SCOPED_ARRAY( wxDataFormat, wxDataFormatScopedArray )
-
#if wxCHECK_LESSTIF()
void wxClipboardCallback( Widget xwidget, int* data_id,
int* priv, int* WXUNUSED(reason) )
#include "wx/msw/private.h"
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#if defined(__SMARTPHONE__) && defined(__WXWINCE__)
#include "wx/msw/wince/resources.h"
#include "wx/evtloop.h"
#include "wx/thread.h"
#include "wx/except.h"
-#include "wx/ptr_scpd.h"
#include "wx/msw/private.h"
#if wxUSE_GUI
#include "wx/ownerdrw.h"
#endif
-#include "wx/ptr_scpd.h"
+#include "wx/scopedarray.h"
#include "wx/msw/private.h"
#include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
#include "wx/artprov.h"
#include "wx/sysopt.h"
#include "wx/dcclient.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedarray.h"
#include "wx/msw/private.h"
#include "wx/msw/dc.h"
#include "wx/os2/private.h"
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#define wxDIALOG_DEFAULT_X 300
#define wxDIALOG_DEFAULT_Y 300
#include "wx/evtloop.h"
#include "wx/tooltip.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/os2/private.h"
#include "wx/os2/private/timer.h" // for wxTimerProc
#endif
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
// ----------------------------------------------------------------------------
// wxWin macros
#include "wx/tooltip.h"
#include "wx/except.h"
-#include "wx/ptr_scpd.h"
#if wxUSE_THREADS
#include "wx/thread.h"
#include "wx/datstrm.h"
#include "wx/zstream.h"
#include "wx/strconv.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "expat.h" // from Expat
wx/buffer.h
wx/build.h
wx/chartype.h
+wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/ptr_shrd.h
wx/recguard.h
wx/regex.h
+wx/scopedarray.h
+wx/scopedptr.h
wx/scopeguard.h
+wx/sharedptr.h
wx/snglinst.h
wx/sstream.h
wx/stack.h
wx/meta/if.h
wx/meta/int2type.h
wx/meta/movable.h
-wx/private/fdiodispatcher.h
-wx/private/selectdispatcher.h
wx/unix/app.h
wx/unix/apptbase.h
wx/unix/apptrait.h
wx/buffer.h
wx/build.h
wx/chartype.h
+wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/ptr_shrd.h
wx/recguard.h
wx/regex.h
+wx/scopedarray.h
+wx/scopedptr.h
wx/scopeguard.h
+wx/sharedptr.h
wx/snglinst.h
wx/sstream.h
wx/stack.h
wx/meta/if.h
wx/meta/int2type.h
wx/meta/movable.h
-wx/private/fdiodispatcher.h
-wx/private/selectdispatcher.h
wx/unix/app.h
wx/unix/apptbase.h
wx/unix/apptrait.h
wx/buffer.h
wx/build.h
wx/chartype.h
+wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/ptr_shrd.h
wx/recguard.h
wx/regex.h
+wx/scopedarray.h
+wx/scopedptr.h
wx/scopeguard.h
+wx/sharedptr.h
wx/snglinst.h
wx/sstream.h
wx/stack.h
wx/meta/if.h
wx/meta/int2type.h
wx/meta/movable.h
-wx/private/fdiodispatcher.h
-wx/private/selectdispatcher.h
wx/unix/app.h
wx/unix/apptbase.h
wx/unix/apptrait.h