From b98f53ceca07f06883063789160d9521295533ec Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 29 Feb 2024 09:40:42 +0100 Subject: [PATCH] ENH: make ITstream positioning methods noexcept ENH: add rank() method for compound tokens ENH: add IOstream::minPrecision(unsigned) - reduced typing, more expressive, no namespace ambiguity with max() new: IOstream::minPrecision(10); old: IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); STYLE: namespace qualify min/max for some buffer sizing [clang/hipp] --- .../finiteArea/makeFaMesh/makeFaMesh.C | 4 +- .../snappyRefineMesh/snappyRefineMesh.C | 29 +++++++-- .../mesh/conversion/ansysToFoam/ansysToFoam.L | 6 +- .../mesh/conversion/ccm/ccmToFoam/ccmToFoam.C | 6 +- .../mesh/conversion/cfx4ToFoam/cfx4ToFoam.C | 6 +- .../conversion/ensightToFoam/ensightToFoam.C | 6 +- .../mesh/conversion/fireToFoam/fireToFoam.C | 6 +- .../fluent3DMeshToFoam/fluent3DMeshToFoam.L | 6 +- .../fluentMeshToFoam/fluentMeshToFoam.L | 6 +- .../conversion/gambitToFoam/gambitToFoam.L | 6 +- .../mesh/conversion/gmshToFoam/gmshToFoam.C | 4 +- .../ideasUnvToFoam/ideasUnvToFoam.C | 4 +- .../mesh/conversion/kivaToFoam/readKivaGrid.H | 4 +- .../mesh/conversion/mshToFoam/mshToFoam.C | 6 +- .../netgenNeutralToFoam/netgenNeutralToFoam.C | 6 +- .../conversion/plot3dToFoam/plot3dToFoam.C | 6 +- .../mesh/conversion/star4ToFoam/star4ToFoam.C | 6 +- .../conversion/tetgenToFoam/tetgenToFoam.C | 4 +- .../vtkUnstructuredToFoam.C | 6 +- .../generation/PDRblockMesh/PDRblockMesh.C | 6 +- .../mesh/generation/blockMesh/blockMesh.C | 6 +- .../foamyHexMeshBackgroundMesh.C | 4 +- .../mesh/manipulation/autoPatch/autoPatch.C | 4 +- .../manipulation/createPatch/createPatch.C | 4 +- .../manipulation/flattenMesh/flattenMesh.C | 4 +- .../mesh/manipulation/mirrorMesh/mirrorMesh.C | 6 +- .../mesh/manipulation/rotateMesh/rotateMesh.C | 6 +- .../mesh/manipulation/stitchMesh/stitchMesh.C | 6 +- .../transformPoints/transformPoints.C | 7 +-- .../decomposePar/domainDecomposition.C | 6 +- .../reconstructParMesh/reconstructParMesh.C | 2 +- .../redistributePar/redistributePar.C | 6 +- .../chemkinToFoam/chemkinToFoam.C | 6 +- .../db/IOstreams/IOstreams/IOstream.H | 16 ++++- .../db/IOstreams/Pstreams/PstreamBuffers.C | 2 +- .../db/IOstreams/Pstreams/UOPstreamBase.C | 4 +- src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C | 62 +++++++------------ src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H | 32 ++++++---- src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H | 16 ++--- src/OpenFOAM/db/IOstreams/token/token.H | 17 ++++- src/OpenFOAM/db/IOstreams/token/tokenI.H | 43 ++++++++++--- src/OpenFOAM/db/IOstreams/token/tokenIO.C | 11 ++++ .../dictionaryEntry/dictionaryEntry.C | 3 +- .../dictionaryListEntry/dictionaryListEntry.H | 1 - src/OpenFOAM/db/dictionary/entry/entry.H | 36 ++++------- .../functionEntries/evalEntry/evalEntry.C | 2 +- .../primitiveEntry/primitiveEntry.C | 10 ++- .../primitiveEntry/primitiveEntry.H | 5 +- .../primitiveEntry/primitiveEntryIO.C | 8 +-- .../PDRblockMesh/PDRblockBlockMesh.C | 6 +- .../faDecompose/faMeshDecomposition.C | 4 +- 51 files changed, 271 insertions(+), 207 deletions(-) diff --git a/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C b/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C index 2d96b0d1b5..21be51ee46 100644 --- a/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C +++ b/applications/utilities/finiteArea/makeFaMesh/makeFaMesh.C @@ -155,8 +155,8 @@ int main(int argc, char *argv[]) } else { - // Set the precision of the points data to 10 - IOstream::defaultPrecision(10); + // More precision (for points data) + IOstream::minPrecision(10); Info<< nl << "Write finite area mesh." << nl; aMesh.write(); diff --git a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C index 7d1db05860..6aa76e6653 100644 --- a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C +++ b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -551,9 +551,13 @@ void subsetMesh Info<< "Writing refined mesh to time " << runTime.timeName() << nl << endl; - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + const auto oldPrec = IOstream::minPrecision(10); + mesh.write(); refLevel.write(); + + IOstream::defaultPrecision(oldPrec); } // Update cutCells for removed cells. @@ -922,9 +926,13 @@ int main(int argc, char *argv[]) Info<< " Writing refined mesh to time " << runTime.timeName() << nl << endl; - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + const auto oldPrec = IOstream::minPrecision(10); + mesh.write(); refLevel.write(); + + IOstream::defaultPrecision(oldPrec); } // Update mesh edge stats. @@ -993,20 +1001,29 @@ int main(int argc, char *argv[]) << endl; // Write final mesh - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + + // More precision (for points data) + const auto oldPrec = IOstream::minPrecision(10); + mesh.write(); refLevel.write(); + IOstream::defaultPrecision(oldPrec); } else if (!writeMesh) { + // Write final mesh. (will have been written already if writeMesh=true) + Info<< "Writing refined mesh to time " << runTime.timeName() << nl << endl; - // Write final mesh. (will have been written already if writeMesh=true) - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + const auto oldPrec = IOstream::minPrecision(10); + mesh.write(); refLevel.write(); + + IOstream::defaultPrecision(oldPrec); } diff --git a/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L b/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L index 715a9a17e6..5838ed309f 100644 --- a/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L +++ b/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -704,8 +704,8 @@ int main(int argc, char *argv[]) } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing polyMesh" << endl; pShapeMesh.removeFiles(); diff --git a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C index 677da42c09..ac147c740b 100644 --- a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C +++ b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -198,8 +198,8 @@ int main(int argc, char *argv[]) : IOstreamOption::BINARY ); - // Increase the precision of the points data - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); // Read control options diff --git a/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C b/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C index 536e7dd8a9..c8294f55be 100644 --- a/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C +++ b/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -756,8 +756,8 @@ int main(int argc, char *argv[]) defaultFacesType ); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing polyMesh" << endl; pShapeMesh.removeFiles(); diff --git a/applications/utilities/mesh/conversion/ensightToFoam/ensightToFoam.C b/applications/utilities/mesh/conversion/ensightToFoam/ensightToFoam.C index dd9ce8ced9..a218198dc3 100644 --- a/applications/utilities/mesh/conversion/ensightToFoam/ensightToFoam.C +++ b/applications/utilities/mesh/conversion/ensightToFoam/ensightToFoam.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022 OpenCFD Ltd. + Copyright (C) 2022-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -90,8 +90,8 @@ int main(int argc, char *argv[]) argList args(argc, argv); Time runTime(args.rootPath(), args.caseName()); - // Increase the precision of the points data - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); const fileName geomFile(args.get(1)); diff --git a/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C b/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C index ed4a1de4ee..0f6877096a 100644 --- a/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C +++ b/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -97,8 +97,8 @@ int main(int argc, char *argv[]) : IOstreamOption::BINARY ); - // increase the precision of the points data - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); fileFormats::FIREMeshReader reader diff --git a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L index f46d9c2b86..7e0686d064 100644 --- a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L +++ b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016,2022 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1430,8 +1430,8 @@ int main(int argc, char *argv[]) mesh.setInstance(runTime.constant()); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< nl << "Writing mesh to " << mesh.objectPath() << endl; mesh.write(); diff --git a/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L b/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L index d8e193f9a4..d74f4ab01c 100644 --- a/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L +++ b/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1550,8 +1550,8 @@ int main(int argc, char *argv[]) repatcher.repatch(); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); // Re-do face matching to write sets diff --git a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L index 7d038faf49..c29bff53e5 100644 --- a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L +++ b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -868,8 +868,8 @@ int main(int argc, char *argv[]) defaultFacesType ); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing polyMesh" << endl; pShapeMesh.removeFiles(); diff --git a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C index b4f6e8d6fe..7ebeeca51d 100644 --- a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C +++ b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C @@ -1691,8 +1691,8 @@ int main(int argc, char *argv[]) repatcher.changePatches(newPatches); } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); mesh.write(); diff --git a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C index 2c3ca71f09..cfc923bcf3 100644 --- a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C +++ b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C @@ -1268,8 +1268,8 @@ int main(int argc, char *argv[]) Info << endl; } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); mesh.write(); diff --git a/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H b/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H index 3aabf9614a..9c85e36c01 100644 --- a/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H +++ b/applications/utilities/mesh/conversion/kivaToFoam/readKivaGrid.H @@ -569,8 +569,8 @@ polyMesh pShapeMesh defaultFacesType ); -// Set the precision of the points data to 10 -IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); +// More precision (for points data) +IOstream::minPrecision(10); Info << "Writing polyMesh" << endl; pShapeMesh.removeFiles(); diff --git a/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C b/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C index 2da335492b..45246a242c 100644 --- a/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C +++ b/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -161,8 +161,8 @@ int main(int argc, char *argv[]) wordList() ); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing mesh ..." << endl; diff --git a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C index 1b29209c13..c9cbabe10b 100644 --- a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C +++ b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -318,8 +318,8 @@ int main(int argc, char *argv[]) patchPhysicalTypes ); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing mesh ..." << endl; mesh.removeFiles(); diff --git a/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C b/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C index 840a847a62..681919ce9a 100644 --- a/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C +++ b/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -264,8 +264,8 @@ int main(int argc, char *argv[]) patchPhysicalTypes ); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing polyMesh" << endl; pShapeMesh.removeFiles(); diff --git a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C index 41d4e2b08e..e486173ac8 100644 --- a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C +++ b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,8 +103,8 @@ int main(int argc, char *argv[]) : IOstreamOption::BINARY ); - // Increase the precision of the points data - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); // Remove extensions and/or trailing '.' diff --git a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C index 152eb1e8be..6726474de9 100644 --- a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C +++ b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C @@ -542,8 +542,8 @@ int main(int argc, char *argv[]) ); } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing mesh to " << runTime.constant() << endl << endl; diff --git a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C index cb8f557734..cdc97fab33 100644 --- a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C +++ b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -88,8 +88,8 @@ int main(int argc, char *argv[]) wordList() ); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing mesh ..." << endl; diff --git a/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C b/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C index f6907cad1c..deff3eda0b 100644 --- a/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C +++ b/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -231,8 +231,8 @@ int main(int argc, char *argv[]) polyMesh& mesh = *meshPtr; - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< nl << "Writing polyMesh with " << mesh.cellZones().size() << " cellZones" << endl; diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C index a09d631fd5..1c8aeec6f8 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -289,8 +289,8 @@ int main(int argc, char *argv[]) // Handle cyclic patches #include "handleCyclicPatches.H" - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< nl << "Writing polyMesh with " << mesh.cellZones().size() << " cellZones"; diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C index 3ac559c82a..359c7f2213 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C @@ -67,8 +67,8 @@ scalar getMergeDistance const scalar mergeTol = args.getOrDefault("mergeTol", defaultMergeTol); - scalar writeTol = - Foam::pow(scalar(10), -scalar(IOstream::defaultPrecision())); + const scalar writeTol = + std::pow(scalar(10), -scalar(IOstream::defaultPrecision())); Info<< "Merge tolerance : " << mergeTol << nl << "Write tolerance : " << writeTol << endl; diff --git a/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C b/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C index d9a3c2d438..4a14a22348 100644 --- a/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C +++ b/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C @@ -269,8 +269,8 @@ int main(int argc, char *argv[]) mesh.setInstance(oldInstance); } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); mesh.write(); diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C index 545fe26f84..0eb33b5b9b 100644 --- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C +++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C @@ -1456,8 +1456,8 @@ int main(int argc, char *argv[]) } } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); // Write resulting mesh forAll(meshes, meshi) diff --git a/applications/utilities/mesh/manipulation/flattenMesh/flattenMesh.C b/applications/utilities/mesh/manipulation/flattenMesh/flattenMesh.C index c9fe1967d8..375b770969 100644 --- a/applications/utilities/mesh/manipulation/flattenMesh/flattenMesh.C +++ b/applications/utilities/mesh/manipulation/flattenMesh/flattenMesh.C @@ -100,8 +100,8 @@ int main(int argc, char *argv[]) twoDCorr.correctPoints(points); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing points into directory " << points.path() << nl << endl; points.write(); diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C index 126a03e2a9..6031268487 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C +++ b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -101,8 +101,8 @@ int main(int argc, char *argv[]) } - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); // Generate the mirrorred mesh const fvMesh& mMesh = mesh.mirrorMesh(); diff --git a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C index 2106a2b1cf..0d6711cbf2 100644 --- a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C +++ b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -153,8 +153,8 @@ int main(int argc, char *argv[]) points = transform(rotT, points); - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing points into directory " << runTime.relativePath(points.path()) << nl diff --git a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C index 15dd2c3043..8f0ea89dc2 100644 --- a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C +++ b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -440,8 +440,8 @@ int main(int argc, char *argv[]) //PtrList surfaceTensorFields; //ReadFields(mesh, objects, surfaceTensorFields); - // Increase precision for output mesh points - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); polyTopoChanger stitcher(mesh, IOobject::NO_READ); diff --git a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C index c339fde851..e167520266 100644 --- a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C +++ b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -552,9 +552,8 @@ int main(int argc, char *argv[]) // Output scaling applyScaling(points, getScalingOpt("scale", args)); - - // Set the precision of the points data to 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); Info<< "Writing points into directory " << runTime.relativePath(points.path()) << nl diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C index 44526285c7..2158e2a19e 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -735,8 +735,8 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets) } } - // Set the precision of the points data to be min 10 - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); procMesh.write(); diff --git a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C index eb844f5779..bd7cfdd056 100644 --- a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C +++ b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C @@ -657,7 +657,7 @@ int main(int argc, char *argv[]) if (fullMatch || procMatch) { const scalar writeTol = - Foam::pow(10.0, -scalar(IOstream::defaultPrecision())); + std::pow(scalar(10), -scalar(IOstream::defaultPrecision())); Info<< "Merge tolerance : " << mergeTol << nl << "Write tolerance : " << writeTol << endl; diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 41c45095bb..23d62c2652 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2023 OpenCFD Ltd. + Copyright (C) 2015-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -951,8 +951,8 @@ autoPtr redistributeAndWrite } - // Set the minimum write precision - IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); + // More precision (for points data) + IOstream::minPrecision(10); if (!overwrite) diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C index e248c45c97..5d30a193e8 100644 --- a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C +++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,8 +47,8 @@ using namespace Foam; int main(int argc, char *argv[]) { - // Increase the precision of the output for JANAF coefficients - Ostream::defaultPrecision(10); + // More precision (for output of JANAF coefficients) + IOstream::minPrecision(10); argList::addNote ( diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index 5f5ecc8a94..01546afc1b 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -349,7 +349,7 @@ public: } //- Reset the default precision - // \return the previous value + // \return the previous default precision static unsigned int defaultPrecision(unsigned int prec) noexcept { unsigned int old(precision_); @@ -357,6 +357,18 @@ public: return old; } + //- Set the minimum default precision + // \return the previous default precision + static unsigned int minPrecision(unsigned int prec) noexcept + { + unsigned int old(precision_); + if (precision_ < prec) + { + precision_ = prec; + } + return old; + } + //- Set stream state as reached 'eof' void setEof() noexcept { @@ -370,7 +382,7 @@ public: } //- Set stream state to be 'bad' - void setBad() + void setBad() noexcept { ioState_ |= std::ios_base::badbit; } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C index 1949e7904c..37459b1abd 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C @@ -563,7 +563,7 @@ Foam::label Foam::PstreamBuffers::maxNonLocalRecvCount if (excludeProci != proci) { label len(recvBuffers_[proci].size() - recvPositions_[proci]); - maxLen = max(maxLen, len); + maxLen = Foam::max(maxLen, len); } } } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C index d969c7a08c..e07c5320e8 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C @@ -67,7 +67,7 @@ inline void Foam::UOPstreamBase::prepareBuffer const label pos = byteAlign(sendBuf_.size(), align); // Extend buffer (as required) - sendBuf_.reserve(max(1000, label(pos + count))); + sendBuf_.reserve(Foam::max(label(1024), label(pos + count))); // Move to the aligned output position. Fill any gap with nul char. sendBuf_.resize(pos, '\0'); @@ -115,7 +115,7 @@ inline void Foam::UOPstreamBase::putChar(const char c) { if (!sendBuf_.capacity()) { - sendBuf_.setCapacity(1000); + sendBuf_.setCapacity(1024); } sendBuf_.push_back(c); } diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C index 618bbf3bc9..66c2125e83 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,7 +55,7 @@ static label parseStream(ISstream& is, tokenList& tokens) if (count >= tokens.size()) { // Increase capacity (doubling) with min-size [64] - tokens.resize(max(label(64), 2*tokens.size())); + tokens.resize(Foam::max(label(64), label(2*tokens.size()))); } tokens[count] = std::move(tok); @@ -77,7 +77,7 @@ Foam::ITstream& Foam::ITstream::empty_stream() if (emptyStreamPtr_) { emptyStreamPtr_->ITstream::clear(); // Ensure it really is empty - emptyStreamPtr_->ITstream::seek(0); // rewind(), but bypasss virtual + emptyStreamPtr_->ITstream::seek(0); // rewind() bypassing virtual } else { @@ -113,7 +113,7 @@ void Foam::ITstream::reset(const char* input, size_t nbytes) ISpanStream is(input, nbytes, static_cast(*this)); parseStream(is, static_cast(*this)); - ITstream::seek(0); // rewind(), but bypasss virtual + ITstream::seek(0); // rewind() bypassing virtual } @@ -333,7 +333,7 @@ std::string Foam::ITstream::toString() const } -const Foam::token& Foam::ITstream::peek() const +const Foam::token& Foam::ITstream::peek() const noexcept { // Use putback token if it exists if (Istream::hasPutback()) @@ -359,45 +359,30 @@ Foam::token& Foam::ITstream::currentToken() } -void Foam::ITstream::seek(label pos) +void Foam::ITstream::seek(label pos) noexcept { lineNumber_ = 0; - const tokenList& toks = *this; - const label nToks = toks.size(); - if (!pos) - { - // Seek begin (rewind) - tokenIndex_ = 0; - - if (nToks) - { - lineNumber_ = toks.front().lineNumber(); - } - - setOpened(); - setGood(); - } - else if (pos < 0 || pos >= nToks) + if (pos < 0 || pos >= tokenList::size()) { // Seek end (-1) or seek is out of range - tokenIndex_ = nToks; + tokenIndex_ = tokenList::size(); - if (nToks) + if (!tokenList::empty()) { - lineNumber_ = toks.back().lineNumber(); + // The closest reference lineNumber + lineNumber_ = tokenList::cdata()[tokenIndex_-1].lineNumber(); } setEof(); } else { - // Seek middle (from the beginning) tokenIndex_ = pos; - if (nToks) + if (tokenIndex_ < tokenList::size()) { - lineNumber_ = toks[tokenIndex_].lineNumber(); + lineNumber_ = tokenList::cdata()[tokenIndex_].lineNumber(); } setOpened(); @@ -406,7 +391,7 @@ void Foam::ITstream::seek(label pos) } -bool Foam::ITstream::skip(label n) +bool Foam::ITstream::skip(label n) noexcept { if (!n) { @@ -433,14 +418,14 @@ bool Foam::ITstream::skip(label n) if (!tokenList::empty()) { // The closest reference lineNumber - lineNumber_ = tokenList::back().lineNumber(); + lineNumber_ = tokenList::cdata()[tokenIndex_-1].lineNumber(); } } // Update stream information if (tokenIndex_ < tokenList::size()) { - lineNumber_ = tokenList::operator[](tokenIndex_).lineNumber(); + lineNumber_ = tokenList::cdata()[tokenIndex_].lineNumber(); setOpened(); setGood(); } @@ -585,7 +570,8 @@ Foam::ITstream Foam::ITstream::extract(const labelRange& range) // Move tokens into result list std::move(first, last, result.begin()); - result.seek(0); // rewind + result.seek(0); // rewind() bypassing virtual + (void) remove(slice); // Adjust the original list @@ -708,12 +694,6 @@ Foam::Istream& Foam::ITstream::read(char*, std::streamsize) } -void Foam::ITstream::rewind() -{ - ITstream::seek(0); -} - - void Foam::ITstream::add_tokens(const token& tok) { reserveCapacity(tokenIndex_ + 1); @@ -763,7 +743,7 @@ void Foam::ITstream::operator=(const ITstream& is) Istream::operator=(is); tokenList::operator=(is); name_ = is.name_; - ITstream::seek(0); // rewind(), but bypasss virtual + ITstream::seek(0); // rewind() bypassing virtual } } @@ -771,14 +751,14 @@ void Foam::ITstream::operator=(const ITstream& is) void Foam::ITstream::operator=(const UList& toks) { tokenList::operator=(toks); - ITstream::seek(0); // rewind(), but bypasss virtual + ITstream::seek(0); // rewind() bypassing virtual } void Foam::ITstream::operator=(List&& toks) { tokenList::operator=(std::move(toks)); - ITstream::seek(0); // rewind(), but bypasss virtual + ITstream::seek(0); // rewind() bypassing virtual } diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index 480878bd37..46c61e9084 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -91,12 +91,12 @@ class ITstream //- Failsafe read-access to token at specified location //- or undefinedToken - inline const token& peekNoFail(const label i) const + inline const token& peekNoFail(const label i) const noexcept { return ( (i >= 0 && i < tokenList::size()) - ? tokenList::operator[](i) + ? tokenList::cdata()[i] : token::undefinedToken ); } @@ -353,20 +353,29 @@ public: //- Failsafe peek at the token at the \b front of the tokenList // \return \c undefinedToken if the list is empty. - const token& front() const { return peekNoFail(0); } + const token& front() const noexcept + { + return peekNoFail(0); + } //- Failsafe peek at the token at the \b back of the tokenList // \return \c undefinedToken if the list is empty. - const token& back() const { return peekNoFail(tokenList::size()-1); } + const token& back() const noexcept + { + return peekNoFail(tokenList::size()-1); + } //- Failsafe peek at what the next read would return, //- including handling of any putback // \return \c undefinedToken if list is exhausted - const token& peek() const; + const token& peek() const noexcept; //- Read access to the token at the current tokenIndex. //- \returns \c undefinedToken if list is exhausted - const token& currentToken() const { return peekNoFail(tokenIndex_); } + const token& currentToken() const noexcept + { + return peekNoFail(tokenIndex_); + } //- Write access to the token at the current tokenIndex. //- Fatal if not in range @@ -397,9 +406,10 @@ public: } //- Move tokenIndex to the specified position - // Using seek(0) is identical to rewind. + //- and adjust the stream status (open/good/eof ...) + // Using seek(0) is identical to rewind(). // Using seek(-1) moves to the end. - void seek(label pos); + void seek(label pos) noexcept; //- Move tokenIndex relative to the current position. // Will not overrun the beginning (0) or one-past end positions. @@ -407,7 +417,7 @@ public: // Use skip(2) to move forward two tokens. // Use skip(-2) to move backward two tokens. // \return True if the indexing completed without underflow/overflow - bool skip(label n = 1); + bool skip(label n = 1) noexcept; // Searching @@ -525,7 +535,7 @@ public: virtual bool endRawRead() override { return false; } //- Rewind the stream so that it may be read again. Same as seek(0) - virtual void rewind() override; + virtual void rewind() override { ITstream::seek(0); } // Output diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H index f50d30308e..1be6555640 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -249,20 +249,20 @@ public: // Other + //- Rewind the output stream to position 0 (non-virtual!) + //- and adjust the stream status (open/good/eof ...) //- Reset the output buffer and rewind the stream - void reset() - { - this->rewind(); - } - - //- Rewind the output stream - virtual void rewind() + void reset() noexcept { DynamicList::clear(); setOpened(); setGood(); } + //- Rewind the output stream to position 0 + //- and adjust the stream status (open/good/eof ...) + virtual void rewind() { OTstream::reset(); } + //- Print stream description to Ostream void print(Ostream& os) const override; diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 07180d1050..c4d40e3279 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -279,6 +279,9 @@ public: //- of the underlying data content virtual direction nComponents() const = 0; + //- The vector-space rank associated with the data content + virtual direction rank() const = 0; + //- Pointer to the underlying data as byte data virtual const char* cdata_bytes() const = 0; @@ -419,6 +422,12 @@ public: return pTraits_nComponents(); } + //- The vector-space rank associated with the data content + virtual direction rank() const + { + return pTraits_rank(); + } + //- Pointer to the underlying data as byte data virtual const char* cdata_bytes() const { @@ -474,7 +483,7 @@ private: //- The token type tokenType type_; - //- Line number in the file the token was read from + //- The file line number where the token was read from label line_; @@ -516,6 +525,8 @@ public: inline explicit token(punctuationToken p, label lineNum=0) noexcept; //- Construct label token + //- \note Use boolean() static method for creating a \b bool token + //- since \c bool and \c int are otherwise indistinguishable inline explicit token(const label val, label lineNum=0) noexcept; //- Construct float token @@ -635,7 +646,7 @@ public: inline bool isLabel() const noexcept; //- True if token is LABEL and equal to parameter - inline bool isLabel(const label val) const noexcept; + inline bool isLabel(const label value) const noexcept; //- Token is FLOAT inline bool isFloat() const noexcept; diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index 9476b7e77c..95b52207eb 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -604,17 +604,35 @@ inline Foam::token::punctuationToken Foam::token::pToken() const inline bool Foam::token::isLabel() const noexcept -{ - return (type_ == tokenType::LABEL); -} - - -inline bool Foam::token::isLabel(const label val) const noexcept { return ( type_ == tokenType::LABEL - && data_.labelVal == val + // FUTURE? + // || type_ == tokenType::INT32 + // || type_ == tokenType::INT64 + ); +} + + +inline bool Foam::token::isLabel(const label value) const noexcept +{ + // FUTURE? + // return + // ( + // type_ == tokenType::LABEL + // ? value == data_.labelVal + // : type_ == tokenType::INT32 + // ? value == data_.int32Val + // : type_ == tokenType::INT64 + // ? value == data_.int64Val + // : false + // ); + + return + ( + type_ == tokenType::LABEL + && value == data_.labelVal ); } @@ -695,7 +713,7 @@ inline Foam::scalar Foam::token::scalarToken() const inline bool Foam::token::isNumber() const noexcept { - return (type_ == tokenType::LABEL || isScalar()); + return (isLabel() || isScalar()); } @@ -894,6 +912,15 @@ Foam::token::tokenType Foam::token::Compound::typeCode() const { // List