From 2a3bb0f5c40125768d0c94aa2e4ae197151b340f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 24 Oct 2008 17:21:02 +0200 Subject: [PATCH] autoPtr, tmp cosmetics - dropped non-const tmp::clear() in favour of the const version --- src/OpenFOAM/memory/autoPtr/autoPtr.H | 6 +-- src/OpenFOAM/memory/autoPtr/autoPtrI.H | 12 +++--- src/OpenFOAM/memory/tmp/tmp.H | 5 --- src/OpenFOAM/memory/tmp/tmpI.H | 54 +++++++++----------------- 4 files changed, 28 insertions(+), 49 deletions(-) diff --git a/src/OpenFOAM/memory/autoPtr/autoPtr.H b/src/OpenFOAM/memory/autoPtr/autoPtr.H index 3fbe085a3f..4ee0c95e88 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtr.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtr.H @@ -62,7 +62,7 @@ public: // Constructors //- Store object pointer - inline explicit autoPtr(T* = NULL); + inline explicit autoPtr(T* = 0); //- Construct as copy by transfering pointer to this autoPtr and // setting the arguments pointer to NULL @@ -90,11 +90,11 @@ public: //- Set pointer to that given. // If object pointer already set issue a FatalError. - inline void set(T* p); + inline void set(T*); //- If object pointer already set delete object and // set pointer to that given - inline void reset(T* p = NULL); + inline void reset(T* = 0); //- If object pointer points to valid object: // delete object and set pointer to NULL diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H index fb4c87c49d..0013d9f8e0 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H @@ -29,9 +29,9 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -inline Foam::autoPtr::autoPtr(T* tPtr) +inline Foam::autoPtr::autoPtr(T* p) : - ptr_(tPtr) + ptr_(p) {} @@ -40,7 +40,7 @@ inline Foam::autoPtr::autoPtr(const autoPtr& ap) : ptr_(ap.ptr_) { - ap.ptr_ = NULL; + ap.ptr_ = 0; } @@ -64,7 +64,7 @@ template inline T* Foam::autoPtr::ptr() { T* ptr = ptr_; - ptr_ = NULL; + ptr_ = 0; return ptr; } @@ -74,7 +74,7 @@ inline void Foam::autoPtr::set(T* p) { if (ptr_) { - FatalErrorIn("void autoPtr::set(T* p)") + FatalErrorIn("void autoPtr::set(T*)") << "object already allocated" << abort(FatalError); } @@ -98,7 +98,7 @@ inline void Foam::autoPtr::reset(T* p) template inline void Foam::autoPtr::clear() { - reset(NULL); + reset(0); } diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index 316e109e2f..77894fe239 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -98,16 +98,11 @@ public: // or a temporary that has been allocated inline bool valid() const; - // Edit //- Return tmp pointer for reuse inline T* ptr() const; - //- If object pointer points to valid object: - // delete object and set pointer to NULL - inline void clear(); - //- If object pointer points to valid object: // delete object and set pointer to NULL inline void clear() const; diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index dcba145d07..1c110816a1 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -26,15 +26,10 @@ License #include "error.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -inline tmp::tmp(T* tPtr) +inline Foam::tmp::tmp(T* tPtr) : isTmp_(true), ptr_(tPtr), @@ -43,16 +38,16 @@ inline tmp::tmp(T* tPtr) template -inline tmp::tmp(const T& tRef) +inline Foam::tmp::tmp(const T& tRef) : isTmp_(false), - ptr_(NULL), + ptr_(0), ref_(tRef) {} template -inline tmp::tmp(const tmp& t) +inline Foam::tmp::tmp(const tmp& t) : isTmp_(t.isTmp_), ptr_(t.ptr_), @@ -75,14 +70,14 @@ inline tmp::tmp(const tmp& t) template -inline tmp::~tmp() +inline Foam::tmp::~tmp() { if (isTmp_ && ptr_) { if (ptr_->okToDelete()) { delete ptr_; - ptr_ = NULL; + ptr_ = 0; } else { @@ -95,21 +90,21 @@ inline tmp::~tmp() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -inline bool tmp::isTmp() const +inline bool Foam::tmp::isTmp() const { return isTmp_; } template -inline bool tmp::valid() const +inline bool Foam::tmp::valid() const { return (!isTmp_ || (isTmp_ && ptr_)); } template -inline T* tmp::ptr() const +inline T* Foam::tmp::ptr() const { if (isTmp_) { @@ -121,7 +116,7 @@ inline T* tmp::ptr() const } T* ptr = ptr_; - ptr_ = NULL; + ptr_ = 0; ptr->resetRefCount(); @@ -135,27 +130,20 @@ inline T* tmp::ptr() const template -inline void tmp::clear() +inline void Foam::tmp::clear() const { if (isTmp_ && ptr_) // && ptr_->okToDelete()) { delete ptr_; - ptr_ = NULL; + ptr_ = 0; } } -template -inline void tmp::clear() const -{ - const_cast&>(*this).clear(); -} - - // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template -inline T& tmp::operator()() +inline T& Foam::tmp::operator()() { if (isTmp_) { @@ -181,7 +169,7 @@ inline T& tmp::operator()() template -inline const T& tmp::operator()() const +inline const T& Foam::tmp::operator()() const { if (isTmp_) { @@ -202,14 +190,14 @@ inline const T& tmp::operator()() const template -inline tmp::operator const T&() const +inline Foam::tmp::operator const T&() const { return operator()(); } template -inline T* tmp::operator->() +inline T* Foam::tmp::operator->() { if (isTmp_) { @@ -230,21 +218,21 @@ inline T* tmp::operator->() template -inline const T* tmp::operator->() const +inline const T* Foam::tmp::operator->() const { return const_cast&>(*this).operator->(); } template -inline void tmp::operator=(const tmp& t) +inline void Foam::tmp::operator=(const tmp& t) { if (isTmp_ && ptr_) { if (ptr_->okToDelete()) { delete ptr_; - ptr_ = NULL; + ptr_ = 0; } else { @@ -277,8 +265,4 @@ inline void tmp::operator=(const tmp& t) } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* //