From 33f9ae5080f0cfe5832f84a35843d2872ae8662c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 17 Feb 2020 08:49:19 +0100 Subject: [PATCH] ENH: improvements to IOstreamOption * Support default values for format/compress enum lookups. - Avoids situations where the preferred default format is not ASCII. For example, with dictionary input: format binar; The typing mistake would previously have caused formatEnum to default to ASCII. We can now properly control its behaviour. IOstream::formatEnum ( dict.get("format"), IOstream::BINARY ); Allowing us to switch ascii/binary, using BINARY by default even in the case of spelling mistakes. The mistakes are flagged, but the return value can be non-ASCII. * The format/compression lookup behave as pass-through if the lookup string is empty. - Allows the following to work without complaint IOstream::formatEnum ( dict.getOrDefault("format", word::null), IOstream::BINARY ); - Or use constructor-like failsafe method IOstream::formatEnum("format", dict, IOstream::BINARY); - Apply the same behaviour with setting stream format/compression from a word. is.format("binar"); will emit a warning, but leave the stream format UNCHANGED * Rationalize versionNumber construction - constexpr constructors where possible. Default construct is the "currentVersion" - Construct from token to shift the burden to versionNumber. Support token as argument to version(). Now: is.version(headerDict.get("version")); or failsafe constructor method is.version ( IOstreamOption::versionNumber("version", headerDict) ); Before (controlled input): is.version ( IOstreamOption::versionNumber ( headerDict.get("version") ) ); Old, uncontrolled input - has been removed: is.version(headerDict.lookup("version")); * improve consistency, default behaviour for IOstreamOption construct - constexpr constructors where possible - add copy construct with change of format. - construct IOstreamOption from streamFormat is now non-explicit. This is a commonly expected result with no ill-effects --- applications/test/sizeof/Test-sizeof.C | 15 +- src/OpenFOAM/db/IOobject/IOobjectReadHeader.C | 11 +- .../decomposedBlockData/decomposedBlockData.C | 8 +- .../db/IOstreams/IOstreams/IOstreamOption.C | 164 +++++++-- .../db/IOstreams/IOstreams/IOstreamOption.H | 317 ++++++++++++------ src/OpenFOAM/db/Time/TimeIO.C | 10 +- .../lagrangian/vtkCloud/vtkCloud.C | 12 +- .../utilities/ensightWrite/ensightWrite.C | 10 +- .../utilities/vtkWrite/vtkWrite.C | 17 +- .../surfaceFormats/vtk/VTKsurfaceFormatCore.C | 18 +- .../surfaceFormats/vtp/VTPsurfaceFormatCore.C | 18 +- .../writers/ensight/ensightSurfaceWriter.C | 10 +- src/surfMesh/writers/raw/rawSurfaceWriter.C | 7 +- src/surfMesh/writers/vtk/vtkSurfaceWriter.C | 20 +- 14 files changed, 387 insertions(+), 250 deletions(-) diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C index b6b1b1bf18..78423b0e04 100644 --- a/applications/test/sizeof/Test-sizeof.C +++ b/applications/test/sizeof/Test-sizeof.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,20 +66,23 @@ int main(int argc, char *argv[]) if (true) { + cout<<"IOstreamOption:" << sizeof(IOstreamOption) << nl; cout<<"IOstream:" << sizeof(IOstream) << nl; cout<<"Istream:" << sizeof(Istream) << nl; - cout<<"IPstream:" << sizeof(IPstream) << nl; - cout<<"ISstream:" << sizeof(ISstream) << nl; - cout<<"Ostream:" << sizeof(Ostream) << nl; - cout<<"OPstream:" << sizeof(OPstream) << nl; + + cout<<"ISstream:" << sizeof(ISstream) << nl; cout<<"OSstream:" << sizeof(OSstream) << nl; + + cout<<"IPstream:" << sizeof(IPstream) << nl; + cout<<"OPstream:" << sizeof(OPstream) << nl; } { nil x; cout<<"nil:" << sizeof(x) << nl; } + #if 0 { argList x(argc, argv); cout<<"argList:" << sizeof(x) << nl; @@ -87,6 +90,7 @@ int main(int argc, char *argv[]) TimePaths y(x); cout<<"TimePaths:" << sizeof(y) << nl; } + #endif { zero x; cout<<"zero:" << sizeof(x) << nl; @@ -117,6 +121,7 @@ int main(int argc, char *argv[]) } { + cout<<"short:" << sizeof(short) << nl; cout<<"int:" << sizeof(int) << nl; cout<<"long:" << sizeof(long) << nl; cout<<"float:" << sizeof(float) << nl; diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index f53a3cf072..fe6aed04bb 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -71,14 +71,7 @@ bool Foam::IOobject::readHeader(Istream& is) { const dictionary headerDict(is); - is.version - ( - IOstreamOption::versionNumber - ( - headerDict.get("version") - ) - ); - + is.version(headerDict.get("version")); is.format(headerDict.get("format")); headerClassName_ = headerDict.get("class"); diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index a9a2bb09b3..66653071d3 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -1196,13 +1196,7 @@ Foam::label Foam::decomposedBlockData::numBlocks(const fileName& fName) ) { dictionary headerDict(is); - is.version - ( - IOstreamOption::versionNumber - ( - headerDict.get("version") - ) - ); + is.version(headerDict.get("version")); is.format(headerDict.get("format")); // Obtain number of blocks directly diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C index a5ecc291ea..7138043a72 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,14 +27,13 @@ License #include "IOstreamOption.H" #include "error.H" +#include "dictionary.H" #include "Enum.H" #include "Switch.H" // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * // -const Foam::IOstreamOption::versionNumber - Foam::IOstreamOption::currentVersion(2,0); - +const Foam::IOstreamOption::versionNumber Foam::IOstreamOption::currentVersion; const Foam::Enum < @@ -50,55 +49,151 @@ Foam::IOstreamOption::formatNames // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // Foam::IOstreamOption::streamFormat -Foam::IOstreamOption::formatEnum(const word& formatName) +Foam::IOstreamOption::formatEnum +( + const word& formatName, + const streamFormat deflt +) { - // Handle bad input graciously - if (formatNames.found(formatName)) + // Handle bad input graciously. A no-op for an empty string + + if (!formatName.empty()) { - return formatNames[formatName]; + if (formatNames.found(formatName)) + { + return formatNames[formatName]; + } + + // Fall-through to warning + + WarningInFunction + << "Unknown format specifier '" << formatName + << "', using '" << formatNames[deflt] << "'\n"; } - WarningInFunction - << "Unknown format specifier '" << formatName - << "', using 'ascii'" << endl; + return deflt; +} - return streamFormat::ASCII; + +Foam::IOstreamOption::streamFormat +Foam::IOstreamOption::formatEnum +( + const word& key, + const dictionary& dict, + const streamFormat deflt +) +{ + return formatNames.getOrDefault(key, dict, deflt, true); // failsafe=true } Foam::IOstreamOption::compressionType -Foam::IOstreamOption::compressionEnum(const word& compName) +Foam::IOstreamOption::compressionEnum +( + const word& compName, + const compressionType deflt +) { - // Handle bad input graciously + // Handle bad input graciously. A no-op for an empty string - const Switch sw = Switch::find(compName); - if (sw.good()) + if (!compName.empty()) { - return - ( - sw - ? compressionType::COMPRESSED - : compressionType::UNCOMPRESSED - ); + const Switch sw = Switch::find(compName); + + if (sw.good()) + { + return + ( + sw + ? compressionType::COMPRESSED + : compressionType::UNCOMPRESSED + ); + } + + // Fall-through to warning + + WarningInFunction + << "Unknown compression specifier '" << compName + << "', using compression " + << (deflt ? "on" : "off" ) << nl; } - WarningInFunction - << "Unknown compression specifier '" << compName - << "', assuming no compression" << endl; - - return compressionType::UNCOMPRESSED; + return deflt; } -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // +Foam::IOstreamOption::compressionType +Foam::IOstreamOption::compressionEnum +( + const word& key, + const dictionary& dict, + const compressionType deflt +) +{ + return + ( + Switch(key, dict, Switch(bool(deflt)), true) // failsafe=true + ? compressionType::COMPRESSED + : compressionType::UNCOMPRESSED + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::IOstreamOption::versionNumber::versionNumber(const std::string& verNum) +: + versionNumber(readFloat(verNum)) +{} + + +Foam::IOstreamOption::versionNumber::versionNumber(const token& tok) +: + versionNumber() +{ + if (tok.isStringType()) + { + (*this) = versionNumber(tok.stringToken()); + } + else if (tok.isScalar()) + { + (*this) = versionNumber(float(tok.scalarToken())); + } + else + { + WarningInFunction + << "Wrong token for version - expected word/float, found " + << tok.info() << nl; + } +} + + +Foam::IOstreamOption::versionNumber::versionNumber +( + const word& key, + const dictionary& dict +) +: + versionNumber() +{ + token tok; + + if (dict.readIfPresent(key, tok, keyType::LITERAL)) + { + (*this) = versionNumber(tok); + } +} + + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // Foam::Ostream& Foam::operator<< ( Ostream& os, - const IOstreamOption::streamFormat& sf + const IOstreamOption::streamFormat& fmt ) { - os << IOstreamOption::formatNames[sf]; + os << IOstreamOption::formatNames[fmt]; return os; } @@ -106,12 +201,13 @@ Foam::Ostream& Foam::operator<< Foam::Ostream& Foam::operator<< ( Ostream& os, - const IOstreamOption::versionNumber& vn + const IOstreamOption::versionNumber& ver ) { - // Emit as char sequence instead of as individual characters - // in case this is needed for sending in parallel. - os << vn.str().c_str(); + // Emit unquoted char sequence (eg, word) + // for correct behaviour when sending in parallel + + os.writeQuoted(ver.str(), false); return os; } diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H index 949949faf6..84b7df0036 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstreamOption.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,7 +29,13 @@ Class Description The IOstreamOption is a simple container for options an IOstream - can normally have. For example, ascii/binary, uncompressed/compressed, ... + can normally have. + + The format (ASCII | BINARY) is typically controlled by enumerated + names (ascii, binary). + + The compression (UNCOMPRESSED | COMPRESSED) is typically controlled + by switch values (true/false, on/off, ...). SourceFiles IOstreamOption.C @@ -39,7 +45,6 @@ SourceFiles #ifndef IOstreamOption_H #define IOstreamOption_H -#include "scalar.H" #include "word.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,8 +52,9 @@ SourceFiles namespace Foam { -// Forward declarations -class Ostream; +// Forward Declarations +class token; +class dictionary; template class Enum; /*---------------------------------------------------------------------------*\ @@ -64,7 +70,7 @@ public: //- Data format (ascii | binary) enum streamFormat : char { - ASCII, //!< "ascii" + ASCII = 0, //!< "ascii" (normal default) BINARY //!< "binary" }; @@ -86,6 +92,13 @@ public: // Constructors + //- Default construct \em current version. + //- The value (2.0) corresponds to the \em current version. + constexpr versionNumber() noexcept + : + number_(20) + {} + //- Construct from major, number constexpr versionNumber(int major, int minor) noexcept : @@ -98,36 +111,40 @@ public: 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)) - {} + explicit versionNumber(const std::string& verNum); + + //- Construct from token (float, word, string) + explicit versionNumber(const token& tok); + + //- Failsafe construct from dictionary lookup. + versionNumber(const word& keyword, const dictionary& dict); // Member Functions + //- Compare differences in the versions + // Negative when 'this' is less than other. + // Positive when 'this' is greater than other. + int compare(const versionNumber& other) const noexcept + { + return number_ - other.number_; + } + //- The canonical major/minor pair as an integer value. - inline int canonical() noexcept + int canonical() noexcept { return number_; } //- Return the major version number. - inline int getMajor() const noexcept + int getMajor() const noexcept { return int(number_ / 10); } //- Return the minor version number - inline int getMinor() const noexcept + int getMinor() const noexcept { return int(number_ % 10); } @@ -140,45 +157,6 @@ public: + '.' + std::to_string(getMinor()); } - - - // 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_; - } }; @@ -187,7 +165,7 @@ public: //- Stream format names (ascii, binary) static const Enum formatNames; - //- The current version number + //- The current version number (2.0) static const versionNumber currentVersion; @@ -195,7 +173,8 @@ private: // Private Data - // NB: ordered with adjacent enums to minimize gaps + // NB: ordered with versionNumber first (short) and + // adjacent enums to minimize gaps //- Stream version number (eg, 2.0 for current dictionary format) versionNumber version_; @@ -211,58 +190,98 @@ 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 + //- Default construct (ASCII, UNCOMPRESSED, currentVersion) + //- or construct with format, compression + // \note non-explicit for convenient construction + constexpr IOstreamOption ( - streamFormat format, - compressionType compression, - versionNumber version=currentVersion + streamFormat fmt = streamFormat::ASCII, + compressionType comp = compressionType::UNCOMPRESSED ) noexcept : - version_(version), - format_(format), - compression_(compression) + version_(), + format_(fmt), + compression_(comp) {} - //- Construct with format, version, compression - IOstreamOption + //- Construct from components (format, compression, version) + constexpr IOstreamOption ( - streamFormat format, - versionNumber version, - compressionType compression + streamFormat fmt, + compressionType comp, + versionNumber ver ) noexcept : - version_(version), - format_(format), - compression_(compression) + version_(ver), + format_(fmt), + compression_(comp) + {} + + //- Construct from components (format, version, compression) + constexpr IOstreamOption + ( + streamFormat fmt, + versionNumber ver, + compressionType comp = compressionType::UNCOMPRESSED + ) noexcept + : + version_(ver), + format_(fmt), + compression_(comp) + {} + + //- Copy construct with change of format + IOstreamOption(const IOstreamOption& opt, streamFormat fmt) noexcept + : + version_(opt.version_), + format_(fmt), + compression_(opt.compression_) {} // Static Member Functions //- The stream format enum corresponding to the string - // Expected "ascii", "binary" - static streamFormat formatEnum(const word& formatName); + //- (ascii | binary). + // + // If the string is not recognized, emit warning and return default. + // Silent if the string itself is empty. + // + // \note Can be used as constructor substitute for the enumeration + static streamFormat formatEnum + ( + const word& formatName, + const streamFormat deflt = streamFormat::ASCII + ); - //- The compression enum corresponding to the string - // Expected "true", "false", "on", "off", etc. - static compressionType compressionEnum(const word& compName); + //- Failsafe construct streamFormat from optional dictionary lookup + static streamFormat formatEnum + ( + const word& key, //!< Lookup key. Uses LITERAL (not REGEX) + const dictionary& dict, //!< dictionary + const streamFormat deflt = streamFormat::ASCII + ); + + //- The compression enum corresponding to the string. + // Expects switch values (true/false, on/off, ...) + // + // If the string is not recognized, emit warning and return default. + // Silent if the string itself is empty. + // + // \note Can be used as constructor substitute for the enumeration + static compressionType compressionEnum + ( + const word& compName, + const compressionType deflt = compressionType::UNCOMPRESSED + ); + + //- Failsafe construct compressionType from optional dictionary lookup + static compressionType compressionEnum + ( + const word& key, //!< Lookup key. Uses LITERAL (not REGEX) + const dictionary& dict, //!< dictionary + const compressionType deflt = compressionType::UNCOMPRESSED + ); // Member Functions @@ -275,19 +294,21 @@ public: //- Set the stream format // \return the previous value - streamFormat format(const streamFormat format) noexcept + streamFormat format(const streamFormat fmt) noexcept { streamFormat old(format_); - format_ = format; + format_ = fmt; return old; } - //- Set the stream format, from string value + //- Set the stream format from string value. + // If the string is not recognized, emit warning and leave unchanged. + // Silent if the string itself is empty. // \return the previous value streamFormat format(const word& formatName) { streamFormat old(format_); - format_ = formatEnum(formatName); + format_ = formatEnum(formatName, format_); return old; } @@ -306,12 +327,14 @@ public: return old; } - //- Set the stream compression, from string value. + //- Set the stream compression from string value. + // If the string is not recognized, emit warning and leave unchanged. + // Silent if the string itself is empty. // \return the previous value - compressionType compression(const word& compressionName) + compressionType compression(const word& compName) { compressionType old(compression_); - compression_ = compressionEnum(compressionName); + compression_ = compressionEnum(compName, compression_); return old; } @@ -323,20 +346,92 @@ public: //- Set the stream version // \return the previous value - versionNumber version(const versionNumber verNum) noexcept + versionNumber version(const versionNumber ver) noexcept { versionNumber old(version_); - version_ = verNum; + version_ = ver; + return old; + } + + //- Set the stream version from token + // \return the previous value + versionNumber version(const token& tok) + { + versionNumber old(version_); + version_ = versionNumber(tok); return old; } }; -//- Output the format as text string (ascii | binary) -Ostream& operator<<(Ostream& os, const IOstreamOption::streamFormat& sf); +//- Output format type as text string (ascii | binary) +Ostream& operator<<(Ostream& os, const IOstreamOption::streamFormat& fmt); -//- Output the version as major.minor -Ostream& operator<<(Ostream& os, const IOstreamOption::versionNumber& vn); +//- Output version as major.minor text string +Ostream& operator<<(Ostream& os, const IOstreamOption::versionNumber& ver); + + +// Comparison Operators + +//- Version number equality +inline bool operator== +( + const IOstreamOption::versionNumber& a, + const IOstreamOption::versionNumber& b +) noexcept +{ + return a.compare(b) == 0; +} + +//- Version number inequality +inline bool operator!= +( + const IOstreamOption::versionNumber& a, + const IOstreamOption::versionNumber& b +) noexcept +{ + return a.compare(b) != 0; +} + +//- Version A older than B +inline bool operator< +( + const IOstreamOption::versionNumber& a, + const IOstreamOption::versionNumber& b +) noexcept +{ + return a.compare(b) < 0; +} + +//- Version A same or older than B +inline bool operator<= +( + const IOstreamOption::versionNumber& a, + const IOstreamOption::versionNumber& b +) noexcept +{ + return a.compare(b) <= 0; +} + +//- Version A newer than B +inline bool operator> +( + const IOstreamOption::versionNumber& a, + const IOstreamOption::versionNumber& b +) noexcept +{ + return a.compare(b) > 0; +} + +//- Version A same or newer than B +inline bool operator>= +( + const IOstreamOption::versionNumber& a, + const IOstreamOption::versionNumber& b +) noexcept +{ + return a.compare(b) >= 0; +} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index 46c878bb4f..177733f53b 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -360,13 +360,7 @@ void Foam::Time::readDict() if (controlDict_.found("writeVersion")) { - writeStreamOption_.version - ( - IOstreamOption::versionNumber - ( - controlDict_.get("writeVersion") - ) - ); + writeStreamOption_.version(controlDict_.get("writeVersion")); } if (controlDict_.found("writeFormat")) diff --git a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C index f951e510f5..dc67743c66 100644 --- a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C +++ b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -381,8 +381,8 @@ bool Foam::functionObjects::vtkCloud::read(const dictionary& dict) writeOpts_.ascii ( - dict.found("format") - && (IOstream::formatEnum(dict.get("format")) == IOstream::ASCII) + IOstream::ASCII + == IOstream::formatEnum("format", dict, IOstream::BINARY) ); writeOpts_.append(false); // No append supported @@ -390,11 +390,7 @@ bool Foam::functionObjects::vtkCloud::read(const dictionary& dict) writeOpts_.precision ( - dict.lookupOrDefault - ( - "precision", - IOstream::defaultPrecision() - ) + dict.getOrDefault("precision", IOstream::defaultPrecision()) ); // Info<< type() << " " << name() << " output-format: " diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.C b/src/functionObjects/utilities/ensightWrite/ensightWrite.C index 06bcdacad4..1a52c72117 100644 --- a/src/functionObjects/utilities/ensightWrite/ensightWrite.C +++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -80,13 +80,7 @@ Foam::functionObjects::ensightWrite::ensightWrite writeOpts_(), caseOpts_ ( - IOstreamOption::formatNames.lookupOrDefault - ( - "format", - dict, - runTime.writeFormat(), - true // Failsafe behaviour - ) + IOstreamOption::formatEnum("format", dict, runTime.writeFormat()) ), outputDir_(), consecutive_(false), diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.C b/src/functionObjects/utilities/vtkWrite/vtkWrite.C index 036bd93ddc..f32203fc6b 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWrite.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -183,22 +183,15 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict) writeOpts_.ascii ( - dict.found("format") - && (IOstream::formatEnum(dict.get("format")) == IOstream::ASCII) + IOstream::ASCII + == IOstream::formatEnum("format", dict, IOstream::BINARY) ); - if (dict.lookupOrDefault("legacy", false)) - { - writeOpts_.legacy(true); - } + writeOpts_.legacy(dict.getOrDefault("legacy", false)); writeOpts_.precision ( - dict.lookupOrDefault - ( - "precision", - IOstream::defaultPrecision() - ) + dict.getOrDefault("precision", IOstream::defaultPrecision()) ); // Info<< type() << " " << name() << " output-format: " diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C index 817960bb93..1b46d510cd 100644 --- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatCore.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,19 +40,15 @@ Foam::fileFormats::VTKsurfaceFormatCore::formatOptions opts.legacy(true); // Legacy. Use VTPsurfaceFormat for non-legacy opts.append(false); // No append format for legacy - const word formatName = dict.lookupOrDefault("format", ""); - if (formatName.size()) - { - opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII); - } + opts.ascii + ( + IOstream::ASCII + == IOstream::formatEnum("format", dict, IOstream::ASCII) + ); opts.precision ( - dict.lookupOrDefault - ( - "precision", - IOstream::defaultPrecision() - ) + dict.getOrDefault("precision", IOstream::defaultPrecision()) ); return opts; diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C index 175c35f1fb..b772c23b83 100644 --- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormatCore.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,19 +40,15 @@ Foam::fileFormats::VTPsurfaceFormatCore::formatOptions opts.legacy(false); // Non-legacy. Use VTKsurfaceFormat for legacy opts.append(false); // No append format - const word formatName = dict.lookupOrDefault("format", ""); - if (formatName.size()) - { - opts.ascii(IOstream::formatEnum(formatName) == IOstream::ASCII); - } + opts.ascii + ( + IOstream::ASCII + == IOstream::formatEnum("format", dict, IOstream::BINARY) + ); opts.precision ( - dict.lookupOrDefault - ( - "precision", - IOstream::defaultPrecision() - ) + dict.getOrDefault("precision", IOstream::defaultPrecision()) ); return opts; diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriter.C b/src/surfMesh/writers/ensight/ensightSurfaceWriter.C index 19d2aae5c0..63da829751 100644 --- a/src/surfMesh/writers/ensight/ensightSurfaceWriter.C +++ b/src/surfMesh/writers/ensight/ensightSurfaceWriter.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -188,13 +188,7 @@ Foam::surfaceWriters::ensightWriter::ensightWriter surfaceWriter(options), writeFormat_ ( - IOstreamOption::formatNames.getOrDefault - ( - "format", - options, - IOstreamOption::ASCII, - true // Failsafe behaviour - ) + IOstreamOption::formatEnum("format", options, IOstream::ASCII) ), collateTimes_(options.getOrDefault("collateTimes", true)) {} diff --git a/src/surfMesh/writers/raw/rawSurfaceWriter.C b/src/surfMesh/writers/raw/rawSurfaceWriter.C index 9b13c1e645..90831e92c8 100644 --- a/src/surfMesh/writers/raw/rawSurfaceWriter.C +++ b/src/surfMesh/writers/raw/rawSurfaceWriter.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,10 +84,7 @@ Foam::surfaceWriters::rawWriter::rawWriter surfaceWriter(options), writeCompression_ ( - IOstream::compressionEnum - ( - options.lookupOrDefault("compression", "false") - ) + IOstream::compressionEnum("compression", options) ) {} diff --git a/src/surfMesh/writers/vtk/vtkSurfaceWriter.C b/src/surfMesh/writers/vtk/vtkSurfaceWriter.C index 2209285382..2d11dbb012 100644 --- a/src/surfMesh/writers/vtk/vtkSurfaceWriter.C +++ b/src/surfMesh/writers/vtk/vtkSurfaceWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -104,19 +104,13 @@ Foam::surfaceWriters::vtkWriter::vtkWriter vtk::outputOptions opts(vtk::formatType::INLINE_BASE64); - const word formatName = options.lookupOrDefault("format", ""); - if (formatName.size()) - { - opts.ascii - ( - IOstream::formatEnum(formatName) == IOstream::ASCII - ); - } + opts.ascii + ( + IOstream::ASCII + == IOstream::formatEnum("format", options, IOstream::BINARY) + ); - if (options.lookupOrDefault("legacy", false)) - { - opts.legacy(true); - } + opts.legacy(options.getOrDefault("legacy", false)); // Convert back to raw data type fmtType_ = static_cast(opts.fmt());