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:
Mark Olesen
2010-04-16 15:43:28 +02:00
parent a17daf7fcc
commit ad1f99ff71
3 changed files with 9 additions and 10 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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
{