diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.C b/src/OpenFOAM/primitives/bools/Switch/Switch.C index 9b7b449a226452dab9f93d65966c3f472659bc2d..8648532a32d30d5609cccee44d57677d8bc13cbb 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.C +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.C @@ -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); } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.H b/src/OpenFOAM/primitives/bools/Switch/Switch.H index 4eaa2dd12b532e9618e6489ff29d2b23d01d92f3..adda09cf4ecfa2895f61f167f3d66d300b79b845 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.H +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.H @@ -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 };