- wxWidgets may now use either wchar_t (UTF-16/32) or UTF-8 internally,
depending on what is optimal for the target platform.
-- New propgrid library containing wxPropertyGrid and related classes, many
- enhancements to wxDataViewCtrl.
+- New propgrid library containing wxPropertyGrid and related classes.
+
+- Many enhancements to wxDataViewCtrl.
- Event loops, timers and sockets can now be used in wxBase, without GUI.
Linnakangas).
- wxVariant::Unshare allows exclusive allocation of data that must be shared,
if the wxVariantData::Clone function is implemented.
-- Added wxWeakRef<T>, wxScopedPtr<T>, wxSharedPtr<T> class templates
+- Added wxWeakRef<T>, wxScopedPtr<T>, wxScopedArray<T>, wxSharedPtr<T> templates.
- 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
- Added wxSHUTDOWN_LOGOFF and wxSHUTDOWN_FORCE wxShutdown() flags (troelsk).
- Added wxSocket::ShutdownOutput().
- Handle exceptions thrown from overridden wxView::OnCreate() gracefully.
+- Added wxPATH_RMDIR_FULL/RECURSIVE wxFileName::Rmdir() flags (Marcin Malich).
- Added wxStandardPaths::GetAppDocumentsDir().
All (Unix):
// Name: wx/ptr_scpd.h
// Purpose: scoped smart pointer class
// Author: Jesse Lovelace <jllovela@eos.ncsu.edu>
-// Modified by:
+// 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
/////////////////////////////////////////////////////////////////////////////
#include "wx/defs.h"
// ----------------------------------------------------------------------------
-// wxScopedPtr: A scoped pointer
+// wxScopedPtr: A scoped pointer
// ----------------------------------------------------------------------------
-template <class T>
+template <class T>
class wxScopedPtr
-{
-private:
- T * m_ptr;
-
- wxScopedPtr(wxScopedPtr const &);
- wxScopedPtr & operator=(wxScopedPtr const &);
-
-public:
+{
+public:
typedef T element_type;
-
- wxEXPLICIT wxScopedPtr(T * ptr = NULL)
- : m_ptr(ptr) { }
-
- ~wxScopedPtr()
- {
- if (m_ptr)
- delete m_ptr;
- }
-
+
+ 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;
return m_ptr ? &wxScopedPtr<T>::get : NULL;
}
- void reset(T * ptr = NULL)
- {
- if (m_ptr != ptr)
- {
- delete m_ptr;
- m_ptr = ptr;
- }
- }
-
- T *release()
- {
- T *ptr = m_ptr;
- m_ptr = NULL;
- return ptr;
- }
-
- T & operator*() const
- {
- wxASSERT(m_ptr != NULL);
- return *m_ptr;
- }
-
- T * operator->() const
- {
- wxASSERT(m_ptr != NULL);
- return m_ptr;
- }
-
- T * get() const
- {
- return m_ptr;
- }
-
- void swap(wxScopedPtr & ot)
- {
- T * tmp = ot.m_ptr;
- ot.m_ptr = m_ptr;
- m_ptr = tmp;
- }
+ 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)
};
// ----------------------------------------------------------------------------
/**
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}
{
public:
/**
- Constructor.
+ Constructor takes ownership of the pointer.
+
+ @param ptr
+ Pointer allocated with @c new or @NULL.
*/
wxScopedPtr(T* ptr = NULL);
/**
- Destructor.
+ Destructor deletes the pointer.
*/
~wxScopedPtr();
/**
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.
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 { return m_array; }
+
+ /// Swaps the contents of this array with another one.
+ void swap(wxScopedArray &other)
+ {
+ T * const tmp = other.m_array;
+ other.m_array = m_array;
+ m_array = tmp;
+ }
+};