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]
This commit is contained in:
Mark Olesen 2024-02-29 09:40:42 +01:00
parent 5a70be0846
commit b98f53ceca
51 changed files with 271 additions and 207 deletions

View File

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

View File

@ -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);
}

View File

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

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

@ -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;

View File

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

View File

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

View File

@ -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 '.'

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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";

View File

@ -67,8 +67,8 @@ scalar getMergeDistance
const scalar mergeTol =
args.getOrDefault<scalar>("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;

View File

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

View File

@ -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)

View File

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

View File

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

View File

@ -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

View File

@ -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<surfaceTensorField> 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);

View File

@ -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

View File

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

View File

@ -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;

View File

@ -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<mapDistributePolyMesh> redistributeAndWrite
}
// Set the minimum write precision
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
// More precision (for points data)
IOstream::minPrecision(10);
if (!overwrite)

View File

@ -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
(

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -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<IOstreamOption>(*this));
parseStream(is, static_cast<tokenList&>(*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<token>& toks)
{
tokenList::operator=(toks);
ITstream::seek(0); // rewind(), but bypasss virtual
ITstream::seek(0); // rewind() bypassing virtual
}
void Foam::ITstream::operator=(List<token>&& toks)
{
tokenList::operator=(std::move(toks));
ITstream::seek(0); // rewind(), but bypasss virtual
ITstream::seek(0); // rewind() bypassing virtual
}

View File

@ -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

View File

@ -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<token>::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;

View File

@ -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<value_type>();
}
//- The vector-space rank associated with the data content
virtual direction rank() const
{
return pTraits_rank<value_type>();
}
//- 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;

View File

@ -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<T>::typeCode() const
{
// List<label>, List<labelVector> etc
return token::tokenType::LABEL;
// FUTURE?
// return
// (
// sizeof(int32_t) == sizeof(Foam::label)
// ? token::tokenType::INT32
// : token::tokenType::INT64
// );
}
else if (is_contiguous_scalar<valueType>::value)
{

View File

@ -57,6 +57,14 @@ static OS& printTokenInfo(OS& os, const token& tok)
os << "punctuation '" << tok.pToken() << '\'';
break;
// case token::tokenType::INT32:
// os << "int32 " << tok.int32Token();
// break;
//
// case token::tokenType::INT64:
// os << "int64 " << tok.int64Token();
// break;
case token::tokenType::LABEL:
os << "label " << tok.labelToken();
break;
@ -146,6 +154,9 @@ Foam::word Foam::token::name(const token::tokenType tokType)
case token::tokenType::BOOL: return "bool";
case token::tokenType::FLAG: return "flag";
case token::tokenType::PUNCTUATION: return "punctuation";
// case token::tokenType::INT32: return "int32";
// case token::tokenType::INT64: return "int64";
case token::tokenType::LABEL: return "label";
case token::tokenType::FLOAT: return "float";
case token::tokenType::DOUBLE: return "double";

View File

@ -70,7 +70,8 @@ Foam::label Foam::dictionaryEntry::endLineNumber() const
Foam::ITstream& Foam::dictionaryEntry::stream() const
{
FatalIOErrorInFunction(*this)
<< "Attempt to return dictionary entry as a primitive"
<< "Attempt to return stream of primitives from a dictionary entry: "
<< entry::keyword() << nl
<< abort(FatalIOError);
// Need to return something - send back an empty stream

View File

@ -37,7 +37,6 @@ Description
comment. Can be used to e.g. manipulate polyMesh/boundary files.
SourceFiles
dictionaryListEntry.C
dictionaryListEntryIO.C
\*---------------------------------------------------------------------------*/

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -193,16 +193,10 @@ public:
// Member Functions
//- Return keyword
const keyType& keyword() const noexcept
{
return keyword_;
}
const keyType& keyword() const noexcept { return keyword_; }
//- Return non-const access to keyword
keyType& keyword() noexcept
{
return keyword_;
}
keyType& keyword() noexcept { return keyword_; }
//- Return the entry name
virtual const fileName& name() const = 0;
@ -221,34 +215,26 @@ public:
//- Return true if this entry is a stream
virtual bool isStream() const noexcept
{
return false;
}
virtual bool isStream() const noexcept { return false; }
//- Return pointer to token stream, if entry is a primitive entry
// Return nullptr if the entry is not a primitive entry
virtual ITstream* streamPtr() const { return nullptr; }
//- Return token stream, if entry is a primitive entry
virtual ITstream& stream() const = 0;
//- Return true if this entry is a dictionary
virtual bool isDict() const noexcept
{
return this->dictPtr();
}
virtual bool isDict() const noexcept { return this->dictPtr(); }
//- Return pointer to dictionary, if entry is a dictionary.
// Return nullptr if the entry is not a dictionary.
virtual const dictionary* dictPtr() const noexcept
{
return nullptr;
}
virtual const dictionary* dictPtr() const noexcept { return nullptr; }
//- Return non-const pointer to dictionary, if entry is a dictionary
// Return nullptr if the entry is not a dictionary.
virtual dictionary* dictPtr() noexcept
{
return nullptr;
}
virtual dictionary* dictPtr() noexcept { return nullptr; }
//- Return dictionary, if entry is a dictionary
virtual const dictionary& dict() const = 0;

View File

@ -198,7 +198,7 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate
// - #eval INT "expr"
// - #eval INT { expr }
// - #eval INT #{ expr #}
fieldWidth = max(1, tok.labelToken());
fieldWidth = Foam::max(1, tok.labelToken());
is >> tok;
}

View File

@ -273,10 +273,18 @@ Foam::primitiveEntry::primitiveEntry
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::ITstream* Foam::primitiveEntry::streamPtr() const
{
ITstream* ptr = const_cast<primitiveEntry*>(this);
ptr->seek(0);
return ptr;
}
Foam::ITstream& Foam::primitiveEntry::stream() const
{
ITstream& is = const_cast<primitiveEntry&>(*this);
is.rewind();
is.seek(0);
return is;
}

View File

@ -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.
@ -187,6 +187,9 @@ public:
return true;
}
//- Return pointer to token stream for this primitive entry
virtual ITstream* streamPtr() const;
//- Return token stream for this primitive entry
virtual ITstream& stream() const;

View File

@ -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.
@ -333,16 +333,16 @@ Foam::Ostream& Foam::operator<<
e.print(os);
constexpr label nPrintTokens = 10;
const label nPrintTokens = Foam::min(label(10), label(e.size()));
os << " primitiveEntry '" << e.keyword() << "' comprises ";
for (label i=0; i<min(e.size(), nPrintTokens); ++i)
for (label i = 0; i < nPrintTokens; ++i)
{
os << nl << " " << e[i].info();
}
if (e.size() > nPrintTokens)
if (10 < e.size())
{
os << " ...";
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2023 OpenCFD Ltd.
Copyright (C) 2020-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -814,8 +814,8 @@ void Foam::PDRblock::writeBlockMeshDict(const IOobject& io) const
<< "Generate blockMeshDict: "
<< iodict.db().time().relativePath(os.name()) << endl;
// Set precision for points to 10
os.precision(max(10u, IOstream::defaultPrecision()));
// More precision (for points data)
os.precision(Foam::max(10u, IOstream::defaultPrecision()));
iodict.writeHeader(os);

View File

@ -1239,8 +1239,8 @@ bool Foam::faMeshDecomposition::writeDecomposition()
// Add boundary patches
procMesh.addFaPatches(procPatches);
// Set the precision of the points data to 10
IOstream::defaultPrecision(10);
// More precision (for points data)
IOstream::minPrecision(10);
procMesh.write();