mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'master' of ssh://noisy/home/noisy3/OpenFOAM/OpenFOAM-dev
This commit is contained in:
@ -38,20 +38,20 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
|
||||
"off", "on",
|
||||
"no", "yes",
|
||||
"n", "y",
|
||||
"none", "true", // is there a reasonable counterpart to "none"?
|
||||
"invalid"
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Switch::switchType Foam::Switch::asEnum(const bool val)
|
||||
Foam::Switch::switchType Foam::Switch::asEnum(const bool b)
|
||||
{
|
||||
return val ? Switch::TRUE : Switch::FALSE;
|
||||
return b ? Switch::TRUE : Switch::FALSE;
|
||||
}
|
||||
|
||||
|
||||
Foam::Switch::switchType
|
||||
Foam::Switch::asEnum
|
||||
Foam::Switch::switchType Foam::Switch::asEnum
|
||||
(
|
||||
const std::string& str,
|
||||
const bool allowInvalid
|
||||
@ -61,8 +61,8 @@ Foam::Switch::asEnum
|
||||
{
|
||||
if (str == names[sw])
|
||||
{
|
||||
// convert y/n to yes/no (perhaps should deprecate y/n)
|
||||
if (sw == Switch::NO_1)
|
||||
// convert n/y to no/yes (perhaps should deprecate y/n)
|
||||
if (sw == Switch::NO_1 || sw == Switch::NONE)
|
||||
{
|
||||
return Switch::NO;
|
||||
}
|
||||
@ -90,6 +90,7 @@ Foam::Switch::asEnum
|
||||
|
||||
bool Foam::Switch::asBool(const switchType sw)
|
||||
{
|
||||
// relies on (INVALID & 0x1) evaluating to false
|
||||
return (sw & 0x1);
|
||||
}
|
||||
|
||||
@ -103,13 +104,19 @@ bool Foam::Switch::asBool
|
||||
// allow invalid values, but catch after for correct error message
|
||||
switchType sw = asEnum(str, true);
|
||||
|
||||
if (sw == Switch::INVALID && !allowInvalid)
|
||||
if (sw == Switch::INVALID)
|
||||
{
|
||||
FatalErrorIn("Switch::asBool(const std::string&)")
|
||||
<< "unknown switch word " << str << nl
|
||||
<< abort(FatalError);
|
||||
if (!allowInvalid)
|
||||
{
|
||||
FatalErrorIn("Switch::asBool(const std::string&)")
|
||||
<< "unknown switch word " << str << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return (sw & 0x1);
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ Class
|
||||
|
||||
Description
|
||||
A simple wrapper around bool so that it can be read as a word:
|
||||
true/false, on/off, yes/no or y/n.
|
||||
true/false, on/off, yes/no or y/n or none.
|
||||
|
||||
SourceFiles
|
||||
Switch.C
|
||||
@ -80,6 +80,7 @@ public:
|
||||
OFF = 2, ON = 3,
|
||||
NO = 4, YES = 5,
|
||||
NO_1 = 6, YES_1 = 7,
|
||||
NONE = 8, PLACEHOLDER = 9,
|
||||
INVALID
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user