Commit 2a3bb0f5 authored by Mark Olesen's avatar Mark Olesen
Browse files

autoPtr, tmp cosmetics

  - dropped non-const tmp::clear() in favour of the const version
parent 7d081f0e
......@@ -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
......
......@@ -29,9 +29,9 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
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_)
{
ap.ptr_ = NULL;
ap.ptr_ = 0;
}
......@@ -64,7 +64,7 @@ template<class T>
inline T* Foam::autoPtr<T>::ptr()
{
T* ptr = ptr_;
ptr_ = NULL;
ptr_ = 0;
return ptr;
}
......@@ -74,7 +74,7 @@ inline void Foam::autoPtr<T>::set(T* p)
{
if (ptr_)
{
FatalErrorIn("void autoPtr<T>::set(T* p)")
FatalErrorIn("void autoPtr<T>::set(T*)")
<< "object already allocated"
<< abort(FatalError);
}
......@@ -98,7 +98,7 @@ inline void Foam::autoPtr<T>::reset(T* p)
template<class T>
inline void Foam::autoPtr<T>::clear()
{
reset(NULL);
reset(0);
}
......
......@@ -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;
......
......@@ -26,15 +26,10 @@ License
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline tmp<T>::tmp(T* tPtr)
inline Foam::tmp<T>::tmp(T* tPtr)
:
isTmp_(true),
ptr_(tPtr),
......@@ -43,16 +38,16 @@ inline tmp<T>::tmp(T* tPtr)
template<class T>
inline tmp<T>::tmp(const T& tRef)
inline Foam::tmp<T>::tmp(const T& tRef)
:
isTmp_(false),
ptr_(NULL),
ptr_(0),
ref_(tRef)
{}
template<class T>
inline tmp<T>::tmp(const tmp<T>& t)
inline Foam::tmp<T>::tmp(const tmp<T>& t)
:
isTmp_(t.isTmp_),
ptr_(t.ptr_),
......@@ -75,14 +70,14 @@ inline tmp<T>::tmp(const tmp<T>& t)
template<class T>
inline tmp<T>::~tmp()
inline Foam::tmp<T>::~tmp()
{
if (isTmp_ && ptr_)
{
if (ptr_->okToDelete())
{
delete ptr_;
ptr_ = NULL;
ptr_ = 0;
}
else
{
......@@ -95,21 +90,21 @@ inline tmp<T>::~tmp()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline bool tmp<T>::isTmp() const
inline bool Foam::tmp<T>::isTmp() const
{
return isTmp_;
}
template<class T>
inline bool tmp<T>::valid() const
inline bool Foam::tmp<T>::valid() const
{
return (!isTmp_ || (isTmp_ && ptr_));
}
template<class T>
inline T* tmp<T>::ptr() const
inline T* Foam::tmp<T>::ptr() const
{
if (isTmp_)
{
......@@ -121,7 +116,7 @@ inline T* tmp<T>::ptr() const
}
T* ptr = ptr_;
ptr_ = NULL;
ptr_ = 0;
ptr->resetRefCount();
......@@ -135,27 +130,20 @@ inline T* tmp<T>::ptr() const
template<class T>
inline void tmp<T>::clear()
inline void Foam::tmp<T>::clear() const
{
if (isTmp_ && ptr_) // && ptr_->okToDelete())
{
delete ptr_;
ptr_ = NULL;
ptr_ = 0;
}
}
template<class T>
inline void tmp<T>::clear() const
{
const_cast<tmp<T>&>(*this).clear();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline T& tmp<T>::operator()()
inline T& Foam::tmp<T>::operator()()
{
if (isTmp_)
{
......@@ -181,7 +169,7 @@ inline T& tmp<T>::operator()()
template<class T>
inline const T& tmp<T>::operator()() const
inline const T& Foam::tmp<T>::operator()() const
{
if (isTmp_)
{
......@@ -202,14 +190,14 @@ inline const T& tmp<T>::operator()() const
template<class T>
inline tmp<T>::operator const T&() const
inline Foam::tmp<T>::operator const T&() const
{
return operator()();
}
template<class T>
inline T* tmp<T>::operator->()
inline T* Foam::tmp<T>::operator->()
{
if (isTmp_)
{
......@@ -230,21 +218,21 @@ inline T* tmp<T>::operator->()
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->();
}
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 (ptr_->okToDelete())
{
delete ptr_;
ptr_ = NULL;
ptr_ = 0;
}
else
{
......@@ -277,8 +265,4 @@ inline void tmp<T>::operator=(const tmp<T>& t)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment