diff --git a/Makefile.in b/Makefile.in
index c6ee928f4e..ad2b1ce288 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -318,6 +318,7 @@ ALL_BASE_HEADERS = \
wx/buffer.h \
wx/build.h \
wx/chartype.h \
+ wx/checkeddelete.h \
wx/chkconf.h \
wx/clntdata.h \
wx/cmdargs.h \
@@ -391,7 +392,10 @@ ALL_BASE_HEADERS = \
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 \
@@ -471,6 +475,7 @@ ALL_PORTS_BASE_HEADERS = \
wx/buffer.h \
wx/build.h \
wx/chartype.h \
+ wx/checkeddelete.h \
wx/chkconf.h \
wx/clntdata.h \
wx/cmdargs.h \
@@ -544,7 +549,10 @@ ALL_PORTS_BASE_HEADERS = \
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 \
diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl
index a68221526b..450ca53e93 100644
--- a/build/bakefiles/files.bkl
+++ b/build/bakefiles/files.bkl
@@ -399,6 +399,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/buffer.h
wx/build.h
wx/chartype.h
+ wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
@@ -472,7 +473,10 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
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
diff --git a/build/msw/wx_base.dsp b/build/msw/wx_base.dsp
index c80d3e2168..bc94929fdb 100644
--- a/build/msw/wx_base.dsp
+++ b/build/msw/wx_base.dsp
@@ -1071,6 +1071,10 @@ SOURCE=..\..\include\wx\chartype.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\wx\checkeddelete.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\wx\chkconf.h
# End Source File
# Begin Source File
@@ -1371,10 +1375,22 @@ SOURCE=..\..\include\wx\regex.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\wx\scopedarray.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\wx\scopedptr.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\wx\scopeguard.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\wx\sharedptr.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\wx\snglinst.h
# End Source File
# Begin Source File
diff --git a/build/msw/wx_vc7_base.vcproj b/build/msw/wx_vc7_base.vcproj
index 3c4d781e0f..f8994ddb02 100644
--- a/build/msw/wx_vc7_base.vcproj
+++ b/build/msw/wx_vc7_base.vcproj
@@ -1221,6 +1221,9 @@
+
+
@@ -1446,9 +1449,18 @@
+
+
+
+
+
+
diff --git a/build/msw/wx_vc8_base.vcproj b/build/msw/wx_vc8_base.vcproj
index a9ae6c9abc..f2a8489fd4 100644
--- a/build/msw/wx_vc8_base.vcproj
+++ b/build/msw/wx_vc8_base.vcproj
@@ -1651,6 +1651,10 @@
RelativePath="..\..\include\wx\chartype.h"
>
+
+
@@ -1951,10 +1955,22 @@
RelativePath="..\..\include\wx\regex.h"
>
+
+
+
+
+
+
diff --git a/build/msw/wx_vc9_base.vcproj b/build/msw/wx_vc9_base.vcproj
index c8a2fe2b8b..5e214ecae5 100644
--- a/build/msw/wx_vc9_base.vcproj
+++ b/build/msw/wx_vc9_base.vcproj
@@ -1647,6 +1647,10 @@
RelativePath="..\..\include\wx\chartype.h"
>
+
+
@@ -1947,10 +1951,22 @@
RelativePath="..\..\include\wx\regex.h"
>
+
+
+
+
+
+
diff --git a/docs/changes.txt b/docs/changes.txt
index 62aa60f58c..24dcd34498 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -320,7 +320,9 @@ All:
Linnakangas).
- wxVariant::Unshare allows exclusive allocation of data that must be shared,
if the wxVariantData::Clone function is implemented.
-- Added wxWeakRef, wxScopedPtr, wxScopedArray, wxSharedPtr templates.
+- Added wxWeakRef, wxScopedPtr, wxScopedArray, wxSharedPtr 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 class templates
- Added wxON_BLOCK_EXIT_SET() and wxON_BLOCK_EXIT_NULL() to wx/scopeguard.h.
- Added wxEvtHandler::QueueEvent() replacing AddPendingEvent() and
diff --git a/include/wx/checkeddelete.h b/include/wx/checkeddelete.h
new file mode 100644
index 0000000000..a9e14c3a2e
--- /dev/null
+++ b/include/wx/checkeddelete.h
@@ -0,0 +1,54 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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_
+
diff --git a/include/wx/dataview.h b/include/wx/dataview.h
index 2ced284014..901e3ca068 100644
--- a/include/wx/dataview.h
+++ b/include/wx/dataview.h
@@ -791,7 +791,6 @@ public:
// 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; }
@@ -800,6 +799,7 @@ public:
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); }
diff --git a/include/wx/scopedarray.h b/include/wx/scopedarray.h
new file mode 100644
index 0000000000..4175fcee62
--- /dev/null
+++ b/include/wx/scopedarray.h
@@ -0,0 +1,120 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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 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::*unspecified_bool_type)() const;
+ operator unspecified_bool_type() const
+ {
+ return m_array ? &wxScopedArray::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_
+
diff --git a/include/wx/ptr_scpd.h b/include/wx/scopedptr.h
similarity index 61%
rename from include/wx/ptr_scpd.h
rename to include/wx/scopedptr.h
index ffbb01105d..a27b8dbd6b 100644
--- a/include/wx/ptr_scpd.h
+++ b/include/wx/scopedptr.h
@@ -1,8 +1,7 @@
/////////////////////////////////////////////////////////////////////////////
-// Name: wx/ptr_scpd.h
+// Name: wx/scopedptr.h
// Purpose: scoped smart pointer class
// Author: Jesse Lovelace
-// 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)
@@ -26,10 +25,11 @@
// See http://www.boost.org/libs/smart_ptr/scoped_ptr.htm for documentation.
//
-#ifndef __WX_SCOPED_POINTER__
-#define __WX_SCOPED_POINTER__
+#ifndef _WX_SCOPED_PTR_H_
+#define _WX_SCOPED_PTR_H_
#include "wx/defs.h"
+#include "wx/checkeddelete.h"
// ----------------------------------------------------------------------------
// wxScopedPtr: A scoped pointer
@@ -99,90 +99,10 @@ private:
DECLARE_NO_COPY_TEMPLATE_CLASS(wxScopedPtr, T)
};
-// ----------------------------------------------------------------------------
-// wxScopedArray: A scoped array
-// ----------------------------------------------------------------------------
-
-template
-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::*unspecified_bool_type)() const;
- operator unspecified_bool_type() const
- {
- return m_array ? &wxScopedArray::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
@@ -257,55 +177,6 @@ name::~name() \
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
@@ -333,5 +204,5 @@ void name::reset(T * p){ \
T *m_pOld; \
};
-#endif // __WX_SCOPED_POINTER__
+#endif // _WX_SCOPED_PTR_H_
diff --git a/include/wx/ptr_shrd.h b/include/wx/sharedptr.h
similarity index 77%
rename from include/wx/ptr_shrd.h
rename to include/wx/sharedptr.h
index 71492d9754..5bfd215136 100644
--- a/include/wx/ptr_shrd.h
+++ b/include/wx/sharedptr.h
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
-// Name: wx/ptr_shrd.h
+// Name: wx/sharedptr.h
// Purpose: Shared pointer based on the counted_ptr<> template, which
// is in the public domain
// Author: Robert Roebling, Yonat Sharon
@@ -8,8 +8,8 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_SHARED_PTRH__
-#define _WX_SHARED_PTRH__
+#ifndef _WX_SHAREDPTR_H_
+#define _WX_SHAREDPTR_H_
#include "wx/defs.h"
#include "wx/atomic.h"
@@ -18,25 +18,25 @@
// wxSharedPtr: A smart pointer with non-intrusive reference counting.
// ----------------------------------------------------------------------------
-template
+template
class wxSharedPtr
{
public:
typedef T element_type;
wxEXPLICIT wxSharedPtr( T* ptr = NULL )
- : m_ref(NULL)
- {
- if (ptr)
- m_ref = new reftype(ptr);
+ : 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)
+ if (this != &tocopy)
{
Release();
Acquire(tocopy.m_ref);
@@ -46,11 +46,11 @@ public:
wxSharedPtr& operator=( T* ptr )
{
- if (get() != ptr)
+ if (get() != ptr)
{
Release();
- if (ptr)
- m_ref = new reftype(ptr);
+ if (ptr)
+ m_ref = new reftype(ptr);
}
return *this;
}
@@ -67,56 +67,56 @@ public:
}
T& operator*() const
- {
- wxASSERT(m_ref != NULL);
- wxASSERT(m_ref->m_ptr != NULL);
+ {
+ 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);
+ {
+ 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;
+
+ T* get() const
+ {
+ return m_ref ? m_ref->m_ptr : NULL;
}
-
+
void reset( T* ptr = NULL )
{
Release();
- if (ptr)
- m_ref = new reftype(ptr);
+ 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
+ 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)
+ void Acquire(reftype* ref)
{
m_ref = ref;
- if (ref)
+ if (ref)
wxAtomicInc( ref->m_count );
}
void Release()
{
- if (m_ref)
+ if (m_ref)
{
wxAtomicDec( m_ref->m_count );
- if (m_ref->m_count == 0)
+ if (m_ref->m_count == 0)
{
delete m_ref->m_ptr;
delete m_ref;
@@ -138,6 +138,4 @@ bool operator != (wxSharedPtr const &a, wxSharedPtr const &b )
return a.get() != b.get();
}
-
-
-#endif // _WX_SHARED_PTRH__
+#endif // _WX_SHAREDPTR_H_
diff --git a/interface/wx/scopedarray.h b/interface/wx/scopedarray.h
new file mode 100644
index 0000000000..1582f3c05d
--- /dev/null
+++ b/interface/wx/scopedarray.h
@@ -0,0 +1,172 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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
+
+ Declaring new smart pointer types:
+ @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 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);
+};
diff --git a/interface/wx/ptr_scpd.h b/interface/wx/scopedptr.h
similarity index 63%
rename from interface/wx/ptr_scpd.h
rename to interface/wx/scopedptr.h
index 7e0caa3a69..53d1eb4181 100644
--- a/interface/wx/ptr_scpd.h
+++ b/interface/wx/scopedptr.h
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
-// Name: ptr_scpd.h
+// Name: wx/scopedptr.h
// Purpose: interface of wxScopedPtr
// Author: wxWidgets team
// RCS-ID: $Id$
@@ -152,106 +152,6 @@ public:
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
-
- Declaring new smart pointer types:
- @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
@@ -289,7 +189,6 @@ public:
/**
-
A scoped pointer template class.
It is the template version of the old-style @ref wxScopedPtr "scoped pointer macros".
@@ -368,71 +267,3 @@ public:
void swap(wxScopedPtr& 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 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);
-};
diff --git a/interface/wx/ptr_shrd.h b/interface/wx/sharedptr.h
similarity index 87%
rename from interface/wx/ptr_shrd.h
rename to interface/wx/sharedptr.h
index 718e452a52..7e7f43d032 100644
--- a/interface/wx/ptr_shrd.h
+++ b/interface/wx/sharedptr.h
@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
-// Name: ptr_shrd.h
+// Name: sharedptr.h
// Purpose: interface of wxSharedPtr
// Author: wxWidgets team
// RCS-ID: $Id$
@@ -7,17 +7,16 @@
/////////////////////////////////////////////////////////////////////////////
/**
+ A smart pointer with non-intrusive reference counting.
- 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 -
- unlike @c std::auto_ptr<> and wxScopedPtr.
+ It is modeled after @c boost::shared_ptr<> and can be used with STL
+ containers and wxVector unlike @c std::auto_ptr<> and wxScopedPtr.
@library{wxbase}
@category{smartpointers}
@see wxScopedPtr, wxWeakRef, wxObjectDataPtr
*/
-
template
class wxSharedPtr
{
@@ -47,7 +46,7 @@ public:
/**
Conversion to a boolean expression (in a variant which is not
- convertable to anything but a boolean expression).
+ 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.
diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp
index 740deebb2b..30c7f093b2 100644
--- a/src/common/appbase.cpp
+++ b/src/common/appbase.cpp
@@ -42,7 +42,7 @@
#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"
diff --git a/src/common/docview.cpp b/src/common/docview.cpp
index 9c5118b3c1..dc27049995 100644
--- a/src/common/docview.cpp
+++ b/src/common/docview.cpp
@@ -58,7 +58,8 @@
#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"
diff --git a/src/common/event.cpp b/src/common/event.cpp
index 6a878fd460..a3cce6f3f3 100644
--- a/src/common/event.cpp
+++ b/src/common/event.cpp
@@ -47,7 +47,7 @@
#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)
diff --git a/src/common/fs_filter.cpp b/src/common/fs_filter.cpp
index 621fed3a23..628a34af0e 100644
--- a/src/common/fs_filter.cpp
+++ b/src/common/fs_filter.cpp
@@ -20,7 +20,7 @@
#ifndef WX_PRECOMP
#endif
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
wxDEFINE_SCOPED_PTR_TYPE(wxFSFile)
wxDEFINE_SCOPED_PTR_TYPE(wxInputStream)
diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp
index 0a2dad2724..fb55baac1b 100644
--- a/src/common/gifdecod.cpp
+++ b/src/common/gifdecod.cpp
@@ -24,7 +24,7 @@
#include
#include
#include "wx/gifdecod.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include "wx/scopeguard.h"
diff --git a/src/common/init.cpp b/src/common/init.cpp
index d9d3cf0dc7..91e0abaf70 100644
--- a/src/common/init.cpp
+++ b/src/common/init.cpp
@@ -34,7 +34,7 @@
#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__)
diff --git a/src/common/intl.cpp b/src/common/intl.cpp
index d0a11eac2f..2284a72490 100644
--- a/src/common/intl.cpp
+++ b/src/common/intl.cpp
@@ -66,7 +66,7 @@
#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"
diff --git a/src/common/rendcmn.cpp b/src/common/rendcmn.cpp
index b44fcf3a75..1206b78fa0 100644
--- a/src/common/rendcmn.cpp
+++ b/src/common/rendcmn.cpp
@@ -32,7 +32,7 @@
#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"
diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp
index 7eb827582e..033c34cf09 100644
--- a/src/common/tarstrm.cpp
+++ b/src/common/tarstrm.cpp
@@ -26,7 +26,7 @@
#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"
diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp
index 0bb02d568d..8461c74422 100644
--- a/src/common/zipstrm.cpp
+++ b/src/common/zipstrm.cpp
@@ -28,7 +28,7 @@
#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"
diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp
index 15ffd8be44..3ab24136a8 100644
--- a/src/gtk/clipbrd.cpp
+++ b/src/gtk/clipbrd.cpp
@@ -29,13 +29,12 @@
#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 wxDataFormatArray;
// ----------------------------------------------------------------------------
// data
diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp
index 0100682914..2a2e83a0e0 100644
--- a/src/gtk/dialog.cpp
+++ b/src/gtk/dialog.cpp
@@ -18,7 +18,7 @@
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
#include
diff --git a/src/motif/clipbrd.cpp b/src/motif/clipbrd.cpp
index 936328d7cf..6a38390943 100644
--- a/src/motif/clipbrd.cpp
+++ b/src/motif/clipbrd.cpp
@@ -32,7 +32,9 @@
#include "wx/dataobj.h"
#endif
-#include "wx/ptr_scpd.h"
+#include "wx/scopedarray.h"
+
+typedef wxScopedArray wxDataFormatScopedArray;
#ifdef __VMS__
#pragma message disable nosimpint
@@ -233,9 +235,6 @@ bool wxClipboard::SetData( wxDataObject *data )
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) )
diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp
index 55bd004088..1f9459d57d 100644
--- a/src/msw/dialog.cpp
+++ b/src/msw/dialog.cpp
@@ -40,7 +40,7 @@
#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"
diff --git a/src/msw/evtloop.cpp b/src/msw/evtloop.cpp
index d09faae69f..78d4ee212e 100644
--- a/src/msw/evtloop.cpp
+++ b/src/msw/evtloop.cpp
@@ -34,7 +34,6 @@
#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
diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp
index 46346acca8..b7c688c171 100644
--- a/src/msw/menu.cpp
+++ b/src/msw/menu.cpp
@@ -39,7 +39,7 @@
#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 "properly"
diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp
index 140831106f..b5d1b6ef2f 100644
--- a/src/msw/toolbar.cpp
+++ b/src/msw/toolbar.cpp
@@ -46,7 +46,7 @@
#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"
diff --git a/src/os2/dialog.cpp b/src/os2/dialog.cpp
index 0f299aaff5..d7da58b468 100644
--- a/src/os2/dialog.cpp
+++ b/src/os2/dialog.cpp
@@ -25,7 +25,7 @@
#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
diff --git a/src/os2/evtloop.cpp b/src/os2/evtloop.cpp
index da4a396c41..b054bfce48 100644
--- a/src/os2/evtloop.cpp
+++ b/src/os2/evtloop.cpp
@@ -33,7 +33,7 @@
#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
diff --git a/src/palmos/dialog.cpp b/src/palmos/dialog.cpp
index 971d771aae..32989e6eef 100644
--- a/src/palmos/dialog.cpp
+++ b/src/palmos/dialog.cpp
@@ -36,7 +36,7 @@
#endif
#include "wx/evtloop.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
// ----------------------------------------------------------------------------
// wxWin macros
diff --git a/src/palmos/evtloop.cpp b/src/palmos/evtloop.cpp
index 5dc164d157..5835fb3df8 100644
--- a/src/palmos/evtloop.cpp
+++ b/src/palmos/evtloop.cpp
@@ -33,7 +33,6 @@
#include "wx/tooltip.h"
#include "wx/except.h"
-#include "wx/ptr_scpd.h"
#if wxUSE_THREADS
#include "wx/thread.h"
diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp
index 1555d29b72..0f5e61d83c 100644
--- a/src/xml/xml.cpp
+++ b/src/xml/xml.cpp
@@ -29,7 +29,7 @@
#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
diff --git a/wxGTK.spec b/wxGTK.spec
index 4736b7dcb6..7bd321f1ff 100644
--- a/wxGTK.spec
+++ b/wxGTK.spec
@@ -217,6 +217,7 @@ wx/beforestd.h
wx/buffer.h
wx/build.h
wx/chartype.h
+wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
@@ -290,7 +291,10 @@ wx/ptr_scpd.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
@@ -341,8 +345,6 @@ wx/meta/convertible.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
diff --git a/wxMotif.spec b/wxMotif.spec
index b08d11074e..d1c674579b 100644
--- a/wxMotif.spec
+++ b/wxMotif.spec
@@ -122,6 +122,7 @@ wx/beforestd.h
wx/buffer.h
wx/build.h
wx/chartype.h
+wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
@@ -195,7 +196,10 @@ wx/ptr_scpd.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
@@ -246,8 +250,6 @@ wx/meta/convertible.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
diff --git a/wxX11.spec b/wxX11.spec
index ab1b782d29..5a532f693f 100644
--- a/wxX11.spec
+++ b/wxX11.spec
@@ -146,6 +146,7 @@ wx/beforestd.h
wx/buffer.h
wx/build.h
wx/chartype.h
+wx/checkeddelete.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
@@ -219,7 +220,10 @@ wx/ptr_scpd.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
@@ -270,8 +274,6 @@ wx/meta/convertible.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