mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: simplify short-circuit involving autoPtr (#1775)
- with '&&' conditions, often better to check for non-null autoPtr
first (it is cheap)
- check as bool instead of valid() method for cleaner code, especially
when the wrapped item itself has a valid/empty or good.
Also when handling multiple checks.
Now
if (ptr && ptr->valid())
if (ptr1 || ptr2)
instead
if (ptr.valid() && ptr->valid())
if (ptr1.valid() || ptr2.valid())
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -38,7 +38,7 @@ withSurfaceFields() const
|
||||
(
|
||||
stFaceZone == regionType_
|
||||
|| stPatch == regionType_
|
||||
|| (sampledPtr_.valid() && sampledPtr_->withSurfaceFields())
|
||||
|| (sampledPtr_ && sampledPtr_->withSurfaceFields())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -370,7 +370,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
|
||||
Field<Type> values(getFieldValues<Type>(fieldName, true));
|
||||
|
||||
// Write raw values on surface if specified
|
||||
if (surfaceWriterPtr_.valid() && surfaceWriterPtr_->enabled())
|
||||
if (surfaceWriterPtr_ && surfaceWriterPtr_->enabled())
|
||||
{
|
||||
Field<Type> allValues(values);
|
||||
combineFields(allValues);
|
||||
|
||||
@ -34,7 +34,7 @@ template<class chemistryType>
|
||||
void Foam::functionObjects::reactionsSensitivityAnalysis<chemistryType>::
|
||||
createFileNames()
|
||||
{
|
||||
if (writeToFile() && !prodFilePtr_.valid())
|
||||
if (writeToFile() && !prodFilePtr_)
|
||||
{
|
||||
prodFilePtr_ = createFile("production");
|
||||
writeHeader(prodFilePtr_(), "production");
|
||||
|
||||
@ -413,8 +413,8 @@ bool Foam::functionObjects::regionSizeDistribution::write()
|
||||
|
||||
const volScalarField& alpha =
|
||||
(
|
||||
alphaPtr.valid()
|
||||
? alphaPtr()
|
||||
alphaPtr
|
||||
? *alphaPtr
|
||||
: obr_.lookupObject<volScalarField>(alphaName_)
|
||||
);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -54,7 +54,7 @@ void Foam::functionObjects::forceCoeffs::createFiles()
|
||||
{
|
||||
// Note: Only possible to create bin files after bins have been initialised
|
||||
|
||||
if (writeToFile() && !coeffFilePtr_.valid())
|
||||
if (writeToFile() && !coeffFilePtr_)
|
||||
{
|
||||
coeffFilePtr_ = createFile("coefficient");
|
||||
writeIntegratedHeader("Coefficients", coeffFilePtr_());
|
||||
|
||||
@ -58,7 +58,7 @@ void Foam::functionObjects::forces::createFiles()
|
||||
{
|
||||
// Note: Only possible to create bin files after bins have been initialised
|
||||
|
||||
if (writeToFile() && !forceFilePtr_.valid())
|
||||
if (writeToFile() && !forceFilePtr_)
|
||||
{
|
||||
forceFilePtr_ = createFile("force");
|
||||
writeIntegratedHeader("Force", forceFilePtr_());
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -126,7 +126,7 @@ Foam::label Foam::functionObjects::vtkWrite::writeVolFields
|
||||
const auto& field = tfield();
|
||||
|
||||
// Internal
|
||||
if (internalWriter.valid() && pInterp.valid())
|
||||
if (internalWriter && pInterp)
|
||||
{
|
||||
ok = true;
|
||||
internalWriter->write(field, *pInterp);
|
||||
|
||||
Reference in New Issue
Block a user