ENH: allow single-character 't' and 'f' aliases for bool/Switch

This commit is contained in:
Mark Olesen
2010-09-14 11:42:25 +02:00
parent 0f57f4ec8a
commit 2a37f5b11c
2 changed files with 42 additions and 17 deletions

View File

@ -37,6 +37,7 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
"off", "on", "off", "on",
"no", "yes", "no", "yes",
"n", "y", "n", "y",
"f", "t",
"none", "true", // is there a reasonable counterpart to "none"? "none", "true", // is there a reasonable counterpart to "none"?
"invalid" "invalid"
}; };
@ -54,18 +55,39 @@ Foam::Switch::switchType Foam::Switch::asEnum
{ {
if (str == names[sw]) if (str == names[sw])
{ {
// convert n/y to no/yes - perhaps should deprecate y/n // handle aliases
if (sw == Switch::NO_1 || sw == Switch::NONE) switch (sw)
{
case Switch::NO_1:
case Switch::NONE:
{ {
return Switch::NO; return Switch::NO;
break;
} }
else if (sw == Switch::YES_1)
case Switch::YES_1:
{ {
return Switch::YES; return Switch::YES;
break;
} }
else
case Switch::FALSE_1:
{
return Switch::FALSE;
break;
}
case Switch::TRUE_1:
{
return Switch::TRUE;
break;
}
default:
{ {
return switchType(sw); return switchType(sw);
break;
}
} }
} }
} }

View File

@ -26,7 +26,7 @@ Class
Description Description
A simple wrapper around bool so that it can be read as a word: 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 SourceFiles
Switch.C Switch.C
@ -78,6 +78,8 @@ public:
#undef YES #undef YES
#undef NO_1 #undef NO_1
#undef YES_1 #undef YES_1
#undef FALSE_1
#undef TRUE_1
#undef NONE #undef NONE
#undef PLACEHOLDER #undef PLACEHOLDER
#undef INVALID #undef INVALID
@ -90,7 +92,8 @@ public:
OFF = 2, ON = 3, OFF = 2, ON = 3,
NO = 4, YES = 5, NO = 4, YES = 5,
NO_1 = 6, YES_1 = 7, NO_1 = 6, YES_1 = 7,
NONE = 8, PLACEHOLDER = 9, FALSE_1 = 8, TRUE_1 = 9,
NONE = 10, PLACEHOLDER = 11,
INVALID INVALID
}; };