Commit ad1f99ff authored by Mark Olesen's avatar Mark Olesen
Browse files

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.
parent a17daf7f
......@@ -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
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment