Skip to content
Snippets Groups Projects
Commit 41dcf4ab authored by Henry's avatar Henry
Browse files

OpenFOAM: added "transfer" constructor to tmp

Needed for return of tmp argument in "absolute" meshPhi function
parent 06d573d6
No related merge requests found
......@@ -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);
}
}
......
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