mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: allow single-character 't' and 'f' aliases for bool/Switch
This commit is contained in:
@ -37,6 +37,7 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
|
||||
"off", "on",
|
||||
"no", "yes",
|
||||
"n", "y",
|
||||
"f", "t",
|
||||
"none", "true", // is there a reasonable counterpart to "none"?
|
||||
"invalid"
|
||||
};
|
||||
@ -54,18 +55,39 @@ Foam::Switch::switchType Foam::Switch::asEnum
|
||||
{
|
||||
if (str == names[sw])
|
||||
{
|
||||
// convert n/y to no/yes - perhaps should deprecate y/n
|
||||
if (sw == Switch::NO_1 || sw == Switch::NONE)
|
||||
// handle aliases
|
||||
switch (sw)
|
||||
{
|
||||
return Switch::NO;
|
||||
}
|
||||
else if (sw == Switch::YES_1)
|
||||
{
|
||||
return Switch::YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return switchType(sw);
|
||||
case Switch::NO_1:
|
||||
case Switch::NONE:
|
||||
{
|
||||
return Switch::NO;
|
||||
break;
|
||||
}
|
||||
|
||||
case Switch::YES_1:
|
||||
{
|
||||
return Switch::YES;
|
||||
break;
|
||||
}
|
||||
|
||||
case Switch::FALSE_1:
|
||||
{
|
||||
return Switch::FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
case Switch::TRUE_1:
|
||||
{
|
||||
return Switch::TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return switchType(sw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,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 or none.
|
||||
true/false, on/off, yes/no, y/n, t/f, or none.
|
||||
|
||||
SourceFiles
|
||||
Switch.C
|
||||
@ -78,6 +78,8 @@ public:
|
||||
#undef YES
|
||||
#undef NO_1
|
||||
#undef YES_1
|
||||
#undef FALSE_1
|
||||
#undef TRUE_1
|
||||
#undef NONE
|
||||
#undef PLACEHOLDER
|
||||
#undef INVALID
|
||||
@ -86,11 +88,12 @@ public:
|
||||
// These also correspond to the entries in names.
|
||||
enum switchType
|
||||
{
|
||||
FALSE = 0, TRUE = 1,
|
||||
OFF = 2, ON = 3,
|
||||
NO = 4, YES = 5,
|
||||
NO_1 = 6, YES_1 = 7,
|
||||
NONE = 8, PLACEHOLDER = 9,
|
||||
FALSE = 0, TRUE = 1,
|
||||
OFF = 2, ON = 3,
|
||||
NO = 4, YES = 5,
|
||||
NO_1 = 6, YES_1 = 7,
|
||||
FALSE_1 = 8, TRUE_1 = 9,
|
||||
NONE = 10, PLACEHOLDER = 11,
|
||||
INVALID
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user