mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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<word>("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<token>("version"));
or failsafe constructor method
is.version
(
IOstreamOption::versionNumber("version", headerDict)
);
Before (controlled input):
is.version
(
IOstreamOption::versionNumber
(
headerDict.get<float>("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
This commit is contained in:
@ -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<word>("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: "
|
||||
|
||||
Reference in New Issue
Block a user