Go to the documentation of this file.
33 template<
class EnumType>
36 std::initializer_list<std::pair<EnumType, const char*>> list
43 for (
const auto& pair : list)
45 keys_[i] = pair.second;
46 vals_[i] = int(pair.first);
54 template<
class EnumType>
65 template<
class EnumType>
68 std::initializer_list<std::pair<EnumType, const char*>> list
73 keys_.resize(i + list.size());
74 vals_.resize(i + list.size());
76 for (
const auto& pair : list)
78 keys_[i] = pair.second;
79 vals_[i] = int(pair.first);
85 template<
class EnumType>
88 const label idx =
find(enumName);
93 << enumName <<
" is not in enumeration: " << *
this <<
nl
97 return EnumType(vals_[idx]);
101 template<
class EnumType>
104 const word& enumName,
108 const label idx =
find(enumName);
115 return EnumType(vals_[idx]);
119 template<
class EnumType>
122 const word enumName(is);
124 const label idx =
find(enumName);
129 << enumName <<
" is not in enumeration: " << *
this <<
nl
133 return EnumType(vals_[idx]);
137 template<
class EnumType>
145 const word enumName(is);
147 const label idx =
find(enumName);
151 e = EnumType(vals_[idx]);
158 << enumName <<
" is not in enumeration: " << *
this <<
nl
166 template<
class EnumType>
173 const word enumName(
dict.get<
word>(key, keyType::LITERAL));
175 const label idx =
find(enumName);
180 << enumName <<
" is not in enumeration: " << *
this <<
nl
184 return EnumType(vals_[idx]);
188 template<
class EnumType>
193 const EnumType deflt,
197 const entry* eptr =
dict.findEntry(key, keyType::LITERAL);
203 const label idx =
find(enumName);
207 return EnumType(vals_[idx]);
215 << enumName <<
" is not in enumeration: " << *
this <<
nl
216 <<
"using failsafe " << get(deflt)
217 <<
" (value " << int(deflt) <<
')' <<
endl;
222 << enumName <<
" is not in enumeration: " << *
this <<
nl
231 template<
class EnumType>
240 const entry* eptr =
dict.findEntry(key, keyType::LITERAL);
246 const label idx =
find(enumName);
250 val = EnumType(vals_[idx]);
255 << enumName <<
" is not in enumeration: " << *
this <<
nl
261 <<
"'" << key <<
"' not found in dictionary " <<
dict.name() <<
nl
269 template<
class EnumType>
278 return readEntry(key,
dict, val,
false);
A keyword and a list of tokens is an 'entry'.
A class for handling words, derived from Foam::string.
Enum()=default
Construct null (empty list)
Ostream & endl(Ostream &os)
Add newline and flush stream.
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
EnumType getOrDefault(const word &key, const dictionary &dict, const EnumType deflt, const bool failsafe=false) const
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void append(std::initializer_list< std::pair< EnumType, const char * >> list)
Append value/key pairs to the lists of known enumerations.
const dimensionedScalar e
Elementary charge.
bool readIfPresent(const word &key, const dictionary &dict, EnumType &val) const
Find an entry if present, and assign to T val.
List< word > sortedToc() const
The sorted list of enum names.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
bool readEntry(const word &key, const dictionary &dict, EnumType &val, const bool mandatory=true) const
Find entry and assign to T val.