added template wxScopedArray<> too

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58460 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-01-27 16:40:51 +00:00
parent e5d28ed426
commit 058f225a44
3 changed files with 190 additions and 66 deletions

View File

@@ -291,8 +291,11 @@ public:
/**
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}
@@ -303,12 +306,15 @@ class wxScopedPtr<T>
{
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();
@@ -319,7 +325,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.
@@ -362,3 +368,76 @@ public:
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;
}
};