diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index baa9a33541..1728aa9a91 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -80,20 +80,14 @@ Foam::Detail::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) Foam::IFstream::IFstream ( const fileName& pathname, - streamFormat format, - versionNumber version + IOstreamOption streamOpt ) : Detail::IFstreamAllocator(pathname), - ISstream - ( - *allocatedPtr_, - pathname, - format, - version, - IFstreamAllocator::detectedCompression_ - ) + ISstream(*allocatedPtr_, pathname, streamOpt) { + IOstream::compression(IFstreamAllocator::detectedCompression_); + setClosed(); setState(allocatedPtr_->rdstate()); diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H index 2ed746d3d6..cc5f097221 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.H @@ -100,10 +100,20 @@ public: explicit IFstream ( const fileName& pathname, - streamFormat format=ASCII, - versionNumber version=currentVersion + IOstreamOption streamOpt = IOstreamOption() ); + //- Construct from pathname, format (version) + IFstream + ( + const fileName& pathname, + streamFormat fmt, + versionNumber ver = currentVersion + ) + : + IFstream(pathname, IOstreamOption(fmt, ver)) + {} + //- Destructor ~IFstream() = default; diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index 6fd6ec8021..b78ca64d7e 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C @@ -111,21 +111,12 @@ Foam::Detail::OFstreamAllocator::OFstreamAllocator Foam::OFstream::OFstream ( const fileName& pathname, - streamFormat format, - versionNumber version, - compressionType compression, + IOstreamOption streamOpt, const bool append ) : - Detail::OFstreamAllocator(pathname, compression, append), - OSstream - ( - *allocatedPtr_, - pathname, - format, - version, - compression - ) + Detail::OFstreamAllocator(pathname, streamOpt.compression(), append), + OSstream(*allocatedPtr_, pathname, streamOpt) { setClosed(); setState(allocatedPtr_->rdstate()); diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H index 038400d2c5..39c4c22ec7 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.H @@ -102,12 +102,23 @@ public: explicit OFstream ( const fileName& pathname, - streamFormat format=ASCII, - versionNumber version=currentVersion, - compressionType compression=UNCOMPRESSED, + IOstreamOption streamOpt = IOstreamOption(), const bool append = false ); + //- Construct from pathname, format (version, compression) + OFstream + ( + const fileName& pathname, + streamFormat fmt, + versionNumber ver = currentVersion, + compressionType comp = compressionType::UNCOMPRESSED, + const bool append = false + ) + : + OFstream(pathname, IOstreamOption(fmt, comp, ver), append) + {} + //- Destructor ~OFstream() = default; diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C index 2aa4c10c60..dc10310c9e 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.C @@ -184,16 +184,14 @@ void Foam::masterOFstream::commit() Foam::masterOFstream::masterOFstream ( const fileName& pathName, - streamFormat format, - versionNumber version, - compressionType compression, + IOstreamOption streamOpt, const bool append, const bool valid ) : - OStringStream(format, version), + OStringStream(streamOpt.format(), streamOpt.version()), pathName_(pathName), - compression_(compression), + compression_(streamOpt.compression()), append_(append), valid_(valid) {} diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H index 7115463330..cfe0b868d7 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H +++ b/src/OpenFOAM/db/IOstreams/Fstreams/masterOFstream.H @@ -86,17 +86,35 @@ public: // Constructors - //- Construct and set stream status + //- Construct from pathname and set stream status explicit masterOFstream ( const fileName& pathname, - streamFormat format=ASCII, - versionNumber version=currentVersion, - compressionType compression=UNCOMPRESSED, + IOstreamOption streamOpt = IOstreamOption(), const bool append = false, const bool valid = true ); + //- Construct from pathname, version and set stream status + masterOFstream + ( + const fileName& pathname, + streamFormat fmt, + versionNumber ver = currentVersion, + compressionType comp = compressionType::UNCOMPRESSED, + const bool append = false, + const bool valid = true + ) + : + masterOFstream + ( + pathname, + IOstreamOption(fmt, comp, ver), + append, + valid + ) + {} + //- Destructor - commits buffered information to file ~masterOFstream(); diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H index 8f75c253de..b476ec020d 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/OTstream.H @@ -28,6 +28,7 @@ Class Description A simple output token stream that can be used to build token lists. + Always UNCOMPRESSED. Note Appending single characters to token list is fragile. @@ -63,13 +64,23 @@ public: // Constructors //- Default construct, set stream status + explicit OTstream(IOstreamOption streamOpt = IOstreamOption()) + : + Ostream(streamOpt.format(), streamOpt.version()), + DynamicList() + { + setOpened(); + setGood(); + } + + //- Construct with format, version explicit OTstream ( - streamFormat format=ASCII, - versionNumber version=currentVersion + streamFormat fmt, + versionNumber ver = currentVersion ) : - Ostream(format, version), + Ostream(fmt, ver), DynamicList() { setOpened(); diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C index 234ffbc16c..d5ef43cbaa 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C @@ -199,10 +199,8 @@ bool Foam::fileOperations::collatedFileOperation::appendObject OFstream os ( pathName, - IOstream::BINARY, - ver, - IOstream::UNCOMPRESSED, // no compression - !isMaster + IOstreamOption(IOstream::BINARY, ver), // UNCOMPRESSED + !isMaster // append slaves ); if (!os.good()) @@ -488,10 +486,8 @@ bool Foam::fileOperations::collatedFileOperation::writeObject masterOFstream os ( pathName, - fmt, - ver, - cmp, - false, + IOstreamOption(fmt, ver, cmp), + false, // append=false valid ); @@ -534,10 +530,8 @@ bool Foam::fileOperations::collatedFileOperation::writeObject masterOFstream os ( pathName, - fmt, - ver, - cmp, - false, + IOstreamOption(fmt, ver, cmp), + false, // append=false valid ); @@ -596,9 +590,7 @@ bool Foam::fileOperations::collatedFileOperation::writeObject ( writer_, pathName, - fmt, - ver, - cmp, + IOstreamOption(fmt, ver, cmp), useThread ); diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C index f7f29990fc..e3c7cc20ed 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.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. @@ -35,16 +36,14 @@ Foam::threadedCollatedOFstream::threadedCollatedOFstream ( OFstreamCollator& writer, const fileName& pathName, - streamFormat format, - versionNumber version, - compressionType compression, + IOstreamOption streamOpt, const bool useThread ) : - OStringStream(format, version), + OStringStream(streamOpt.format(), streamOpt.version()), writer_(writer), pathName_(pathName), - compression_(compression), + compression_(streamOpt.compression()), useThread_(useThread) {} @@ -61,7 +60,7 @@ Foam::threadedCollatedOFstream::~threadedCollatedOFstream() IOstream::BINARY, version(), compression_, - false, // append + false, // append=false useThread_ ); } diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H index 0a896ad1cf..87990ec39a 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/threadedCollatedOFstream.H @@ -72,14 +72,32 @@ public: //- Construct and set stream status threadedCollatedOFstream ( - OFstreamCollator&, + OFstreamCollator& writer, const fileName& pathname, - streamFormat format=ASCII, - versionNumber version=currentVersion, - compressionType compression=UNCOMPRESSED, + IOstreamOption streamOpt = IOstreamOption(), const bool useThread = true ); + //- Construct and set stream status + threadedCollatedOFstream + ( + OFstreamCollator& writer, + const fileName& pathname, + streamFormat fmt, + versionNumber ver = currentVersion, + compressionType comp = compressionType::UNCOMPRESSED, + const bool useThread = true + ) + : + threadedCollatedOFstream + ( + writer, + pathname, + IOstreamOption(fmt, ver, comp), + useThread + ) + {} + //- Destructor ~threadedCollatedOFstream(); diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C index 50d1bad4d1..09b95f6363 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C @@ -466,7 +466,7 @@ bool Foam::fileOperation::writeObject const regIOobject& io, IOstream::streamFormat fmt, IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstream::compressionType comp, const bool valid ) const { @@ -478,21 +478,15 @@ bool Foam::fileOperation::writeObject autoPtr osPtr ( - NewOFstream - ( - pathName, - fmt, - ver, - cmp - ) + NewOFstream(pathName, IOstreamOption(fmt, ver, comp)) ); - if (!osPtr.valid()) + if (!osPtr) { return false; } - Ostream& os = osPtr(); + OSstream& os = osPtr(); // If any of these fail, return (leave error handling to Ostream class) if (!os.good()) diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H index 8296e0af0e..d2e21e448d 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H @@ -409,10 +409,10 @@ public: // suppress empty local lagrangian data) virtual bool writeObject ( - const regIOobject&, - IOstream::streamFormat format=IOstream::ASCII, - IOstream::versionNumber version=IOstream::currentVersion, - IOstream::compressionType compression=IOstream::UNCOMPRESSED, + const regIOobject& io, + IOstream::streamFormat fmt = IOstream::ASCII, + IOstream::versionNumber ver = IOstream::currentVersion, + IOstream::compressionType comp = IOstream::UNCOMPRESSED, const bool valid = true ) const; @@ -430,9 +430,7 @@ public: virtual autoPtr NewOFstream ( const fileName& pathname, - IOstream::streamFormat format=IOstream::ASCII, - IOstream::versionNumber version=IOstream::currentVersion, - IOstream::compressionType compression=IOstream::UNCOMPRESSED, + IOstreamOption streamOpt = IOstreamOption(), const bool valid = true ) const = 0; diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C index cf296acff0..e9b2283272 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C @@ -2246,7 +2246,7 @@ bool Foam::fileOperations::masterUncollatedFileOperation::writeObject const regIOobject& io, IOstream::streamFormat fmt, IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstream::compressionType comp, const bool valid ) const { @@ -2266,13 +2266,11 @@ bool Foam::fileOperations::masterUncollatedFileOperation::writeObject NewOFstream ( pathName, - fmt, - ver, - cmp, + IOstreamOption(fmt, ver, comp), valid ) ); - Ostream& os = osPtr(); + OSstream& os = osPtr(); // If any of these fail, return (leave error handling to Ostream class) if (!os.good()) @@ -2549,9 +2547,7 @@ Foam::autoPtr Foam::fileOperations::masterUncollatedFileOperation::NewOFstream ( const fileName& pathName, - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool valid ) const { @@ -2560,10 +2556,8 @@ Foam::fileOperations::masterUncollatedFileOperation::NewOFstream new masterOFstream ( pathName, - fmt, - ver, - cmp, - false, // append + streamOpt, + false, // append=false valid ) ); diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H index bf20ad25a4..4b6e729c80 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H @@ -487,7 +487,7 @@ public: TypeName("masterUncollated"); - // Static data + // Static Data //- Max size of parallel communications. Switches from non-blocking // to scheduled when reading/writing files. Read as float to enable @@ -696,7 +696,7 @@ public: // Returns success state. virtual bool writeObject ( - const regIOobject&, + const regIOobject& io, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, @@ -710,9 +710,7 @@ public: virtual autoPtr NewOFstream ( const fileName& pathname, - IOstream::streamFormat format=IOstream::ASCII, - IOstream::versionNumber version=IOstream::currentVersion, - IOstream::compressionType compression=IOstream::UNCOMPRESSED, + IOstreamOption streamOpt = IOstreamOption(), const bool valid = true ) const; diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C index dbdcd526f5..24fa936b34 100644 --- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C @@ -724,13 +724,11 @@ Foam::autoPtr Foam::fileOperations::uncollatedFileOperation::NewOFstream ( const fileName& pathName, - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, + IOstreamOption streamOpt, const bool valid ) const { - return autoPtr(new OFstream(pathName, fmt, ver, cmp)); + return autoPtr(new OFstream(pathName, streamOpt)); } diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H index 793f74e749..325648160b 100644 --- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H @@ -282,9 +282,7 @@ public: virtual autoPtr NewOFstream ( const fileName& pathname, - IOstream::streamFormat format=IOstream::ASCII, - IOstream::versionNumber version=IOstream::currentVersion, - IOstream::compressionType compression=IOstream::UNCOMPRESSED, + IOstreamOption streamOpt = IOstreamOption(), const bool valid = true ) const; }; diff --git a/src/fileFormats/obj/OBJstream.C b/src/fileFormats/obj/OBJstream.C index bb34828c2f..893ea3f55a 100644 --- a/src/fileFormats/obj/OBJstream.C +++ b/src/fileFormats/obj/OBJstream.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -63,12 +64,10 @@ void Foam::OBJstream::writeAndCheck(const char c) Foam::OBJstream::OBJstream ( const fileName& pathname, - streamFormat format, - versionNumber version, - compressionType compression + IOstreamOption streamOpt ) : - OFstream(pathname, format, version, compression), + OFstream(pathname, streamOpt), startOfLine_(true), nVertices_(0) {} diff --git a/src/fileFormats/obj/OBJstream.H b/src/fileFormats/obj/OBJstream.H index 699c8438fc..bfba632494 100644 --- a/src/fileFormats/obj/OBJstream.H +++ b/src/fileFormats/obj/OBJstream.H @@ -83,11 +83,21 @@ public: explicit OBJstream ( const fileName& pathname, - streamFormat format=ASCII, - versionNumber version=currentVersion, - compressionType compression=UNCOMPRESSED + IOstreamOption streamOpt = IOstreamOption() ); + //- Construct from pathname + OBJstream + ( + const fileName& pathname, + streamFormat fmt, + versionNumber ver = currentVersion, + compressionType comp = compressionType::UNCOMPRESSED + ) + : + OBJstream(pathname, IOstreamOption(fmt, ver, comp)) + {} + //- Destructor ~OBJstream() = default; diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C index af78a780f8..593008f8e4 100644 --- a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C @@ -142,13 +142,7 @@ void Foam::MeshedSurfaceProxy::write ) ); - OFstream os - ( - objectDir/io.name(), - t.writeFormat(), - IOstream::currentVersion, - t.writeCompression() - ); + OFstream os(objectDir/io.name(), t.writeStreamOption()); io.writeHeader(os); @@ -174,13 +168,8 @@ void Foam::MeshedSurfaceProxy::write ) ); - OFstream os - ( - objectDir/io.name(), - t.writeFormat(), - IOstream::currentVersion, - t.writeCompression() - ); + OFstream os(objectDir/io.name(), t.writeStreamOption()); + io.writeHeader(os); if (this->useFaceMap()) @@ -212,8 +201,9 @@ void Foam::MeshedSurfaceProxy::write ) ); - // write as ascii + // Write as ASCII-only OFstream os(objectDir/io.name()); + io.writeHeader(os); os << this->surfZones();