ENH: adjustments to Switch

- align Switch more with Enum.
  Now have find(), found() static methods.
  Constructors with failsafe option.

  The find() method makes for clearer coding:

  OLD

     Switch sw(some_string, true); // NB: true = allowBad

     if (sw.valid()) ...

  NOW

     Switch sw = Switch::find(some_string);

     if (sw.good()) ...

  or

     if (Switch::found(some_string)) ...

- improve construct from dictionary to handle all valid token types.
  Previously just read in a word.

- Remove asText() method - replaced by c_str() and str() several
  versions ago.
This commit is contained in:
Mark Olesen
2020-02-14 17:21:44 +01:00
parent ed4bd54846
commit bb53e8adb3
10 changed files with 277 additions and 184 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2017 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -279,16 +279,9 @@ int main(int argc, char *argv[])
surfaceIntersection::NONE
);
const Switch writeObj = surfaceDict.lookupOrDefault<Switch>
(
"writeObj",
Switch::OFF
);
const Switch writeVTK = surfaceDict.lookupOrDefault<Switch>
(
"writeVTK",
Switch::OFF
);
const Switch writeObj("writeObj", surfaceDict, Switch::OFF);
const Switch writeVTK("writeVTK", surfaceDict, Switch::OFF);
// The "surfaces" entry is normally optional, but make it mandatory
// if the dictionary name doesn't have an extension