41 "Switch::switchType does not have 9 entries" 46 static const char*
names[9] =
67 os <<
"Bad token - could not get bool/switch" <<
nl;
71 os <<
"Expected true/false, on/off... found " 76 os <<
"Wrong token - expected bool/switch, found " 89 const std::string& str,
90 const bool failOnError
99 case '0':
case 'f':
return switchType::FALSE;
100 case '1':
case 't':
return switchType::TRUE;
101 case 'n':
return switchType::NO;
102 case 'y':
return switchType::YES;
108 if (
str ==
names[switchType::NO])
return switchType::NO;
109 if (
str ==
names[switchType::ON])
return switchType::ON;
114 if (
str ==
names[switchType::OFF])
return switchType::OFF;
115 if (
str ==
names[switchType::YES])
return switchType::YES;
116 if (
str ==
names[switchType::ANY])
return switchType::ANY;
121 if (
str ==
names[switchType::NONE])
return switchType::NONE;
122 if (
str ==
names[switchType::TRUE])
return switchType::TRUE;
127 if (
str ==
names[switchType::FALSE])
return switchType::FALSE;
135 <<
"Unknown switch " <<
str <<
nl 139 return switchType::INVALID;
159 return (switchType::INVALID != parse(str,
false));
189 value_(parse(str, true))
195 value_(parse(str, true))
201 value_(parse(str, !allowBad))
207 value_(parse(str, !allowBad))
225 value_(switchType::INVALID)
251 value_(switchType::INVALID)
292 <<
"using default " << deflt.
c_str() <<
endl;
313 return (value_ < switchType::INVALID);
325 if (value_ < switchType::INVALID)
341 return names[(value_ & 0x0F)];
void negate() noexcept
Flip the type, so OFF becomes ON, etc.
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
bool good() const noexcept
True if the Switch represents a valid enumeration.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
static bool contains(const std::string &str)
True if there is a switch type corresponding to the given string.
std::string str() const
A string representation of the Switch value.
switchType
Switch enumerations corresponding to common text representations.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
const char * c_str() const noexcept
A C-string representation of the Switch value.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
const word & wordToken() const
Return const reference to the word contents.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
Ostream & endl(Ostream &os)
Add newline and flush stream.
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.
static Switch getOrDefault(const word &key, const dictionary &dict, const Switch deflt=switchType::FALSE)
Construct Switch from dictionary, with default value.
bool boolToken() const
Return boolean token 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(const bool b) noexcept
A string representation of bool as "false" / "true".
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
Istream & operator>>(Istream &, directionInfo &)
errorManip< error > abort(error &err)
constexpr Switch() noexcept
Default construct as false.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
switchType type() const noexcept
The underlying enumeration value.
bool isBool() const noexcept
Token is BOOL.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
T getOrAdd(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX)
Find and return a T, or return the given default value and add it to dictionary. FatalIOError if it i...
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
label labelToken() const
Return label value.
bool isLabel() const noexcept
Token is LABEL.
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
bool readIfPresent(const word &key, const dictionary &dict)
Update the value of the Switch if it is found in the dictionary.
static Switch find(const std::string &str)
Find switchType for the given string, returning as a Switch that can be tested for good() or bad()...
void setBad() noexcept
Set stream state to be 'bad'.
static OS & printTokenError(OS &os, const token &tok)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...