mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add Switch::negate() method (no-op for invalid state)
- flips state while preserving the textual representation. Eg, OFF <-> ON, YES <-> NO etc. - fix test case to avoid triggering abort(), which we cannot try/catch
This commit is contained in:
@ -309,6 +309,16 @@ Foam::Switch::switchType Foam::Switch::type() const noexcept
|
||||
}
|
||||
|
||||
|
||||
void Foam::Switch::negate() noexcept
|
||||
{
|
||||
if (value_ < switchType::INVALID)
|
||||
{
|
||||
// Toggle final bit. So NO <-> YES, OFF <-> ON ...
|
||||
value_ ^= 0x1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char* Foam::Switch::c_str() const noexcept
|
||||
{
|
||||
return names[(value_ & 0x0F)];
|
||||
|
||||
@ -91,7 +91,7 @@ public:
|
||||
NO = 2 /*!< "no" */, YES = 3 /*!< "yes" */,
|
||||
OFF = 4 /*!< "off" */, ON = 5 /*!< "on" */,
|
||||
NONE = 6 /*!< "none" */, ANY = 7 /*!< "any" */,
|
||||
INVALID = 8 /*!< "invalid" */,
|
||||
INVALID = 8 /*!< "invalid" (output only) */,
|
||||
};
|
||||
|
||||
|
||||
@ -227,6 +227,10 @@ public:
|
||||
//- The underlying enumeration value
|
||||
switchType type() const noexcept;
|
||||
|
||||
//- Flip the type, so OFF becomes ON, etc.
|
||||
// Ignored if the Switch is INVALID
|
||||
void negate() noexcept;
|
||||
|
||||
//- A C-string representation of the Switch value
|
||||
const char* c_str() const noexcept;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user