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 5552674fc7
commit 4758c2ac86
34 changed files with 291 additions and 183 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,7 +43,7 @@ Foam::tmp<Foam::scalarField> Foam::polyMeshTools::faceOrthogonality
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
tmp<scalarField> tortho(new scalarField(mesh.nFaces(), 1.0));
scalarField& ortho = tortho();
scalarField& ortho = tortho.ref();
// Internal faces
forAll(nei, faceI)
@ -100,7 +100,7 @@ Foam::tmp<Foam::scalarField> Foam::polyMeshTools::faceSkewness
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
tmp<scalarField> tskew(new scalarField(mesh.nFaces()));
scalarField& skew = tskew();
scalarField& skew = tskew.ref();
forAll(nei, faceI)
{
@ -184,7 +184,7 @@ Foam::tmp<Foam::scalarField> Foam::polyMeshTools::faceWeights
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
tmp<scalarField> tweight(new scalarField(mesh.nFaces(), 1.0));
scalarField& weight = tweight();
scalarField& weight = tweight.ref();
// Internal faces
forAll(nei, faceI)
@ -240,7 +240,7 @@ Foam::tmp<Foam::scalarField> Foam::polyMeshTools::volRatio
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
tmp<scalarField> tratio(new scalarField(mesh.nFaces(), 1.0));
scalarField& ratio = tratio();
scalarField& ratio = tratio.ref();
// Internal faces
forAll(nei, faceI)