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. More...
#include <OpenFOAM/Switch.H>
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.
Definition at line 61 of file Switch.H.
Public Types | |
enum | switchType { FALSE = 0, TRUE = 1, OFF = 2, ON = 3, NO = 4, YES = 5, NO_1 = 6, YES_1 = 7, NONE = 8, PLACEHOLDER = 9, INVALID } |
The various text representations for a switch value. More... | |
Public Member Functions | |
Switch () | |
Construct null as false.
| |
Switch (const bool value) | |
Construct from bool.
| |
Switch (const int value) | |
Construct from integer values (treats integer as bool value)
| |
Switch (const std::string &value) | |
Construct from std::string, string, word.
| |
Switch (const char *value) | |
Construct from character array.
| |
Switch (Istream &is) | |
Construct from Istream.
| |
operator bool () const | |
Conversion to bool.
| |
const Switch & | operator= (const bool b) |
Assignment from bool.
| |
bool | readIfPresent (const word &, const dictionary &) |
Update the value of the Switch if it is found in the dictionary.
| |
Static Public Member Functions | |
static switchType | asEnum (const bool) |
Return a switchType representation of a bool.
| |
static switchType | asEnum (const std::string &, const bool allowInvalid=false) |
Return a switchType representation of a word.
| |
static bool | asBool (const switchType) |
Return a bool representation of a switchType.
| |
static bool | asBool (const std::string &, const bool allowInvalid=false) |
Return a bool representation of a word.
| |
static const char * | asText (const bool) |
Return a text representation of a bool value.
| |
static const char * | asText (const switchType) |
Return a text representation of a switchType.
| |
static Switch | lookupOrAddToDict (const word &, dictionary &, const Switch &defaultValue=false) |
Construct from dictionary, supplying default value so that if the.
| |
Static Public Attributes | |
static const char * | names [INVALID+1] |
The set of names corresponding to the switchType enumeration.
| |
Friends | |
Istream & | operator>> (Istream &, Switch &) |
Ostream & | operator<< (Ostream &, const Switch &) |
enum switchType |
Switch | ( | const int | value ) | [inline]
|
Switch | ( | const std::string & | value ) | [inline]
|
Switch | ( | const char * | value ) | [inline]
|
Construct from Istream.
Definition at line 31 of file SwitchIO.C.
Foam::Switch::switchType asEnum | ( | const bool | b ) | [static]
|
Return a switchType representation of a bool.
Definition at line 47 of file Switch.C.
References Switch::FALSE, and Switch::TRUE.
Referenced by Foam::operator>>().
Foam::Switch::switchType asEnum | ( | const std::string & | str, |
const bool | allowInvalid = false
|
||
) | [static]
|
Return a switchType representation of a word.
Optionally allow bad words, and catch the error elsewhere
Definition at line 54 of file Switch.C.
References Foam::abort(), Foam::FatalError, FatalErrorIn, Switch::INVALID, Foam::nl, Switch::NO, Switch::NO_1, Switch::NONE, Switch::YES, and Switch::YES_1.
bool asBool | ( | const switchType | sw ) | [static]
|
bool asBool | ( | const std::string & | str, |
const bool | allowInvalid = false
|
||
) | [static]
|
Return a bool representation of a word.
Optionally allow bad words, and catch the error elsewhere
Definition at line 98 of file Switch.C.
References Foam::abort(), Foam::FatalError, FatalErrorIn, Switch::INVALID, and Foam::nl.
const char * asText | ( | const bool | b ) | [static]
|
Return a text representation of a bool value.
Definition at line 123 of file Switch.C.
References Switch::FALSE, and Switch::TRUE.
const char * asText | ( | const switchType | sw ) | [static]
|
Foam::Switch lookupOrAddToDict | ( | const word & | name, |
dictionary & | dict, | ||
const Switch & | defaultValue = false
|
||
) | [static]
|
Construct from dictionary, supplying default value so that if the.
value is not found, it is added into the dictionary.
Definition at line 136 of file Switch.C.
References dictionary::lookupOrAddDefault(), and Foam::name().
const Switch& operator= | ( | const bool | b ) | [inline]
|
Assignment from bool.
Definition at line 179 of file Switch.H.
References Switch::FALSE, and Switch::TRUE.
bool readIfPresent | ( | const word & | name, |
const dictionary & | dict | ||
) |
Update the value of the Switch if it is found in the dictionary.
Definition at line 148 of file Switch.C.
References Foam::name(), and dictionary::readIfPresent().
Referenced by qZeta::read().
const char * names [static]
|
{ "false", "true", "off", "on", "no", "yes", "n", "y", "none", "true", "invalid" }
The set of names corresponding to the switchType enumeration.
Includes an extra entry for "invalid".
Definition at line 91 of file Switch.H.
Referenced by Foam::operator<<().