From c8e3b45dc8808882f6bb820987a563a64f461875 Mon Sep 17 00:00:00 2001 From: cantor Date: Mon, 6 Aug 2007 03:46:16 +0000 Subject: [PATCH] Array deletion auto_ptr. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@371 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/unicode.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/xmltooling/unicode.h b/xmltooling/unicode.h index 6f6893e..6cc8763 100644 --- a/xmltooling/unicode.h +++ b/xmltooling/unicode.h @@ -178,6 +178,49 @@ namespace xmltooling { XMLCh* m_buf; }; + /** + * An auto_ptr that uses array delete on its contents. + * + * @param T type of pointer to wrap + */ + template class auto_arrayptr + { + T* m_ptr; + + auto_arrayptr(const auto_arrayptr&); + auto_arrayptr& operator=(const auto_arrayptr&); + public: + /** + * Constructor. + * + * @param ptr pointer to wrap + */ + auto_arrayptr(T* ptr) : m_ptr(ptr) { + } + + /** + * Destructor, uses array delete operation on wrapped pointer. + */ + ~auto_arrayptr() { + delete[] m_ptr; + } + + /** + * Returns the wrapped pointer. + * @return the wrapped pointer + */ + const T* get() const { + return m_ptr; + } + + /** + * Returns the wrapped pointer and transfers ownership of it to the caller. + * @return the wrapped pointer + */ + T* release() { + T* temp=m_ptr; m_ptr=NULL; return temp; + } + }; }; #endif /* __xmltooling_unicode_h__ */ -- 2.1.4