tmp: Updated to store and preserve the const-ness of the reference to a constant object

This change requires that the de-reference operator '()' returns a
const-reference to the object stored irrespective of the const-ness of
object stored and the new member function 'ref()' is provided to return
an non-const reference to stored object which throws a fatal error if the
stored object is const.

In order to smooth the transition to this new safer 'tmp' the now
deprecated and unsafe non-const de-reference operator '()' is still
provided by default but may be switched-off with the compilation switch
'CONST_TMP'.

The main OpenFOAM library has already been upgraded and '-DCONST_TMP'
option specified in the 'options' file to switch to the new 'tmp'
behavior.  The rest of OpenFOAM-dev will be upgraded over the following
few weeks.

Henry G. Weller
CFD Direct
This commit is contained in:
Henry Weller
2016-02-22 16:23:21 +00:00
parent 96b0f62d04
commit 15b7e87da7
34 changed files with 291 additions and 183 deletions

View File

@ -106,14 +106,14 @@ void inv(Field<tensor>& tf, const UList<tensor>& tf1)
tmp<tensorField> inv(const UList<tensor>& tf)
{
tmp<tensorField> result(new tensorField(tf.size()));
inv(result(), tf);
inv(result.ref(), tf);
return result;
}
tmp<tensorField> inv(const tmp<tensorField>& tf)
{
tmp<tensorField> tRes = reuseTmp<tensor, tensor>::New(tf);
inv(tRes(), tf());
inv(tRes.ref(), tf());
reuseTmp<tensor, tensor>::clear(tf);
return tRes;
}
@ -132,7 +132,7 @@ tmp<Field<tensor>> transformFieldMask<tensor>
)
{
tmp<tensorField> tRes(new tensorField(stf.size()));
tensorField& res = tRes();
tensorField& res = tRes.ref();
TFOR_ALL_F_OP_F(tensor, res, =, symmTensor, stf)
return tRes;
}