mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
OpenFOAM: added "transfer" constructor to tmp
Needed for return of tmp argument in "absolute" meshPhi function
This commit is contained in:
@ -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();
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user