+ 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