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:
Mark Olesen
2020-07-15 08:50:57 +02:00
parent 3baebcb101
commit 9af3f85cf9
35 changed files with 118 additions and 123 deletions

View File

@ -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_());

View File

@ -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_());