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>
57 std::initializer_list<std::pair<EnumType, const char*>> list
62 keys_.resize(i + list.size());
63 vals_.resize(i + list.size());
65 for (
const auto& pair : list)
67 keys_[i] = pair.second;
68 vals_[i] = int(pair.first);
74 template<
class EnumType>
77 const label idx =
find(enumName);
82 << enumName <<
" is not in enumeration: " << *
this <<
nl
86 return EnumType(vals_[idx]);
90 template<
class EnumType>
97 const label idx =
find(enumName);
104 return EnumType(vals_[idx]);
108 template<
class EnumType>
111 const word enumName(is);
113 const label idx =
find(enumName);
118 << enumName <<
" is not in enumeration: " << *
this <<
nl
122 return EnumType(vals_[idx]);
126 template<
class EnumType>
134 const word enumName(is);
136 const label idx =
find(enumName);
140 val = EnumType(vals_[idx]);
147 << enumName <<
" is not in enumeration: " << *
this <<
nl
155 template<
class EnumType>
164 const label idx =
find(enumName);
169 << enumName <<
" is not in enumeration: " << *
this <<
nl
173 return EnumType(vals_[idx]);
177 template<
class EnumType>
182 const EnumType deflt,
186 const entry* eptr =
dict.findEntry(
key, keyType::LITERAL);
192 const label idx =
find(enumName);
196 return EnumType(vals_[idx]);
204 << enumName <<
" is not in enumeration: " << *
this <<
nl
205 <<
"using failsafe " <<
get(deflt)
206 <<
" (value " << int(deflt) <<
')' <<
endl;
211 << enumName <<
" is not in enumeration: " << *
this <<
nl
220 template<
class EnumType>
229 const entry* eptr =
dict.findEntry(
key, keyType::LITERAL);
235 const label idx =
find(enumName);
239 val = EnumType(vals_[idx]);
244 << enumName <<
" is not in enumeration: " << *
this <<
nl
250 <<
"'" <<
key <<
"' not found in dictionary " <<
dict.name() <<
nl
A keyword and a list of tokens is an 'entry'.
A class for handling words, derived from Foam::string.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
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
Enum() noexcept=default
Default construct, an empty list.
EnumType lookup(const word &enumName, const EnumType deflt) const
The enumeration corresponding to the given name.
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.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
#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.