autoPtr, tmp cosmetics

- dropped non-const tmp::clear() in favour of the const version
This commit is contained in:
Mark Olesen
2008-10-24 17:21:02 +02:00
parent 7d081f0ed3
commit 2a3bb0f5c4
4 changed files with 28 additions and 49 deletions

View File

@ -62,7 +62,7 @@ public:
// Constructors // Constructors
//- Store object pointer //- Store object pointer
inline explicit autoPtr(T* = NULL); inline explicit autoPtr(T* = 0);
//- Construct as copy by transfering pointer to this autoPtr and //- Construct as copy by transfering pointer to this autoPtr and
// setting the arguments pointer to NULL // setting the arguments pointer to NULL
@ -90,11 +90,11 @@ public:
//- Set pointer to that given. //- Set pointer to that given.
// If object pointer already set issue a FatalError. // 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 //- If object pointer already set delete object and
// set pointer to that given // set pointer to that given
inline void reset(T* p = NULL); inline void reset(T* = 0);
//- If object pointer points to valid object: //- If object pointer points to valid object:
// delete object and set pointer to NULL // delete object and set pointer to NULL

View File

@ -29,9 +29,9 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
inline Foam::autoPtr<T>::autoPtr(T* tPtr) inline Foam::autoPtr<T>::autoPtr(T* p)
: :
ptr_(tPtr) ptr_(p)
{} {}
@ -40,7 +40,7 @@ inline Foam::autoPtr<T>::autoPtr(const autoPtr<T>& ap)
: :
ptr_(ap.ptr_) ptr_(ap.ptr_)
{ {
ap.ptr_ = NULL; ap.ptr_ = 0;
} }
@ -64,7 +64,7 @@ template<class T>
inline T* Foam::autoPtr<T>::ptr() inline T* Foam::autoPtr<T>::ptr()
{ {
T* ptr = ptr_; T* ptr = ptr_;
ptr_ = NULL; ptr_ = 0;
return ptr; return ptr;
} }
@ -74,7 +74,7 @@ inline void Foam::autoPtr<T>::set(T* p)
{ {
if (ptr_) if (ptr_)
{ {
FatalErrorIn("void autoPtr<T>::set(T* p)") FatalErrorIn("void autoPtr<T>::set(T*)")
<< "object already allocated" << "object already allocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -98,7 +98,7 @@ inline void Foam::autoPtr<T>::reset(T* p)
template<class T> template<class T>
inline void Foam::autoPtr<T>::clear() inline void Foam::autoPtr<T>::clear()
{ {
reset(NULL); reset(0);
} }

View File

@ -98,16 +98,11 @@ public:
// or a temporary that has been allocated // or a temporary that has been allocated
inline bool valid() const; inline bool valid() const;
// Edit // Edit
//- Return tmp pointer for reuse //- Return tmp pointer for reuse
inline T* ptr() const; 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: //- If object pointer points to valid object:
// delete object and set pointer to NULL // delete object and set pointer to NULL
inline void clear() const; inline void clear() const;

View File

@ -26,15 +26,10 @@ License
#include "error.H" #include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
inline tmp<T>::tmp(T* tPtr) inline Foam::tmp<T>::tmp(T* tPtr)
: :
isTmp_(true), isTmp_(true),
ptr_(tPtr), ptr_(tPtr),
@ -43,16 +38,16 @@ inline tmp<T>::tmp(T* tPtr)
template<class T> template<class T>
inline tmp<T>::tmp(const T& tRef) inline Foam::tmp<T>::tmp(const T& tRef)
: :
isTmp_(false), isTmp_(false),
ptr_(NULL), ptr_(0),
ref_(tRef) ref_(tRef)
{} {}
template<class T> template<class T>
inline tmp<T>::tmp(const tmp<T>& t) inline Foam::tmp<T>::tmp(const tmp<T>& t)
: :
isTmp_(t.isTmp_), isTmp_(t.isTmp_),
ptr_(t.ptr_), ptr_(t.ptr_),
@ -75,14 +70,14 @@ inline tmp<T>::tmp(const tmp<T>& t)
template<class T> template<class T>
inline tmp<T>::~tmp() inline Foam::tmp<T>::~tmp()
{ {
if (isTmp_ && ptr_) if (isTmp_ && ptr_)
{ {
if (ptr_->okToDelete()) if (ptr_->okToDelete())
{ {
delete ptr_; delete ptr_;
ptr_ = NULL; ptr_ = 0;
} }
else else
{ {
@ -95,21 +90,21 @@ inline tmp<T>::~tmp()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T> template<class T>
inline bool tmp<T>::isTmp() const inline bool Foam::tmp<T>::isTmp() const
{ {
return isTmp_; return isTmp_;
} }
template<class T> template<class T>
inline bool tmp<T>::valid() const inline bool Foam::tmp<T>::valid() const
{ {
return (!isTmp_ || (isTmp_ && ptr_)); return (!isTmp_ || (isTmp_ && ptr_));
} }
template<class T> template<class T>
inline T* tmp<T>::ptr() const inline T* Foam::tmp<T>::ptr() const
{ {
if (isTmp_) if (isTmp_)
{ {
@ -121,7 +116,7 @@ inline T* tmp<T>::ptr() const
} }
T* ptr = ptr_; T* ptr = ptr_;
ptr_ = NULL; ptr_ = 0;
ptr->resetRefCount(); ptr->resetRefCount();
@ -135,27 +130,20 @@ inline T* tmp<T>::ptr() const
template<class T> template<class T>
inline void tmp<T>::clear() inline void Foam::tmp<T>::clear() const
{ {
if (isTmp_ && ptr_) // && ptr_->okToDelete()) if (isTmp_ && ptr_) // && ptr_->okToDelete())
{ {
delete ptr_; delete ptr_;
ptr_ = NULL; ptr_ = 0;
} }
} }
template<class T>
inline void tmp<T>::clear() const
{
const_cast<tmp<T>&>(*this).clear();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T>
inline T& tmp<T>::operator()() inline T& Foam::tmp<T>::operator()()
{ {
if (isTmp_) if (isTmp_)
{ {
@ -181,7 +169,7 @@ inline T& tmp<T>::operator()()
template<class T> template<class T>
inline const T& tmp<T>::operator()() const inline const T& Foam::tmp<T>::operator()() const
{ {
if (isTmp_) if (isTmp_)
{ {
@ -202,14 +190,14 @@ inline const T& tmp<T>::operator()() const
template<class T> template<class T>
inline tmp<T>::operator const T&() const inline Foam::tmp<T>::operator const T&() const
{ {
return operator()(); return operator()();
} }
template<class T> template<class T>
inline T* tmp<T>::operator->() inline T* Foam::tmp<T>::operator->()
{ {
if (isTmp_) if (isTmp_)
{ {
@ -230,21 +218,21 @@ inline T* tmp<T>::operator->()
template<class T> template<class T>
inline const T* tmp<T>::operator->() const inline const T* Foam::tmp<T>::operator->() const
{ {
return const_cast<tmp<T>&>(*this).operator->(); return const_cast<tmp<T>&>(*this).operator->();
} }
template<class T> template<class T>
inline void tmp<T>::operator=(const tmp<T>& t) inline void Foam::tmp<T>::operator=(const tmp<T>& t)
{ {
if (isTmp_ && ptr_) if (isTmp_ && ptr_)
{ {
if (ptr_->okToDelete()) if (ptr_->okToDelete())
{ {
delete ptr_; delete ptr_;
ptr_ = NULL; ptr_ = 0;
} }
else else
{ {
@ -277,8 +265,4 @@ inline void tmp<T>::operator=(const tmp<T>& t)
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //