X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ae3c17b4013e80b99976c750c19fca47729517f6..fcd209b6a20b41e7ddf9acf837311ac6779ea41f:/interface/wx/ptr_scpd.h diff --git a/interface/wx/ptr_scpd.h b/interface/wx/ptr_scpd.h index 11180b1a55..b551c81cb0 100644 --- a/interface/wx/ptr_scpd.h +++ b/interface/wx/ptr_scpd.h @@ -8,7 +8,6 @@ /** @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 @@ -57,7 +56,7 @@ 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 @@ -157,7 +156,6 @@ public: /** @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 @@ -256,7 +254,6 @@ public: /** @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, @@ -278,8 +275,8 @@ public: 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 @@ -292,10 +289,12 @@ public: /** - @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} @@ -307,12 +306,15 @@ class wxScopedPtr { 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(); @@ -323,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. @@ -366,3 +368,76 @@ 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 { 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; + } +};