A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n. More...
#include <Switch.H>
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. | |
| Switch & | operator= (const Switch &) noexcept=default |
| Copy assignment. | |
| constexpr | Switch () noexcept |
| Default construct as false. | |
| constexpr | Switch (switchType sw) noexcept |
| Implicit construct from enumerated value. | |
| constexpr | Switch (bool b) noexcept |
| Implicit construct from bool. | |
| constexpr | Switch (int i) noexcept |
| Implicit construct from int (treat integer as bool value). | |
| Switch (const char *s) | |
| Construct from character array - catches bad input. | |
| Switch (const std::string &s) | |
| Construct from string - catches bad input. | |
| Switch (std::string_view s) | |
| Construct from string_view - catches bad input. | |
| Switch (const float val, const float tol=0.5) | |
| Construct from float with rounding to zero given by the tolerance (default: 0.5). | |
| Switch (const double val, const double tol=0.5) | |
| Construct from double with rounding to zero given by the tolerance (default: 0.5). | |
| Switch (const token &tok) | |
| Construct from token. Handles bool/label/word types. | |
| Switch (const word &key, const dictionary &dict) | |
| Construct from dictionary lookup. | |
| Switch (const word &key, const dictionary &dict, const Switch deflt, const bool warnOnly=false) | |
| Find the key in the dictionary and use the corresponding switch value or the default if not found in dictionary. | |
| Switch (Istream &is) | |
| Construct from Istream by reading a token. | |
| bool | good () const noexcept |
| True if the Switch represents a valid enumeration. | |
| bool | bad () const noexcept |
| True if the Switch does not represent a valid enumeration. | |
| switchType | type () const noexcept |
| The underlying enumeration value. | |
| void | negate () noexcept |
| Flip the type, so OFF becomes ON, etc. | |
| const char * | c_str () const noexcept |
| A C-string representation of the Switch value. | |
| std::string | str () const |
| A string representation of the Switch value. | |
| bool | readIfPresent (const word &key, const dictionary &dict) |
| Update the value of the Switch if it is found in the dictionary. | |
| bool | is_any () const noexcept |
| Test for 'any' type. | |
| bool | is_none () const noexcept |
| Test for 'none' type. | |
| operator bool () const noexcept | |
| Conversion to bool. | |
| Switch & | operator= (switchType sw) noexcept |
| Assignment from enumerated value. | |
| Switch & | operator= (bool b) noexcept |
| Assignment from bool. | |
| Switch (const std::string &str, bool allowBad) | |
| Deprecated(2020-01) From string with/without bad input test. | |
| Switch (const char *str, bool allowBad) | |
| Deprecated(2020-01) From string with/without bad input test. | |
| FOAM_DEPRECATED_FOR (2019-02, "good() or static contains() method") bool valid() const noexcept | |
| Deprecated(2020-01) Use good() method, or static contains() method. | |
Static Public Member Functions | |
| static Switch | getOrDefault (const word &key, const dictionary &dict, const Switch deflt=switchType::FALSE) |
| Construct Switch from dictionary, with default value. | |
| static Switch | getOrAddToDict (const word &key, dictionary &dict, const Switch deflt=switchType::FALSE) |
| Construct from dictionary, supplying default value so that if the value is not found, it is added into the dictionary. | |
| static const char * | name (bool b) noexcept |
| A string representation of bool as "false" / "true". | |
| static bool | contains (std::string_view s) noexcept |
| True if there is a switch type corresponding to the given string. | |
| static Switch | find (const char *s) |
| Find switchType for the given string, returning a Switch that can be tested for good() or bad(). | |
| static Switch | find (const std::string &s) noexcept |
| Find switchType for the given string, returning a Switch that can be tested for good() or bad(). | |
| static Switch | find (std::string_view s) noexcept |
| Find switchType for the given string, returning a Switch that can be tested for good() or bad(). | |
| static bool | found (const std::string &str) |
| Same as contains(). | |
| static Switch | lookupOrAddToDict (const word &name, dictionary &dict, const Switch deflt=switchType::FALSE) |
| Same as getOrAddToDict(). | |
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
| 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" (output only) |
|
defaultnoexcept |
Copy construct.
References Switch().
Referenced by find(), find(), find(), getOrAddToDict(), getOrDefault(), lookupOrAddToDict(), operator=(), operator=(), operator=(), Switch(), Switch(), Switch(), and Switch().


|
inlineconstexprnoexcept |
Default construct as false.
Definition at line 147 of file Switch.H.
References FALSE, and Foam::noexcept.
|
inlineconstexprnoexcept |
Implicit construct from enumerated value.
Definition at line 155 of file Switch.H.
References Foam::noexcept.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Implicit construct from int (treat integer as bool value).
Definition at line 171 of file Switch.H.
References FALSE, Foam::noexcept, and TRUE.
|
explicit |
|
explicit |
|
explicit |
|
explicit |
Construct from float with rounding to zero given by the tolerance (default: 0.5).
|
explicit |
Construct from double with rounding to zero given by the tolerance (default: 0.5).
|
explicit |
Construct from token. Handles bool/label/word types.
| Switch | ( | const word & | key, |
| const dictionary & | dict ) |
| Switch | ( | const word & | key, |
| const dictionary & | dict, | ||
| const Switch | deflt, | ||
| const bool | warnOnly = 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 warnOnly downgrades the FatalIOError to an IOWarning.
| key | Lookup key. Uses LITERAL (not REGEX) |
| dict | dictionary |
| deflt | fallback if not found |
| warnOnly | Warn (not fail) on bad input |
References dict, and Switch().

| Switch | ( | const std::string & | str, |
| bool | allowBad ) |
Deprecated(2020-01) From string with/without bad input test.
References FOAM_DEPRECATED_FOR(), str(), and Switch().

| Switch | ( | const char * | str, |
| bool | allowBad ) |
Deprecated(2020-01) From string with/without bad input test.
References str(), and Switch().

|
static |
|
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 |
References dict, FALSE, and Switch().
Referenced by lookupOrAddToDict().


|
staticnoexcept |
A string representation of bool as "false" / "true".
References b.
Referenced by surfaceNoise::calculate(), debugWriter::debugWriter(), boolEntry::evaluate(), fvExprDriver::getOrReadFieldImpl(), lookupOrAddToDict(), fieldInfo::operator<<, Foam::operator<<(), ensightMesh::options::print(), mappedPatchBase::write(), profilingInformation::write(), and attachDetach::writeDict().

|
staticnoexcept |
|
static |
Find switchType for the given string, returning a Switch that can be tested for good() or bad().
Referenced by IOstreamOption::compressionEnum(), isoSurfaceParams::getFilterType(), and error::useAbort().


|
staticnoexcept |
|
staticnoexcept |
|
inlinenoexcept |
True if the Switch represents a valid enumeration.
Definition at line 307 of file Switch.H.
References INVALID, and Foam::noexcept.
Referenced by bad(), FOAM_DEPRECATED_FOR(), isoSurfaceParams::getFilterType(), and functionObjectList::read().

|
inlinenoexcept |
True if the Switch does not represent a valid enumeration.
Definition at line 312 of file Switch.H.
References good(), and Foam::noexcept.

|
inlinenoexcept |
The underlying enumeration value.
Definition at line 317 of file Switch.H.
References Foam::noexcept.
|
noexcept |
|
noexcept |
A C-string representation of the Switch value.
References c_str(), and Foam::noexcept.
Referenced by c_str().


| 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 |
References dict, and readIfPresent().
Referenced by readIfPresent().


|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestatic |
Same as contains().
Definition at line 399 of file Switch.H.
References contains(), and str().

|
inlinenoexcept |
Deprecated(2020-01) Use good() method, or static contains() method.
Definition at line 422 of file Switch.H.
References FOAM_DEPRECATED_FOR(), good(), and Foam::noexcept.
Referenced by FOAM_DEPRECATED_FOR(), and Switch().


|
inlinestatic |
Same as getOrAddToDict().
Definition at line 429 of file Switch.H.
References dict, FALSE, getOrAddToDict(), lookupOrAddToDict(), name(), and Switch().
Referenced by lookupOrAddToDict().

