mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: IOstream::compressionEnum() used Switch::switchType incorrectly
- use enhanced Switch constructor and the new valid() method to avoid potential pitfalls of using Switch::switchType directly.
This commit is contained in:
@ -61,9 +61,9 @@ Foam::IOstream::compressionType
|
||||
Foam::IOstream::compressionEnum(const word& compression)
|
||||
{
|
||||
// get Switch (bool) value, but allow it to fail
|
||||
Switch::switchType sw = Switch::asEnum(compression, true);
|
||||
Switch sw(compression, true);
|
||||
|
||||
if (sw != Switch::INVALID)
|
||||
if (sw.valid())
|
||||
{
|
||||
return sw ? IOstream::COMPRESSED : IOstream::UNCOMPRESSED;
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ Foam::Switch::switchType Foam::Switch::asEnum
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return INVALID;
|
||||
return Switch::INVALID;
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +115,6 @@ bool Foam::Switch::asBool
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return (sw & 0x1);
|
||||
}
|
||||
|
||||
|
||||
@ -53,9 +53,13 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s)
|
||||
else if (t.isWord())
|
||||
{
|
||||
// allow invalid values, but catch after for correct error message
|
||||
Switch::switchType sw = Switch::asEnum(t.wordToken(), true);
|
||||
Switch sw(t.wordToken(), true);
|
||||
|
||||
if (sw == Switch::INVALID)
|
||||
if (sw.valid())
|
||||
{
|
||||
s.switch_ = sw.switch_;
|
||||
}
|
||||
else
|
||||
{
|
||||
is.setBad();
|
||||
FatalIOErrorIn("operator>>(Istream&, Switch&)", is)
|
||||
@ -64,10 +68,6 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s)
|
||||
|
||||
return is;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.switch_ = sw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user