OpenFOAM: added "transfer" constructor to tmp

Needed for return of tmp argument in "absolute" meshPhi function
This commit is contained in:
Henry
2012-10-11 18:10:39 +01:00
parent 06d573d69a
commit 41dcf4abfb
3 changed files with 37 additions and 2 deletions

View File

@ -79,6 +79,9 @@ public:
//- Construct copy and increment reference count
inline tmp(const tmp<T>&);
//- Construct copy transferring content of temporary if required
inline tmp(const tmp<T>&, bool allowTransfer);
//- Destructor, delete object when reference count == 0
inline ~tmp();

View File

@ -68,6 +68,38 @@ inline Foam::tmp<T>::tmp(const tmp<T>& t)
}
template<class T>
inline Foam::tmp<T>::tmp(const tmp<T>& t, bool allowTransfer)
:
isTmp_(t.isTmp_),
ptr_(t.ptr_),
ref_(t.ref_)
{
if (isTmp_)
{
if (allowTransfer)
{
const_cast<tmp<T>&>(t).ptr_ = 0;
}
else
{
if (ptr_)
{
ptr_->operator++();
}
else
{
FatalErrorIn
(
"Foam::tmp<T>::tmp(const tmp<T>&, bool allowTransfer)"
) << "attempted copy of a deallocated temporary"
<< abort(FatalError);
}
}
}
}
template<class T>
inline Foam::tmp<T>::~tmp()
{

View File

@ -160,7 +160,7 @@ Foam::tmp<Foam::surfaceScalarField> Foam::fvc::absolute
}
else
{
return tphi;
return tmp<surfaceScalarField>(tphi, true);
}
}
@ -178,7 +178,7 @@ Foam::tmp<Foam::surfaceScalarField> Foam::fvc::absolute
}
else
{
return tphi;
return tmp<surfaceScalarField>(tphi, true);
}
}