/**
@class wxScopedPtr
- @wxheader{ptr_scpd.h}
This is a simple scoped smart pointer implementation that is similar to
the Boost smart pointers (see http://www.boost.org) but rewritten
theCharObj[0] = "!";
@endcode
- @section wxscopedptr_newpointers Declaring new smart pointer types
+ @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
/**
@class wxScopedArray
- @wxheader{ptr_scpd.h}
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
/**
@class wxScopedTiedPtr
- @wxheader{ptr_scpd.h}
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,
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 ctor() constructor)
+ 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
/**
- @wxheader{ptr_scpd.h}
- A scoped pointer template class. It is the template version of
- the old-style @ref classwx_scoped_ptr "scoped pointer macros".
+ 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;
+ }
+};