diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index 94cc850a1f..1ec0ff1528 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -646,7 +646,7 @@ int main(int argc, char *argv[]) dictList.writeObject ( runTime.writeFormat(), - runTime.writeFormat(), + IOstream::currentVersion, IOstream::UNCOMPRESSED, true ); diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 0ec1cb054f..944d0d26ab 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -158,6 +158,7 @@ Streams = db/IOstreams $(Streams)/token/tokenIO.C IOstreams = $(Streams)/IOstreams +$(IOstreams)/IOstreamOption.C $(IOstreams)/IOstream.C $(IOstreams)/Istream.C $(IOstreams)/Ostream.C diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index d97bc75153..16d2052583 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -72,8 +72,7 @@ namespace Foam ::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name) {} - virtual ~addfileModificationCheckingToOpt() - {} + virtual ~addfileModificationCheckingToOpt() = default; virtual void readData(Foam::Istream& is) { diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index e25d715b9b..466d8086e5 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -295,7 +295,7 @@ public: // Member Functions - // General access + // General access //- Return the local objectRegistry const objectRegistry& db() const; @@ -337,7 +337,7 @@ public: inline bool& globalObject(); - // Read/write options + // Read/write options //- The read option inline readOption readOpt() const; @@ -352,7 +352,7 @@ public: inline writeOption& writeOpt(); - // Path components + // Path components //- Return group (extension part of name) word group() const; @@ -402,7 +402,7 @@ public: ) const; - // Reading + // Reading //- Read header bool readHeader(Istream& is); @@ -424,7 +424,7 @@ public: void warnNoRereading() const; - // Writing + // Writing //- Write the standard OpenFOAM file/dictionary banner // Optionally without -*- C++ -*- editor hint (eg, for logs) @@ -443,14 +443,14 @@ public: bool writeHeader(Ostream& os, const word& objectType) const; - // Error Handling + // Error Handling inline bool good() const; inline bool bad() const; - // Info + // Info //- Return info proxy. // Used to print token information to a stream diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 362ea395b8..3478473db1 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -60,7 +60,7 @@ class IOobjectList { // Private Member Functions - //- Disallow default bitwise assignment + //- No copy assignment void operator=(const IOobjectList&) = delete; @@ -92,7 +92,7 @@ public: // Member functions - // Basic methods + // Basic methods //- Add an IOobject to the list bool add(IOobject& io); @@ -101,7 +101,7 @@ public: bool remove(IOobject& io); - // Lookup + // Lookup //- Lookup a given name and return IOobject ptr if found else nullptr IOobject* lookup(const word& name) const; @@ -116,7 +116,7 @@ public: IOobjectList lookupClass(const word& clsName) const; - // Summary of classes + // Summary of classes //- A summary hash of classes used and their associated object names. // The HashTable representation allows us to leverage various @@ -196,7 +196,7 @@ public: HashTable classes(const wordRes& matcher) const; - // Summary of names + // Summary of names //- A list of names of the IOobjects wordList names() const; @@ -213,7 +213,7 @@ public: wordList names(const word& clsName, const wordRes& matcher) const; - // Summary of names (sorted) + // Summary of names (sorted) //- A sorted list of names of the IOobjects wordList sortedNames() const; diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index 830c959494..f22e5bc495 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -644,7 +644,7 @@ Foam::autoPtr Foam::decomposedBlockData::readBlocks // version string versionString(realIsPtr().version().str()); Pstream::scatter(versionString, Pstream::msgType(), comm); - realIsPtr().version(IStringStream(versionString)()); + realIsPtr().version(IOstream::versionNumber(versionString)); // stream { @@ -1071,7 +1071,7 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const writeHeader ( os, - IOstream::versionNumber(IStringStream(versionString)()), + IOstream::versionNumber(versionString), IOstream::formatEnum(formatString), io.headerClassName(), io.note(), diff --git a/src/OpenFOAM/db/IOstreams/IOstreams.C b/src/OpenFOAM/db/IOstreams/IOstreams.C index ee4cfb0e43..520d758842 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -23,35 +23,30 @@ License \*---------------------------------------------------------------------------*/ +#include "IOstreamOption.H" #include "IOstreams.H" #include "OFstream.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Define the default IOstream versions and precision - -const IOstream::versionNumber IOstream::originalVersion(0.5); -const IOstream::versionNumber IOstream::currentVersion(2.0); -unsigned int IOstream::precision_(debug::infoSwitch("writePrecision", 6)); +// Default output precision +unsigned int Foam::IOstream::precision_ +( + Foam::debug::infoSwitch("writePrecision", 6) +); -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Global Variables * * * * * * * * * * * * * * // + // Global IO streams -ISstream Sin(cin, "Sin"); -OSstream Sout(cout, "Sout"); -OSstream Serr(cerr, "Serr"); -OFstream Snull("/dev/null"); +Foam::ISstream Foam::Sin(std::cin, "Sin"); +Foam::OSstream Foam::Sout(std::cout, "Sout"); +Foam::OSstream Foam::Serr(std::cerr, "Serr"); +Foam::OFstream Foam::Snull("/dev/null"); -prefixOSstream Pout(cout, "Pout"); -prefixOSstream Perr(cerr, "Perr"); +Foam::prefixOSstream Foam::Pout(std::cout, "Pout"); +Foam::prefixOSstream Foam::Perr(std::cerr, "Perr"); -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C index 016fc281d8..b1ec766ecd 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,68 +25,12 @@ License #include "IOstream.H" #include "error.H" -#include "Switch.H" -#include // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // Foam::fileName Foam::IOstream::staticName_("IOstream"); -// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // - -Foam::IOstream::streamFormat -Foam::IOstream::formatEnum(const word& format) -{ - if (format == "ascii") - { - return IOstream::ASCII; - } - else if (format == "binary") - { - return IOstream::BINARY; - } - else - { - WarningInFunction - << "bad format specifier '" << format << "', using 'ascii'" - << endl; - - return IOstream::ASCII; - } -} - - -Foam::IOstream::compressionType -Foam::IOstream::compressionEnum(const word& compression) -{ - // get Switch (bool) value, but allow it to fail - Switch sw(compression, true); - - if (sw.valid()) - { - return sw ? IOstream::COMPRESSED : IOstream::UNCOMPRESSED; - } - else if (compression == "uncompressed") - { - return IOstream::UNCOMPRESSED; - } - else if (compression == "compressed") - { - return IOstream::COMPRESSED; - } - else - { - WarningInFunction - << "bad compression specifier '" << compression - << "', using 'uncompressed'" - << endl; - - return IOstream::UNCOMPRESSED; - } -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // const Foam::fileName& Foam::IOstream::name() const @@ -125,32 +69,10 @@ void Foam::IOstream::fatalCheck(const char* operation) const } -Foam::string Foam::IOstream::versionNumber::str() const -{ - std::ostringstream os; - os.precision(1); - os.setf(ios_base::fixed, ios_base::floatfield); - os << versionNumber_; - return os.str(); -} - - void Foam::IOstream::print(Ostream& os) const { - os << "IOstream: " << "Version " << version_ << ", format "; - - switch (format_) - { - case ASCII: - os << "ASCII"; - break; - - case BINARY: - os << "BINARY"; - break; - } - - os << ", line " << lineNumber(); + os << "IOstream: " << "Version " << version() << ", format " + << format() << ", line " << lineNumber(); if (opened()) { @@ -213,28 +135,6 @@ void Foam::IOstream::print(Ostream& os, const int streamState) const // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // -Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::streamFormat& sf) -{ - if (sf == IOstream::ASCII) - { - os << "ascii"; - } - else - { - os << "binary"; - } - - return os; -} - - -Foam::Ostream& Foam::operator<<(Ostream& os, const IOstream::versionNumber& vn) -{ - os << vn.str().c_str(); - return os; -} - - template<> Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy& ip) { diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index 653fe66e50..08baec0a28 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,6 +49,7 @@ SourceFiles #include "scalar.H" #include "fileName.H" #include "InfoProxy.H" +#include "IOstreamOption.H" #include @@ -70,201 +71,85 @@ namespace Foam \*---------------------------------------------------------------------------*/ class IOstream +: + public IOstreamOption { - public: - // Public data types + // Public Data Types //- Enumeration for whether the stream open or closed - enum streamAccess + enum streamAccess : char { - OPENED, - CLOSED - }; - - //- Enumeration for the format of data in the stream - enum streamFormat - { - ASCII, - BINARY - }; - - //- Ostream operator - friend Ostream& operator<<(Ostream& os, const streamFormat& sf); - - //- Version number type - class versionNumber - { - //- The version number - scalar versionNumber_; - - //- The version number as an integer - int index_; - - - public: - - // Constructors - - //- Construct from number - versionNumber(const scalar num) - : - versionNumber_(num), - index_(numberToIndex(num)) - {} - - //- Construct from Istream - versionNumber(Istream& is) - : - versionNumber_(readScalar(is)), - index_(numberToIndex(versionNumber_)) - {} - - - // Member functions - - //- Convert a version number into an index - int numberToIndex(const scalar num) const - { - return int(10*num + SMALL); - } - - //- Return major version - int majorVersion() const - { - return int(versionNumber_); - } - - //- Return minor version - int minorVersion() const - { - return int(10.0*(versionNumber_ - majorVersion())); - } - - //- Return the versionNumber as a character string - string str() const; - - - // Member operators - - //- Are these versionNumbers the same? - bool operator==(const versionNumber& vn) - { - return index_ == vn.index_; - } - - //- Are these versionNumbers different? - bool operator!=(const versionNumber& vn) - { - return index_ != vn.index_; - } - - //- Is this version older than the one given - bool operator<(const versionNumber& vn) - { - return index_ < vn.index_; - } - - //- Is this version the same as or older than the one given - bool operator<=(const versionNumber& vn) - { - return index_ <= vn.index_; - } - - //- Is this version newer than the one given - bool operator>(const versionNumber& vn) - { - return index_ > vn.index_; - } - - //- This version the same as or newer than the one given - bool operator>=(const versionNumber& vn) - { - return index_ >= vn.index_; - } - - - //- Ostream operator - friend Ostream& operator<<(Ostream& os, const versionNumber& vn); + CLOSED = 0, //!< stream not open + OPENED //!< stream is open }; - //- Enumeration for the format of data in the stream - enum compressionType - { - UNCOMPRESSED, - COMPRESSED - }; - - - // Public static data - - //- Original version number - static const versionNumber originalVersion; - - //- Current version number - static const versionNumber currentVersion; + // Public Static Data //- Default precision static unsigned int precision_; -private: +protected: - // Private data + // Protected Data //- Name for any generic stream - normally treat as readonly static fileName staticName_; - streamFormat format_; - versionNumber version_; - compressionType compression_; - streamAccess openClosed_; + ios_base::iostate ioState_; - -protected: - - // Protected data - label lineNumber_; // Protected Member Functions - // Access + // Access - //- Set stream opened - void setOpened() - { - openClosed_ = OPENED; - } + //- Set stream opened + void setOpened() + { + openClosed_ = OPENED; + } - //- Set stream closed - void setClosed() - { - openClosed_ = CLOSED; - } + //- Set stream closed + void setClosed() + { + openClosed_ = CLOSED; + } - //- Set stream state - void setState(ios_base::iostate state) - { - ioState_ = state; - } + //- Set stream state + void setState(ios_base::iostate state) + { + ioState_ = state; + } - //- Set stream to be good - void setGood() - { - ioState_ = ios_base::iostate(0); - } + //- Set stream to be good + void setGood() + { + ioState_ = ios_base::iostate(0); + } public: // Constructors + //- Construct with specified stream option + explicit IOstream(const IOstreamOption option) + : + IOstreamOption(option), + openClosed_(CLOSED), + ioState_(ios_base::iostate(0)), + lineNumber_(0) + { + setBad(); + } + //- Construct setting format and version IOstream ( @@ -273,265 +158,194 @@ public: compressionType compression=UNCOMPRESSED ) : - format_(format), - version_(version), - compression_(compression), - openClosed_(CLOSED), - ioState_(ios_base::iostate(0)), - lineNumber_(0) - { - setBad(); - } + IOstream(IOstreamOption(format, version, compression)) + {} //- Destructor - virtual ~IOstream() - {} + virtual ~IOstream() = default; - // Member functions + // Member Functions - // Access + // Access - //- Return the name of the stream - // Useful for Fstream to return the filename - virtual const fileName& name() const; + //- Return the name of the stream + // Useful for Fstream to return the filename + virtual const fileName& name() const; - //- Return non-const access to the name of the stream - // Useful to alter the stream name - virtual fileName& name(); + //- Return non-const access to the name of the stream + // Useful to alter the stream name + virtual fileName& name(); - // Check + // Check - //- Check IOstream status for given operation - // print IOstream state if error has occured - virtual bool check(const char* operation) const; + //- Check IOstream status for given operation + // print IOstream state if error has occured + virtual bool check(const char* operation) const; - //- Check IOstream status for given operation - // print IOstream state if error has occured and exit - void fatalCheck(const char* operation) const; + //- Check IOstream status for given operation + // print IOstream state if error has occured and exit + void fatalCheck(const char* operation) const; - //- Return true if stream has been opened - bool opened() const - { - return openClosed_ == OPENED; - } + //- Return true if stream has been opened + bool opened() const + { + return openClosed_ == OPENED; + } - //- Return true if stream is closed - bool closed() const - { - return openClosed_ == CLOSED; - } + //- Return true if stream is closed + bool closed() const + { + return openClosed_ == CLOSED; + } - //- Return true if next operation might succeed - bool good() const - { - return ioState_ == 0; - } + //- Return true if next operation might succeed + bool good() const + { + return ioState_ == 0; + } - //- Return true if end of input seen - bool eof() const - { - return ioState_ & ios_base::eofbit; - } + //- Return true if end of input seen + bool eof() const + { + return ioState_ & ios_base::eofbit; + } - //- Return true if next operation will fail - bool fail() const - { - return ioState_ & (ios_base::badbit | ios_base::failbit); - } + //- Return true if next operation will fail + bool fail() const + { + return ioState_ & (ios_base::badbit | ios_base::failbit); + } - //- Return true if stream is corrupted - bool bad() const - { - return ioState_ & ios_base::badbit; - } + //- Return true if stream is corrupted + bool bad() const + { + return ioState_ & ios_base::badbit; + } - //- Return non-zero if the stream has not failed - operator void*() const - { - return fail() - ? reinterpret_cast(0) - : reinterpret_cast(-1); - } + //- Return non-zero if the stream has not failed + operator void*() const + { + return fail() + ? reinterpret_cast(0) + : reinterpret_cast(-1); + } - //- Return true if the stream has failed - bool operator!() const - { - return fail(); - } + //- Return true if the stream has failed + bool operator!() const + { + return fail(); + } - // Stream state functions + // Stream State Functions - //- Return stream format of given format name - static streamFormat formatEnum(const word&); + //- Const access to the current stream line number + label lineNumber() const + { + return lineNumber_; + } - //- Return current stream format - streamFormat format() const - { - return format_; - } + //- Non-const access to the current stream line number + label& lineNumber() + { + return lineNumber_; + } - //- Set the stream format - streamFormat format(const streamFormat fmt) - { - streamFormat fmt0 = format_; - format_ = fmt; - return fmt0; - } + //- Set the stream line number + // \return the previous value + label lineNumber(const label num) + { + label old(lineNumber_); + lineNumber_ = num; + return old; + } - //- Set the stream format from word - streamFormat format(const word& fmt) - { - streamFormat fmt0 = format_; - format_ = formatEnum(fmt); - return fmt0; - } + //- Return flags of stream + virtual ios_base::fmtflags flags() const = 0; - //- Return the stream version - versionNumber version() const - { - return version_; - } + //- Return the default precision + static unsigned int defaultPrecision() + { + return precision_; + } - //- Set the stream version - versionNumber version(const versionNumber ver) - { - versionNumber ver0 = version_; - version_ = ver; - return ver0; - } + //- Reset the default precision + // \return the previous value + static unsigned int defaultPrecision(unsigned int prec) + { + unsigned int old(precision_); + precision_ = prec; + return old; + } - //- Return compression of given compression name - static compressionType compressionEnum(const word&); + //- Set stream to have reached eof + void setEof() + { + ioState_ |= ios_base::eofbit; + } - //- Return the stream compression - compressionType compression() const - { - return compression_; - } + //- Set stream to have failed + void setFail() + { + ioState_ |= ios_base::failbit; + } - //- Set the stream compression - compressionType compression(const compressionType cmp) - { - compressionType cmp0 = compression_; - compression_ = cmp; - return cmp0; - } + //- Set stream to be bad + void setBad() + { + ioState_ |= ios_base::badbit; + } - //- Set the stream compression from word - compressionType compression(const word& cmp) - { - compressionType cmp0 = compression_; - compression_ = compressionEnum(cmp); - return cmp0; - } + //- Set flags of stream + virtual ios_base::fmtflags flags(const ios_base::fmtflags f) = 0; - //- Return current stream line number - label lineNumber() const - { - return lineNumber_; - } + //- Set flags of stream + ios_base::fmtflags setf(const ios_base::fmtflags f) + { + return flags(flags() | f); + } - //- Return current stream line number - label& lineNumber() - { - return lineNumber_; - } + //- Set flags of given field of stream + ios_base::fmtflags setf + ( + const ios_base::fmtflags f, + const ios_base::fmtflags mask + ) + { + return flags((flags() & ~mask) | (f & mask)); + } - //- Set the stream line number - label lineNumber(const label ln) - { - label ln0 = lineNumber_; - lineNumber_ = ln; - return ln0; - } - - //- Return flags of stream - virtual ios_base::fmtflags flags() const = 0; - - //- Return the default precision - static unsigned int defaultPrecision() - { - return precision_; - } - - //- Reset the default precision (and return old precision) - static unsigned int defaultPrecision(unsigned int p) - { - unsigned int precision0 = precision_; - precision_ = p; - return precision0; - } - - //- Set stream to have reached eof - void setEof() - { - ioState_ |= ios_base::eofbit; - } - - //- Set stream to have failed - void setFail() - { - ioState_ |= ios_base::failbit; - } - - //- Set stream to be bad - void setBad() - { - ioState_ |= ios_base::badbit; - } - - //- Set flags of stream - virtual ios_base::fmtflags flags(const ios_base::fmtflags f) = 0; - - //- Set flags of stream - ios_base::fmtflags setf(const ios_base::fmtflags f) - { - return flags(flags() | f); - } - - //- Set flags of given field of stream - ios_base::fmtflags setf - ( - const ios_base::fmtflags f, - const ios_base::fmtflags mask - ) - { - return flags((flags() & ~mask) | (f & mask)); - } - - //- Unset flags of stream - void unsetf(const ios_base::fmtflags uf) - { - flags(flags()&~uf); - } + //- Unset flags of stream + void unsetf(const ios_base::fmtflags f) + { + flags(flags() & ~f); + } - // Print + // Print - //- Print description of IOstream to Ostream - virtual void print(Ostream&) const; + //- Print description of IOstream to Ostream + virtual void print(Ostream& os) const; - //- Check given stream state bits - void print(Ostream&, const int streamState) const; + //- Print information about the stream state bits + void print(Ostream& os, const int streamState) const; - // Info + // Info - //- Return info proxy. - // Used to print IOstream information to a stream - InfoProxy info() const - { - return *this; - } + //- Return info proxy. + // Used to print IOstream information to a stream + InfoProxy info() const + { + return *this; + } }; -Ostream& operator<<(Ostream& os, const IOstream::streamFormat& sf); -Ostream& operator<<(Ostream& os, const IOstream::versionNumber& vn); +// Ostream operator template<> Ostream& operator<<(Ostream& os, const InfoProxy& ip); diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C new file mode 100644 index 0000000000..0e7b7dd844 --- /dev/null +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "IOstreamOption.H" +#include "error.H" +#include "Enum.H" +#include "Switch.H" + +// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * // + +const Foam::IOstreamOption::versionNumber + Foam::IOstreamOption::originalVersion(0,5); + +const Foam::IOstreamOption::versionNumber + Foam::IOstreamOption::currentVersion(2,0); + + +const Foam::Enum +< + Foam::IOstreamOption::streamFormat +> +Foam::IOstreamOption::formatNames +{ + { streamFormat::ASCII, "ascii" }, + { streamFormat::BINARY, "binary" } +}; + + +// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // + +Foam::IOstreamOption::streamFormat +Foam::IOstreamOption::formatEnum(const word& formatName) +{ + // Handle bad input graciously + if (formatNames.found(formatName)) + { + return formatNames[formatName]; + } + + WarningInFunction + << "Unknown format specifier '" << formatName + << "', using 'ascii'" << endl; + + return streamFormat::ASCII; +} + + +Foam::IOstreamOption::compressionType +Foam::IOstreamOption::compressionEnum(const word& compName) +{ + // Handle bad input graciously + + const Switch sw(compName, true); + if (sw.valid()) + { + return + ( + sw + ? compressionType::COMPRESSED + : compressionType::UNCOMPRESSED + ); + } + + WarningInFunction + << "Unknown compression specifier '" << compName + << "', assuming no compression" << endl; + + return compressionType::UNCOMPRESSED; +} + + +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const IOstreamOption::streamFormat& sf +) +{ + os << IOstreamOption::formatNames[sf]; + return os; +} + + +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const IOstreamOption::versionNumber& vn +) +{ + // Emit as char sequence instead of as individual characters + // in case this is needed for sending in parallel. + os << vn.str().c_str(); + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H new file mode 100644 index 0000000000..f9413a25c9 --- /dev/null +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H @@ -0,0 +1,347 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::IOstreamOption + +Description + The IOstreamOption is a simple container for options an IOstream + can normally have. For example, ascii/binary, uncompressed/compressed, ... + +SourceFiles + IOstreamOption.C + +\*---------------------------------------------------------------------------*/ + +#ifndef IOstreamOption_H +#define IOstreamOption_H + +#include "scalar.H" +#include "word.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declarations +class Ostream; +template class Enum; + +/*---------------------------------------------------------------------------*\ + Class IOstreamOption Declaration +\*---------------------------------------------------------------------------*/ + +class IOstreamOption +{ +public: + + // Public Data Types + + //- Data format (ascii | binary) + enum streamFormat : char + { + ASCII, //!< "ascii" + BINARY //!< "binary" + }; + + //- Compression treatment (UNCOMPRESSED | COMPRESSED) + enum compressionType : char + { + UNCOMPRESSED = 0, //!< compression = false + COMPRESSED //!< compression = true + }; + + + //- Representation of a major/minor version number + class versionNumber + { + //- The combined major/version number. + short number_; + + public: + + // Constructors + + //- Construct from major, number + constexpr versionNumber(int major, int minor) noexcept + : + number_(10*major + (minor % 10)) + {} + + //- Construct from floating-point version number + explicit constexpr versionNumber(const float ver) noexcept + : + number_(10*ver + 0.001) // Allow some rounding + {} + + //- Construct from Istream by reading in a float. + // Non-explicit for convenience + versionNumber(Istream& is) + : + versionNumber(readFloat(is)) + {} + + //- Construct by parsing string "major.minor" + explicit versionNumber(const std::string& verNum) + : + versionNumber(readFloat(verNum)) + {} + + + // Member Functions + + //- The canonical major/minor pair as an integer value. + inline int canonical() noexcept + { + return number_; + } + + //- The major version number + inline int major() const noexcept + { + return int(number_ / 10); + } + + //- The minor version number + inline int minor() const noexcept + { + return int(number_ % 10); + } + + //- A string representation of major.minor + std::string str() const + { + return std::to_string(major()) + '.' + std::to_string(minor()); + } + + + // Member Operators + + //- Version number equality + bool operator==(const versionNumber& rhs) const noexcept + { + return number_ == rhs.number_; + } + + //- Version number inequality + bool operator!=(const versionNumber& rhs) const noexcept + { + return number_ != rhs.number_; + } + + //- Version number older than rhs + bool operator<(const versionNumber& rhs) const noexcept + { + return number_ < rhs.number_; + } + + //- Version number is the same or older than rhs + bool operator<=(const versionNumber& rhs) const noexcept + { + return number_ <= rhs.number_; + } + + //- Version number newer than rhs + bool operator>(const versionNumber& rhs) const noexcept + { + return number_ > rhs.number_; + } + + //- Version number same or newer than rhs + bool operator>=(const versionNumber& rhs) const noexcept + { + return number_ >= rhs.number_; + } + }; + + + // Public Static Data + + //- Stream format names (ascii, binary) + static const Enum formatNames; + + //- The original version number + static const versionNumber originalVersion; + + //- The current version number + static const versionNumber currentVersion; + + +private: + + // Private Data + + // NB: ordered with adjacent enums to minimize gaps + + //- Stream version number (eg, 2.0 for current dictionary format) + versionNumber version_; + + //- Format: (ascii | binary) + streamFormat format_; + + //- Compression: (on | off) + compressionType compression_; + + +public: + + // Constructors + + //- Construct null. (default: ASCII, uncompressed, currentVersion) + IOstreamOption() noexcept + : + version_(currentVersion), + format_(ASCII), + compression_(compressionType::UNCOMPRESSED) + {} + + //- Construct with format. (default: uncompressed, currentVersion) + explicit IOstreamOption(streamFormat format) noexcept + : + version_(currentVersion), + format_(format), + compression_(compressionType::UNCOMPRESSED) + {} + + //- Construct with format and compression, optionally with version. + IOstreamOption + ( + streamFormat format, + compressionType compression, + versionNumber version=currentVersion + ) noexcept + : + version_(version), + format_(format), + compression_(compression) + {} + + //- Construct with format, version, compression + IOstreamOption + ( + streamFormat format, + versionNumber version, + compressionType compression + ) noexcept + : + version_(version), + format_(format), + compression_(compression) + {} + + + // Static Member Functions + + //- The stream format enum corresponding to the string + // Expected "ascii", "binary" + static streamFormat formatEnum(const word& formatName); + + //- The compression enum corresponding to the string + // Expected "true", "false", "on", "off", etc. + static compressionType compressionEnum(const word& compName); + + + // Member Functions + + //- Get the current stream format + streamFormat format() const noexcept + { + return format_; + } + + //- Set the stream format + // \return the previous value + streamFormat format(const streamFormat format) noexcept + { + streamFormat old(format_); + format_ = format; + return old; + } + + //- Set the stream format, from string value + // \return the previous value + streamFormat format(const word& formatName) + { + streamFormat old(format_); + format_ = formatEnum(formatName); + return old; + } + + //- Get the stream compression + compressionType compression() const noexcept + { + return compression_; + } + + //- Set the stream compression + // \return the previous value + compressionType compression(const compressionType comp) noexcept + { + compressionType old(compression_); + compression_ = comp; + return old; + } + + //- Set the stream compression, from string value. + // \return the previous value + compressionType compression(const word& compressionName) + { + compressionType old(compression_); + compression_ = compressionEnum(compressionName); + return old; + } + + //- Get the stream version + versionNumber version() const noexcept + { + return version_; + } + + //- Set the stream version + // \return the previous value + versionNumber version(const versionNumber verNum) noexcept + { + versionNumber old(version_); + version_ = verNum; + return old; + } +}; + + +//- Output the format as text string (ascii | binary) +Ostream& operator<<(Ostream& os, const IOstreamOption::streamFormat& sf); + +//- Output the version as major.minor +Ostream& operator<<(Ostream& os, const IOstreamOption::versionNumber& vn); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index e55211309d..7f84c11593 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -86,8 +86,7 @@ public: //- Destructor - virtual ~Istream() - {} + virtual ~Istream() = default; // Member functions diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index 1c6d2131bc..73506e614f 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -88,8 +88,7 @@ public: //- Destructor - virtual ~Ostream() - {} + virtual ~Ostream() = default; // Member functions diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C index 383fe03319..9b3bf890fa 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C @@ -432,8 +432,7 @@ namespace Foam ::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name) {} - virtual ~addcommsTypeToOpt() - {} + virtual ~addcommsTypeToOpt() = default; virtual void readData(Foam::Istream& is) { diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H index e446272f85..e41a96d6be 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.H @@ -77,7 +77,7 @@ class ISstream // Handles both "$var" and "${var}" forms. Istream& readVariable(string& str); - //- Disallow default bitwise assignment + //- No copy assignment void operator=(const ISstream&) = delete; @@ -97,8 +97,7 @@ public: //- Destructor - virtual ~ISstream() - {} + virtual ~ISstream() = default; // Member functions diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H index 8218a5a3d6..90f0dc9e88 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.H @@ -61,7 +61,7 @@ class OSstream // Private Member Functions - //- Disallow default bitwise assignment + //- No copy assignment void operator=(const OSstream&) = delete; @@ -70,7 +70,7 @@ public: // Constructors //- Construct as wrapper around std::ostream and set stream status - OSstream + inline OSstream ( std::ostream& os, const string& name, diff --git a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H index aa1060e74e..0cdff49b08 100644 --- a/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H +++ b/src/OpenFOAM/db/IOstreams/Tstreams/ITstream.H @@ -160,8 +160,7 @@ public: //- Destructor - virtual ~ITstream() - {} + virtual ~ITstream() = default; // Static Functions diff --git a/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H b/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H index fa0b441dc2..d9d222b7d0 100644 --- a/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H +++ b/src/OpenFOAM/db/IOstreams/dummy/dummyISstream.H @@ -49,7 +49,6 @@ class dummyISstream : public IStringStream { - public: // Constructors @@ -62,8 +61,7 @@ public: //- Destructor - virtual ~dummyISstream() - {} + virtual ~dummyISstream() = default; // Member functions diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index e30a952937..e5333b6158 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -439,10 +439,7 @@ Foam::Time::Time writeOnce_(false), sigWriteNow_(*this, true), sigStopAtWriteNow_(*this, true), - - writeFormat_(IOstream::ASCII), - writeVersion_(IOstream::currentVersion), - writeCompression_(IOstream::UNCOMPRESSED), + writeStreamOption_(IOstream::ASCII), graphFormat_("raw"), runTimeModifiable_(false), @@ -508,10 +505,7 @@ Foam::Time::Time writeOnce_(false), sigWriteNow_(*this, true), sigStopAtWriteNow_(*this, true), - - writeFormat_(IOstream::ASCII), - writeVersion_(IOstream::currentVersion), - writeCompression_(IOstream::UNCOMPRESSED), + writeStreamOption_(IOstream::ASCII), graphFormat_("raw"), runTimeModifiable_(false), @@ -587,10 +581,7 @@ Foam::Time::Time writeOnce_(false), sigWriteNow_(*this, true), sigStopAtWriteNow_(*this, true), - - writeFormat_(IOstream::ASCII), - writeVersion_(IOstream::currentVersion), - writeCompression_(IOstream::UNCOMPRESSED), + writeStreamOption_(IOstream::ASCII), graphFormat_("raw"), runTimeModifiable_(false), @@ -655,9 +646,7 @@ Foam::Time::Time purgeWrite_(0), subCycling_(0), writeOnce_(false), - writeFormat_(IOstream::ASCII), - writeVersion_(IOstream::currentVersion), - writeCompression_(IOstream::UNCOMPRESSED), + writeStreamOption_(IOstream::ASCII), graphFormat_("raw"), runTimeModifiable_(false), diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index 608e835a0d..3cc1860d63 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -193,14 +193,8 @@ protected: private: - //- Default write option - IOstream::streamFormat writeFormat_; - - //- Default output file format version number - IOstream::versionNumber writeVersion_; - - //- Default output compression - IOstream::compressionType writeCompression_; + //- Default write stream option (format, version, compression) + IOstreamOption writeStreamOption_; //- Default graph format word graphFormat_; @@ -309,19 +303,19 @@ public: //- Default write format IOstream::streamFormat writeFormat() const { - return writeFormat_; + return writeStreamOption_.format(); } //- Default write version number IOstream::versionNumber writeVersion() const { - return writeVersion_; + return writeStreamOption_.version(); } //- Default write compression IOstream::compressionType writeCompression() const { - return writeCompression_; + return writeStreamOption_.compression(); } //- Default graph format diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index 66741868ba..71ec656871 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -442,18 +442,18 @@ void Foam::Time::readDict() if (controlDict_.found("writeVersion")) { - writeVersion_ = IOstream::versionNumber + writeStreamOption_.version ( - controlDict_.lookup("writeVersion") + IOstreamOption::versionNumber + ( + controlDict_.lookup("writeVersion") + ) ); } if (controlDict_.found("writeFormat")) { - writeFormat_ = IOstream::formatEnum - ( - controlDict_.lookup("writeFormat") - ); + writeStreamOption_.format(word(controlDict_.lookup("writeFormat"))); } if (controlDict_.found("writePrecision")) @@ -478,23 +478,23 @@ void Foam::Time::readDict() if (controlDict_.found("writeCompression")) { - writeCompression_ = IOstream::compressionEnum + writeStreamOption_.compression ( - controlDict_.lookup("writeCompression") + word(controlDict_.lookup("writeCompression")) ); if ( - writeFormat_ == IOstream::BINARY - && writeCompression_ == IOstream::COMPRESSED + writeStreamOption_.compression() == IOstream::COMPRESSED + && writeStreamOption_.format() == IOstream::BINARY ) { IOWarningInFunction(controlDict_) - << "Selecting compressed binary is inefficient and ineffective" - ", resetting to uncompressed binary" + << "Disabled binary format compression" + << " (inefficient/ineffective)" << endl; - writeCompression_ = IOstream::UNCOMPRESSED; + writeStreamOption_.compression(IOstream::UNCOMPRESSED); } } diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index a85ad3986a..7cc7c55e6f 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -224,31 +224,23 @@ Foam::Field::Field << exit(FatalIOError); } } + else if (is.version() == IOstream::versionNumber(2,0)) + { + IOWarningInFunction(dict) + << "expected keyword 'uniform' or 'nonuniform', " + "assuming deprecated Field format from " + "Foam version 2.0." << endl; + + this->setSize(len); + + is.putBack(firstToken); + operator=(pTraits(is)); + } else { - if (is.version() == 2.0) - { - IOWarningInFunction - ( - dict - ) << "expected keyword 'uniform' or 'nonuniform', " - "assuming deprecated Field format from " - "Foam version 2.0." << endl; - - this->setSize(len); - - is.putBack(firstToken); - operator=(pTraits(is)); - } - else - { - FatalIOErrorInFunction - ( - dict - ) << "expected keyword 'uniform' or 'nonuniform', found " - << firstToken.info() - << exit(FatalIOError); - } + FatalIOErrorInFunction(dict) + << "expected keyword 'uniform' or 'nonuniform', found " + << firstToken.info() << exit(FatalIOError); } } } diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index d9123f68b0..c5b39c4be9 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -165,7 +165,7 @@ inline bool Foam::operator!=(const face& a, const face& b) inline Foam::Istream& Foam::operator>>(Istream& is, face& f) { - if (is.version() == IOstream::originalVersion) + if (is.version() == IOstreamOption::originalVersion) { // Read starting ( is.readBegin("face"); diff --git a/src/conversion/fire/FIREMeshReader.C b/src/conversion/fire/FIREMeshReader.C index 592d03a48e..80da026075 100644 --- a/src/conversion/fire/FIREMeshReader.C +++ b/src/conversion/fire/FIREMeshReader.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -405,7 +405,7 @@ bool Foam::fileFormats::FIREMeshReader::readGeometry(const scalar scaleFactor) << abort(FatalError); } - IFstream is(geometryFile_, fmt, false); + IFstream is(geometryFile_, fmt); readPoints(is, scaleFactor); readFaces(is); @@ -459,17 +459,11 @@ Foam::fileFormats::FIREMeshReader::FIREMeshReader ) : meshReader(name, scaleFactor), - owner_(0), - neigh_(0), - faceZoneId_(0), + owner_(), + neigh_(), + faceZoneId_(), faceNames_() {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::fileFormats::FIREMeshReader::~FIREMeshReader() -{} - - // ************************************************************************* // diff --git a/src/conversion/fire/FIREMeshReader.H b/src/conversion/fire/FIREMeshReader.H index b3e7f0b551..dd6c175ce4 100644 --- a/src/conversion/fire/FIREMeshReader.H +++ b/src/conversion/fire/FIREMeshReader.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -47,7 +47,7 @@ SourceFiles namespace Foam { -// forward declarations +// Forward declarations class polyMesh; namespace fileFormats @@ -76,10 +76,10 @@ protected: // Protected Member Functions - //- Disallow default bitwise copy construct + //- No copy construct FIREMeshReader(const FIREMeshReader&) = delete; - //- Disallow default bitwise assignment + //- No copy assignment void operator=(const FIREMeshReader&) = delete; @@ -113,7 +113,7 @@ public: //- Destructor - virtual ~FIREMeshReader(); + virtual ~FIREMeshReader() = default; // Member Functions diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.C b/src/functionObjects/utilities/ensightWrite/ensightWrite.C index 69c594d4fd..051bc8f79b 100644 --- a/src/functionObjects/utilities/ensightWrite/ensightWrite.C +++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.C @@ -73,9 +73,12 @@ Foam::functionObjects::ensightWrite::ensightWrite fvMeshFunctionObject(name, runTime, dict), writeOpts_ ( - dict.found("format") - ? IOstream::formatEnum(dict.lookup("format")) - : runTime.writeFormat() + IOstreamOption::formatNames.lookupOrFailsafe + ( + "format", + dict, + runTime.writeFormat() + ) ), caseOpts_(writeOpts_.format()), selectFields_(), diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index a34d1494d2..51cbd79966 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -875,38 +875,29 @@ Foam::tmp Foam::mappedPatchBase::readListOrField is >> static_cast&>(fld); if (fld.size() != size) { - FatalIOErrorInFunction - ( - dict - ) << "size " << fld.size() + FatalIOErrorInFunction(dict) + << "size " << fld.size() << " is not equal to the given value of " << size << exit(FatalIOError); } } else { - FatalIOErrorInFunction - ( - dict - ) << "expected keyword 'uniform' or 'nonuniform', found " + FatalIOErrorInFunction(dict) + << "expected keyword 'uniform' or 'nonuniform', found " << firstToken.wordToken() << exit(FatalIOError); } } - else + else if (is.version() == IOstream::versionNumber(2,0)) { - if (is.version() == 2.0) - { - IOWarningInFunction - ( - dict - ) << "expected keyword 'uniform' or 'nonuniform', " - "assuming List format for backwards compatibility." - "Foam version 2.0." << endl; + IOWarningInFunction(dict) + << "expected keyword 'uniform' or 'nonuniform', " + "assuming List format for backwards compatibility." + "Foam version 2.0." << endl; - is.putBack(firstToken); - is >> static_cast&>(fld); - } + is.putBack(firstToken); + is >> static_cast&>(fld); } } return tfld; @@ -1090,10 +1081,8 @@ Foam::mappedPatchBase::mappedPatchBase } else if (mode_ != NEARESTPATCHFACE && mode_ != NEARESTPATCHFACEAMI) { - FatalIOErrorInFunction - ( - dict - ) << "Please supply the offsetMode as one of " + FatalIOErrorInFunction(dict) + << "Please supply the offsetMode as one of " << offsetModeNames_ << exit(FatalIOError); } @@ -1125,10 +1114,8 @@ Foam::mappedPatchBase::mappedPatchBase { if (mode != NEARESTPATCHFACE && mode != NEARESTPATCHFACEAMI) { - FatalIOErrorInFunction - ( - dict - ) << "Construct from sampleMode and dictionary only applicable for " + FatalIOErrorInFunction(dict) + << "Construct from sampleMode and dictionary only applicable for " << " collocated patches in modes " << sampleModeNames_[NEARESTPATCHFACE] << ',' << sampleModeNames_[NEARESTPATCHFACEAMI] diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C index be9711297f..4f2c467371 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C @@ -49,16 +49,17 @@ Foam::ensightSurfaceWriter::ensightSurfaceWriter() Foam::ensightSurfaceWriter::ensightSurfaceWriter(const dictionary& options) : surfaceWriter(), - writeFormat_(IOstream::ASCII), - collateTimes_(true) -{ - // choose ascii or binary format - if (options.found("format")) - { - writeFormat_ = IOstream::formatEnum(options.lookup("format")); - } - options.readIfPresent("collateTimes", collateTimes_); -} + writeFormat_ + ( + IOstreamOption::formatNames.lookupOrFailsafe + ( + "format", + options, + IOstreamOption::ASCII + ) + ), + collateTimes_(options.lookupOrDefault("collateTimes", true)) +{} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //