diff --git a/applications/test/CompactIOList/Test-CompactIOList.C b/applications/test/CompactIOList/Test-CompactIOList.C index 80b8cb4a90e1a482bd685ad4beeb28987c5e5a3a..9e5b40e9b14e9fa41666a6e962b0f6ff913a1db9 100644 --- a/applications/test/CompactIOList/Test-CompactIOList.C +++ b/applications/test/CompactIOList/Test-CompactIOList.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,8 +49,8 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" - IOstream::streamFormat format=IOstream::BINARY; - // IOstream::streamFormat format=IOstream::ASCII; + IOstream::streamFormat format = IOstream::BINARY; + // IOstream::streamFormat format = IOstream::ASCII; const label size = 20000000; @@ -84,12 +85,9 @@ int main(int argc, char *argv[]) << runTime.cpuTimeIncrement() << " s" << nl << endl; - // Write binary faces2.writeObject ( - format, - IOstream::currentVersion, - IOstream::UNCOMPRESSED, + IOstreamOption(format), true ); @@ -147,12 +145,9 @@ int main(int argc, char *argv[]) << runTime.cpuTimeIncrement() << " s" << nl << endl; - // Write binary faces2.writeObject ( - format, - IOstream::currentVersion, - IOstream::UNCOMPRESSED, + IOstreamOption(format), true ); diff --git a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C index 7ad7a637c72f7b910f251c951137e87e1fcb581f..82ca4d6183b95c82980f71ba9f7662bdc88f082b 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 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -643,9 +643,11 @@ int main(int argc, char *argv[]) ( !runTime.objectRegistry::writeObject ( - runTime.writeFormat(), - IOstream::currentVersion, - runTime.writeCompression(), + IOstreamOption + ( + runTime.writeFormat(), + runTime.writeCompression() + ), true ) ) diff --git a/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C b/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C index c8cf9b6a50691a4750d9d1e756651903dd0212f5..f9e5ccebf457802267cd4d90b77fe03d4d60ab4e 100644 --- a/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C +++ b/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -157,12 +157,10 @@ bool writeZones Info<< " Writing " << name << endl; - // Force writing as ascii + // Force writing as ASCII writeOk = meshObject.regIOobject::writeObject ( - IOstream::ASCII, - IOstream::currentVersion, - compression, + IOstreamOption(IOstream::ASCII, compression), true ); } @@ -471,9 +469,11 @@ int main(int argc, char *argv[]) parcels.writeObject ( - runTime.writeFormat(), - IOstream::currentVersion, - runTime.writeCompression(), + IOstreamOption + ( + runTime.writeFormat(), + runTime.writeCompression() + ), parcels.size() ); diff --git a/applications/utilities/parallelProcessing/redistributePar/unmappedPassivePositionParticleCloud.H b/applications/utilities/parallelProcessing/redistributePar/unmappedPassivePositionParticleCloud.H index f15e00e11a80c7b072f535cb2858f7007f7a4acb..74cc738f15a10733ebb41105b8a49a6e8e9f3e70 100644 --- a/applications/utilities/parallelProcessing/redistributePar/unmappedPassivePositionParticleCloud.H +++ b/applications/utilities/parallelProcessing/redistributePar/unmappedPassivePositionParticleCloud.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -93,14 +93,8 @@ public: virtual void autoMap(const mapPolyMesh&) {} - //- Switch off writing the objects - virtual bool writeObject - ( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, - const bool valid - ) const + //- Disable writing objects + virtual bool writeObject(IOstreamOption, const bool valid) const { return true; } diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index d7aa8fea6106a611d1a79dd0efdc6e8fa89e073d..28e784339ddd9d5e333e319f31197f9da9c0d018 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -660,9 +660,7 @@ int main(int argc, char *argv[]) Info<< "Writing modified " << fieldName << endl; dictList.writeObject ( - runTime.writeFormat(), - IOstream::currentVersion, - IOstream::UNCOMPRESSED, + IOstreamOption(runTime.writeFormat()), true ); } diff --git a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C index b17b830497ac5ab07f085fa807e78248ec962905..fc70e5ccdb1cba523750059128248e4b51e34e8b 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C +++ b/applications/utilities/preProcessing/createZeroDirectory/createZeroDirectory.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation - Copyright (C) 2015-2017 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -199,9 +199,7 @@ void createFieldFiles fieldOut.regIOobject::writeObject ( - IOstream::ASCII, - IOstream::currentVersion, - IOstream::UNCOMPRESSED, + IOstreamOption(IOstream::ASCII), true ); } diff --git a/applications/utilities/preProcessing/optimisation/writeActiveDesignVariables/writeActiveDesignVariables.C b/applications/utilities/preProcessing/optimisation/writeActiveDesignVariables/writeActiveDesignVariables.C index 2eae081bb0f18aa3acc82fa6c647cd78b4b6dc11..0ea8df485df7413e680ee5c80dcd578e40f35626 100644 --- a/applications/utilities/preProcessing/optimisation/writeActiveDesignVariables/writeActiveDesignVariables.C +++ b/applications/utilities/preProcessing/optimisation/writeActiveDesignVariables/writeActiveDesignVariables.C @@ -7,7 +7,7 @@ ------------------------------------------------------------------------------- Copyright (C) 2007-2019 PCOpt/NTUA Copyright (C) 2013-2019 FOSS GP - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -95,9 +95,7 @@ int main(int argc, char *argv[]) // Write modified dictionary optDict.regIOobject::writeObject ( - IOstream::ASCII, - IOstream::currentVersion, - IOstream::UNCOMPRESSED, + IOstreamOption(IOstream::ASCII), true ); diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C index c7ab9b7ac9a5bd81ada0429e31945926fc7987eb..027ccc53eaf472730daa11631bf72ebdf360e9fc 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -175,28 +175,26 @@ Foam::CompactIOField::CompactIOField template bool Foam::CompactIOField::writeObject ( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool valid ) const { - if (fmt == IOstream::ASCII) + if (streamOpt.format() == IOstream::ASCII) { // Change type to be non-compact format type const word oldTypeName(typeName); const_cast(typeName) = IOField::typeName; - bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp, valid); + bool good = regIOobject::writeObject(streamOpt, valid); - // Change type back + // Restore type const_cast(typeName) = oldTypeName; return good; } - return regIOobject::writeObject(fmt, ver, cmp, valid); + return regIOobject::writeObject(streamOpt, valid); } diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H index c1b0929250da8273a6c6bb354a4bc82c2d2bd144..09b6fb943fe3921a5ca8a6344c74934414b66036 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -112,11 +113,10 @@ public: // Member Functions + //- Write using stream options virtual bool writeObject ( - IOstream::streamFormat, - IOstream::versionNumber, - IOstream::compressionType, + IOstreamOption streamOpt, const bool valid ) const; diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C index cfd3507fca2653df6cae956057c9c8cf37c59df8..a614641777d9e5f44a9ff8b9a22b8eb2c6b196df 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -168,21 +168,17 @@ Foam::CompactIOList::CompactIOList template bool Foam::CompactIOList::writeObject ( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool valid ) const { - bool nonCompact = false; - - if (fmt == IOstream::ASCII) - { - nonCompact = true; - } - else if (overflows()) + if + ( + streamOpt.format() == IOstream::BINARY + && overflows() + ) { - nonCompact = true; + streamOpt.format(IOstream::ASCII); WarningInFunction << "Overall number of elements of CompactIOList of size " @@ -190,14 +186,14 @@ bool Foam::CompactIOList::writeObject << nl << " Switching to ascii writing" << endl; } - if (nonCompact) + if (streamOpt.format() == IOstream::ASCII) { - // Change to non-compact type + // Change type to be non-compact format type const word oldTypeName(typeName); const_cast(typeName) = IOList::typeName; - bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp, valid); + bool good = regIOobject::writeObject(streamOpt, valid); // Change type back const_cast(typeName) = oldTypeName; @@ -205,7 +201,7 @@ bool Foam::CompactIOList::writeObject return good; } - return regIOobject::writeObject(fmt, ver, cmp, valid); + return regIOobject::writeObject(streamOpt, valid); } diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H index 66630ee1b3ad0ddbf1862681e3902a7e280cd7fe..555114418bb13fb3eaf8a023446df5b3845e940d 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -114,11 +114,10 @@ public: // Member Functions + //- Write using stream options. Checks for overflow in binary virtual bool writeObject ( - IOstream::streamFormat, - IOstream::versionNumber, - IOstream::compressionType, + IOstreamOption streamOpt, const bool valid ) const; diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index 66653071d32a976979c179cbb3e772bb81db439d..24e190d79e654a25ed1a0ad0c2aa4d39abdb95e6 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017-2018 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +31,6 @@ License #include "IPstream.H" #include "PstreamBuffers.H" #include "Fstream.H" -#include "StringStream.H" #include "dictionary.H" #include "objectRegistry.H" #include "SubList.H" @@ -160,12 +160,6 @@ Foam::decomposedBlockData::decomposedBlockData } -// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // - -Foam::decomposedBlockData::~decomposedBlockData() -{} - - // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * // bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is) @@ -181,15 +175,11 @@ bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is) List data(is); is.fatalCheck("read(Istream&) : reading entry"); - IListStream str - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - is.name() - ); - return io.readHeader(str); + UIListStream headerStream(data); + headerStream.name() = is.name(); + + return io.readHeader(headerStream); } @@ -254,24 +244,15 @@ Foam::autoPtr Foam::decomposedBlockData::readBlock is.fatalCheck("read(Istream&)"); - List data; autoPtr realIsPtr; if (blocki == 0) { - is >> data; + List data(is); is.fatalCheck("read(Istream&) : reading entry"); - realIsPtr.reset - ( - new IListStream - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - is.name() - ) - ); + realIsPtr.reset(new IListStream(std::move(data))); + realIsPtr->name() = is.name(); // Read header if (!headerIO.readHeader(realIsPtr())) @@ -284,7 +265,7 @@ Foam::autoPtr Foam::decomposedBlockData::readBlock else { // Read master for header - is >> data; + List data(is); is.fatalCheck("read(Istream&) : reading entry"); IOstream::versionNumber ver(IOstream::currentVersion); @@ -292,13 +273,7 @@ Foam::autoPtr Foam::decomposedBlockData::readBlock unsigned labelByteSize; unsigned scalarByteSize; { - UIListStream headerStream - ( - data, - IOstream::ASCII, - IOstream::currentVersion, - is.name() - ); + UIListStream headerStream(data); // Read header if (!headerIO.readHeader(headerStream)) @@ -315,20 +290,12 @@ Foam::autoPtr Foam::decomposedBlockData::readBlock for (label i = 1; i < blocki+1; i++) { - // Read data, override old data + // Read and discard data, only retain the last one is >> data; is.fatalCheck("read(Istream&) : reading entry"); } - realIsPtr.reset - ( - new IListStream - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - is.name() - ) - ); + realIsPtr.reset(new IListStream(std::move(data))); + realIsPtr->name() = is.name(); // Apply master stream settings to realIsPtr realIsPtr().format(fmt); @@ -336,6 +303,7 @@ Foam::autoPtr Foam::decomposedBlockData::readBlock realIsPtr().setLabelByteSize(labelByteSize); realIsPtr().setScalarByteSize(scalarByteSize); } + return realIsPtr; } @@ -358,22 +326,6 @@ bool Foam::decomposedBlockData::readBlocks bool ok = false; - - - //// Scatter master header info - //string ver; - //unsigned labelByteSize; - //unsigned scalarByteSize; - //if (UPstream::master(comm)) - //{ - // ver = isPtr().version().str(); - // labelByteSize = isPtr().labelByteSize(); - // scalarByteSize = isPtr().scalarByteSize(); - //} - //Pstream::scatter(ver); //, Pstream::msgType(), comm); - //Pstream::scatter(labelByteSize); //, Pstream::msgType(), comm); - //Pstream::scatter(scalarByteSize); //, Pstream::msgType(), comm); - if (commsType == UPstream::commsTypes::scheduled) { if (UPstream::master(comm)) @@ -509,17 +461,8 @@ Foam::autoPtr Foam::decomposedBlockData::readBlocks is >> data; is.fatalCheck("read(Istream&) : reading entry"); - realIsPtr.reset - ( - new IListStream - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - fName - ) - ); - + realIsPtr.reset(new IListStream(std::move(data))); + realIsPtr->name() = fName; // Read header if (!headerIO.readHeader(realIsPtr())) @@ -566,16 +509,8 @@ Foam::autoPtr Foam::decomposedBlockData::readBlocks ); is >> data; - realIsPtr.reset - ( - new IListStream - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - fName - ) - ); + realIsPtr.reset(new IListStream(std::move(data))); + realIsPtr->name() = fName; } } else @@ -597,16 +532,8 @@ Foam::autoPtr Foam::decomposedBlockData::readBlocks is >> data; is.fatalCheck("read(Istream&) : reading entry"); - realIsPtr.reset - ( - new IListStream - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - fName - ) - ); + realIsPtr.reset(new IListStream(std::move(data))); + realIsPtr->name() = fName; // Read header if (!headerIO.readHeader(realIsPtr())) @@ -643,16 +570,8 @@ Foam::autoPtr Foam::decomposedBlockData::readBlocks UIPstream is(UPstream::masterNo(), pBufs); is >> data; - realIsPtr.reset - ( - new IListStream - ( - std::move(data), - IOstream::ASCII, - IOstream::currentVersion, - fName - ) - ); + realIsPtr.reset(new IListStream(std::move(data))); + realIsPtr->name() = fName; } } @@ -661,26 +580,24 @@ Foam::autoPtr Foam::decomposedBlockData::readBlocks //- Set stream properties from realIsPtr on master // Scatter master header info - string ver; - string format; + string versionString; + label formatValue; unsigned labelByteSize; unsigned scalarByteSize; if (UPstream::master(comm)) { - ver = realIsPtr().version().str(); - OStringStream os; - os << realIsPtr().format(); - format = os.str(); + versionString = realIsPtr().version().str(); + formatValue = static_cast