From dd80897a18d5e1af05967f1b70aacdab0b32df8b Mon Sep 17 00:00:00 2001 From: upstream svn Date: Wed, 4 Feb 2009 18:15:10 +0100 Subject: [PATCH] Upstream tarball 9428 --- .svn-revision | 2 +- src/ScopedPtr.h | 205 ++++++++++++++------------------------------------------ 2 files changed, 51 insertions(+), 156 deletions(-) diff --git a/.svn-revision b/.svn-revision index 9ad1d337..ec0cac29 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -9427 +9428 diff --git a/src/ScopedPtr.h b/src/ScopedPtr.h index 5c22ff1f..119a6653 100644 --- a/src/ScopedPtr.h +++ b/src/ScopedPtr.h @@ -1,4 +1,4 @@ -// +// -*- C++ -*- // This file is part of the aMule Project. // // Copyright (c) 2006-2008 Mikkel Schubert ( xaignar@users.sourceforge.net ) @@ -40,35 +40,41 @@ class CScopedPtr { public: /** Constructor. Note that CScopedPtr takes ownership of the pointer. */ - CScopedPtr(TYPE* ptr); - + CScopedPtr(TYPE* ptr = 0) + : m_ptr(ptr) + {} + /** Frees the pointer owned by the instance. */ - ~CScopedPtr(); - - + ~CScopedPtr() { delete m_ptr; } + //@{ /** Deference operators. */ - TYPE& operator*() const; - TYPE* operator->() const; + TYPE& operator*() const { return *m_ptr; } + TYPE* operator->() const { return m_ptr; } //@} - - + + /** Returns the actual pointer value. */ - TYPE* get() const; - + TYPE* get() const { return m_ptr; } + /** Sets the actual pointer to a different value. The old pointer is freed. */ - void reset(TYPE* ptr = 0); - + void reset(TYPE* ptr = 0) { delete m_ptr; m_ptr = ptr; } + /** Returns the actual pointer. The scoped-ptr will thereafter contain NULL. */ - TYPE* release(); - + TYPE* release() + { + TYPE* ptr = m_ptr; + m_ptr = 0; + return ptr; + } + private: //@{ //! A scoped pointer is neither copyable, nor assignable. CScopedPtr(const CScopedPtr&); CScopedPtr& operator=(const CScopedPtr&); //@} - + TYPE* m_ptr; }; @@ -83,159 +89,48 @@ class CScopedArray { public: /** Constructor. Note that CScopedArray takes ownership of the array. */ - CScopedArray(TYPE* ptr); - + CScopedArray(TYPE* ptr = 0) + : m_ptr(ptr) + {} + /** Constructor, allocating nr elements. */ - CScopedArray(size_t nr); - + CScopedArray(size_t nr) { m_ptr = new TYPE[nr]; } + /** Frees the array owned by this instance. */ - ~CScopedArray(); - - + ~CScopedArray() { delete[] m_ptr; } + + /** Accessor. */ - TYPE& operator[](unsigned i) const; - - + TYPE& operator[](unsigned i) const { return m_ptr[i]; } + + /** @see CScopedPtr::get */ - TYPE* get() const; - + TYPE* get() const { return m_ptr; } + /** @see CScopedPtr::reset */ - void reset(TYPE* ptr = 0); - + void reset(TYPE* ptr = 0) { delete[] m_ptr; m_ptr = ptr; } + /** free the existing array and allocate a new one with nr elements */ - void reset(size_t nr); - + void reset(size_t nr) { delete[] m_ptr; m_ptr = new TYPE[nr]; } + /** @see CScopedPtr::release */ - TYPE* release(); - + TYPE* release() + { + TYPE* ptr = m_ptr; + m_ptr = 0; + return ptr; + } + + private: //@{ //! A scoped array is neither copyable, nor assignable. CScopedArray(const CScopedArray&); CScopedArray& operator=(const CScopedArray&); //@} - + TYPE* m_ptr; }; - - - -//////////////////////////////////////////////////////////// -// Implementations - -template -CScopedPtr::CScopedPtr(TYPE* ptr) - : m_ptr(ptr) -{ -} - - -template -CScopedPtr::~CScopedPtr() -{ - delete m_ptr; -} - - -template -TYPE& CScopedPtr::operator*() const -{ - return *m_ptr; -} - - -template -TYPE* CScopedPtr::operator->() const -{ - return m_ptr; -} - - -template -TYPE* CScopedPtr::get() const -{ - return m_ptr; -} - - -template -void CScopedPtr::reset(TYPE* ptr) -{ - delete m_ptr; - m_ptr = ptr; -} - - -template -TYPE* CScopedPtr::release() -{ - TYPE* ptr = m_ptr; - m_ptr = 0; - return ptr; -} - - - -template -CScopedArray::CScopedArray(TYPE* ptr) - : m_ptr(ptr) -{ -} - - -template -CScopedArray::CScopedArray(size_t nr) -{ - m_ptr = new TYPE[nr]; -} - - -template -CScopedArray::~CScopedArray() -{ - delete[] m_ptr; -} - - -template -TYPE& CScopedArray::operator[](unsigned i) const -{ - return m_ptr[i]; -} - - -template -TYPE* CScopedArray::get() const -{ - return m_ptr; -} - - -template -void CScopedArray::reset(TYPE* ptr) -{ - delete[] m_ptr; - m_ptr = ptr; -} - - -template -void CScopedArray::reset(size_t nr) -{ - delete[] m_ptr; - m_ptr = new TYPE[nr]; -} - - -template -TYPE* CScopedArray::release() -{ - TYPE* ptr = m_ptr; - m_ptr = 0; - return ptr; -} - - #endif // SCOPEDPTR_H // File_checked_for_headers -- 2.11.4.GIT