ENH: autoPtr: added reUse flag, improved error message

This commit is contained in:
mattijs
2013-05-21 14:22:43 +01:00
parent 3cdc5d4085
commit f115890dba
4 changed files with 42 additions and 12 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -67,6 +67,10 @@ public:
// setting the arguments pointer to NULL // setting the arguments pointer to NULL
inline autoPtr(const autoPtr<T>&); inline autoPtr(const autoPtr<T>&);
//- Construct either by transfering pointer or cloning. Should
// only be called with type that supports cloning.
inline autoPtr(const autoPtr<T>&, const bool reUse);
//- Destructor, delete object if pointer is not NULL //- Destructor, delete object if pointer is not NULL
inline ~autoPtr(); inline ~autoPtr();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
#include <typeinfo>
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -43,6 +44,21 @@ inline Foam::autoPtr<T>::autoPtr(const autoPtr<T>& ap)
} }
template<class T>
inline Foam::autoPtr<T>::autoPtr(const autoPtr<T>& ap, const bool reUse)
{
if (reUse)
{
ptr_ = ap.ptr_;
ap.ptr_ = 0;
}
else
{
ptr_ = ap().clone().ptr();
}
}
template<class T> template<class T>
inline Foam::autoPtr<T>::~autoPtr() inline Foam::autoPtr<T>::~autoPtr()
{ {
@ -81,7 +97,8 @@ inline void Foam::autoPtr<T>::set(T* p)
if (ptr_) if (ptr_)
{ {
FatalErrorIn("void Foam::autoPtr<T>::set(T*)") FatalErrorIn("void Foam::autoPtr<T>::set(T*)")
<< "object already allocated" << "object of type " << typeid(T).name()
<< " already allocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -116,7 +133,8 @@ inline T& Foam::autoPtr<T>::operator()()
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("T& Foam::autoPtr<T>::operator()()") FatalErrorIn("T& Foam::autoPtr<T>::operator()()")
<< "object is not allocated" << "object of type " << typeid(T).name()
<< " is not allocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -130,7 +148,8 @@ inline const T& Foam::autoPtr<T>::operator()() const
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("const T& Foam::autoPtr<T>::operator()() const") FatalErrorIn("const T& Foam::autoPtr<T>::operator()() const")
<< "object is not allocated" << "object of type " << typeid(T).name()
<< " is not allocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -151,7 +170,8 @@ inline T* Foam::autoPtr<T>::operator->()
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("Foam::autoPtr<T>::operator->()") FatalErrorIn("Foam::autoPtr<T>::operator->()")
<< "object is not allocated" << "object of type " << typeid(T).name()
<< " is not allocated"
<< abort(FatalError); << abort(FatalError);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
#include <typeinfo>
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -62,6 +63,7 @@ inline Foam::tmp<T>::tmp(const tmp<T>& t)
{ {
FatalErrorIn("Foam::tmp<T>::tmp(const tmp<T>&)") FatalErrorIn("Foam::tmp<T>::tmp(const tmp<T>&)")
<< "attempted copy of a deallocated temporary" << "attempted copy of a deallocated temporary"
<< " of type " << typeid(T).name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -93,6 +95,7 @@ inline Foam::tmp<T>::tmp(const tmp<T>& t, bool allowTransfer)
( (
"Foam::tmp<T>::tmp(const tmp<T>&, bool allowTransfer)" "Foam::tmp<T>::tmp(const tmp<T>&, bool allowTransfer)"
) << "attempted copy of a deallocated temporary" ) << "attempted copy of a deallocated temporary"
<< " of type " << typeid(T).name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -149,7 +152,7 @@ inline T* Foam::tmp<T>::ptr() const
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("Foam::tmp<T>::ptr() const") FatalErrorIn("Foam::tmp<T>::ptr() const")
<< "temporary deallocated" << "temporary of type " << typeid(T).name() << " deallocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -188,7 +191,7 @@ inline T& Foam::tmp<T>::operator()()
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("T& Foam::tmp<T>::operator()()") FatalErrorIn("T& Foam::tmp<T>::operator()()")
<< "temporary deallocated" << "temporary of type " << typeid(T).name() << " deallocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -217,7 +220,7 @@ inline const T& Foam::tmp<T>::operator()() const
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("const T& Foam::tmp<T>::operator()() const") FatalErrorIn("const T& Foam::tmp<T>::operator()() const")
<< "temporary deallocated" << "temporary of type " << typeid(T).name() << " deallocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -245,7 +248,7 @@ inline T* Foam::tmp<T>::operator->()
if (!ptr_) if (!ptr_)
{ {
FatalErrorIn("Foam::tmp<T>::operator->()") FatalErrorIn("Foam::tmp<T>::operator->()")
<< "temporary deallocated" << "temporary of type " << typeid(T).name() << " deallocated"
<< abort(FatalError); << abort(FatalError);
} }
@ -294,6 +297,7 @@ inline void Foam::tmp<T>::operator=(const tmp<T>& t)
{ {
FatalErrorIn("Foam::tmp<T>::operator=(const tmp<T>&)") FatalErrorIn("Foam::tmp<T>::operator=(const tmp<T>&)")
<< "attempted copy of a deallocated temporary" << "attempted copy of a deallocated temporary"
<< " of type " << typeid(T).name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -301,6 +305,7 @@ inline void Foam::tmp<T>::operator=(const tmp<T>& t)
{ {
FatalErrorIn("Foam::tmp<T>::operator=(const tmp<T>&)") FatalErrorIn("Foam::tmp<T>::operator=(const tmp<T>&)")
<< "attempted to assign to a const reference to constant object" << "attempted to assign to a const reference to constant object"
<< " of type " << typeid(T).name()
<< abort(FatalError); << abort(FatalError);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,6 +25,7 @@ License
#include "thermoSingleLayer.H" #include "thermoSingleLayer.H"
#include "heatTransferModel.H" #include "heatTransferModel.H"
#include "filmRadiationModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //