A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none. More...
Public Types | |
enum | switchType : unsigned char { FALSE = 0, TRUE = 1, NO = 2, YES = 3, OFF = 4, ON = 5, NONE = 6, ANY = 7, INVALID = 8 } |
Switch enumerations corresponding to common text representations. More... | |
Public Member Functions | |
Switch (const Switch &) noexcept=default | |
Copy construct. More... | |
Switch & | operator= (const Switch &) noexcept=default |
Copy assignment. More... | |
constexpr | Switch () noexcept |
Default construct as false. More... | |
constexpr | Switch (const switchType sw) noexcept |
Construct from enumerated value. More... | |
constexpr | Switch (const bool b) noexcept |
Construct from bool. More... | |
constexpr | Switch (const int i) noexcept |
Construct from int (treat integer as bool value) More... | |
Switch (const std::string &str) | |
Construct from string - catches bad input. More... | |
Switch (const char *str) | |
Construct from character array - catches bad input. More... | |
Switch (const float val, const float tol=0.5) | |
Switch (const double val, const double tol=0.5) | |
Switch (const token &tok) | |
Construct from token. Handles bool/label/word types. More... | |
Switch (const word &key, const dictionary &dict) | |
Construct from dictionary lookup. More... | |
Switch (const word &key, const dictionary &dict, const Switch deflt, const bool failsafe=false) | |
Switch (Istream &is) | |
Construct from Istream by reading a token. More... | |
bool | good () const noexcept |
True if the Switch represents a valid enumeration. More... | |
bool | bad () const noexcept |
True if the Switch does not represent a valid enumeration. More... | |
switchType | type () const noexcept |
The underlying enumeration value. More... | |
const char * | c_str () const noexcept |
A C-string representation of the Switch value. More... | |
std::string | str () const |
A string representation of the Switch value. More... | |
bool | readIfPresent (const word &key, const dictionary &dict) |
Update the value of the Switch if it is found in the dictionary. More... | |
operator bool () const noexcept | |
Conversion to bool. More... | |
Switch & | operator= (const switchType sw) noexcept |
Assignment from enumerated value. More... | |
Switch & | operator= (const bool b) noexcept |
Assignment from bool. More... | |
Switch (const std::string &str, bool allowBad) | |
Deprecated(2020-01) From string with/without bad input test. More... | |
Switch (const char *str, bool allowBad) | |
Deprecated(2020-01) From string with/without bad input test. More... | |
FOAM_DEPRECATED_FOR (2019-02, "good() or static found() method") bool valid() const noexcept | |
Deprecated(2020-01) Use good() method, or static found() method. More... | |
Static Public Member Functions | |
static Switch | getOrAddToDict (const word &key, dictionary &dict, const Switch deflt=switchType::FALSE) |
static const char * | name (const bool b) noexcept |
A string representation of bool as "false" / "true". More... | |
static Switch | find (const std::string &str) |
static bool | found (const std::string &str) |
Test if there is a switch type corresponding to the given string. More... | |
static Switch | lookupOrAddToDict (const word &name, dictionary &dict, const Switch deflt=switchType::FALSE) |
Same as getOrAddToDict() More... | |
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
enum switchType : unsigned char |
Switch enumerations corresponding to common text representations.
Enumerator | |
---|---|
FALSE | "false" |
TRUE | "true" |
NO | "no" |
YES | "yes" |
OFF | "off" |
ON | "on" |
NONE | "none" |
ANY | "any" |
INVALID | "invalid" |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
explicit |
|
explicit |
|
explicit |
|
explicit |
Construct from token. Handles bool/label/word types.
Definition at line 212 of file Switch.C.
References bool, token::boolToken(), token::good(), token::isBool(), token::isLabel(), token::isWord(), token::labelToken(), and token::wordToken().
Switch | ( | const word & | key, |
const dictionary & | dict | ||
) |
Construct from dictionary lookup.
FatalError if anything is incorrect.
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
Definition at line 235 of file Switch.C.
References dict, Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, dictionary::get(), Switch::good(), keyType::LITERAL, and Foam::printTokenError().
Switch | ( | const word & | key, |
const dictionary & | dict, | ||
const Switch | deflt, | ||
const bool | failsafe = false |
||
) |
Find the key in the dictionary and use the corresponding switch value or the default if not found in dictionary.
FatalIOError if the switch name is incorrect. Specifying failsafe downgrades the FatalIOError to an IOWarning.
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
deflt | fallback if not found |
failsafe | Warn only on bad input |
Definition at line 259 of file Switch.C.
References Switch::c_str(), dict, Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Switch::good(), IOWarningInFunction, keyType::LITERAL, Foam::printTokenError(), and dictionary::readIfPresent().
Deprecated(2020-01) From string with/without bad input test.
Deprecated(2020-01) From string with/without bad input test.
|
static |
Construct from dictionary, supplying default value so that if the value is not found, it is added into the dictionary.
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
deflt | default value to add |
Definition at line 164 of file Switch.C.
References dict, dictionary::getOrAdd(), and keyType::LITERAL.
Referenced by Switch::lookupOrAddToDict().
|
staticnoexcept |
A string representation of bool as "false" / "true".
Definition at line 145 of file Switch.C.
References Foam::constant::physicoChemical::b.
Referenced by boolEntry::evaluate(), Switch::lookupOrAddToDict(), ensightMesh::options::print(), and attachDetach::writeDict().
|
static |
|
static |
|
noexcept |
True if the Switch represents a valid enumeration.
Definition at line 300 of file Switch.C.
Referenced by Switch::bad(), IOstreamOption::compressionEnum(), isoSurfaceBase::getFilterType(), isTrue(), Foam::operator>>(), scalarRange::parse(), and Switch::Switch().
|
inlinenoexcept |
True if the Switch does not represent a valid enumeration.
Definition at line 224 of file Switch.H.
References Switch::good().
|
noexcept |
|
noexcept |
A C-string representation of the Switch value.
Definition at line 312 of file Switch.C.
Referenced by Foam::operator<<(), and Switch::Switch().
std::string str | ( | ) | const |
bool readIfPresent | ( | const word & | key, |
const dictionary & | dict | ||
) |
Update the value of the Switch if it is found in the dictionary.
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
Definition at line 325 of file Switch.C.
References dict, keyType::LITERAL, and dictionary::readIfPresent().
Referenced by qZeta::read().
|
inlinenoexcept |
Assignment from bool.
Definition at line 259 of file Switch.H.
References Foam::constant::physicoChemical::b, Switch::FALSE, and Switch::TRUE.
|
inlinenoexcept |
|
inlinestatic |
Same as getOrAddToDict()
Definition at line 288 of file Switch.H.
References dict, Switch::getOrAddToDict(), and Switch::name().