33template<
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);
54template<
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);
74template<
class EnumType>
77 const label idx = keys_.find(enumName);
82 << enumName <<
" is not in enumeration: " << *
this <<
nl
86 return EnumType(vals_[idx]);
90template<
class EnumType>
97 const label idx = keys_.find(enumName);
104 return EnumType(vals_[idx]);
108template<
class EnumType>
111 const word enumName(is);
113 const label idx = keys_.find(enumName);
118 << enumName <<
" is not in enumeration: " << *
this <<
nl
122 return EnumType(vals_[idx]);
126template<
class EnumType>
134 const word enumName(is);
136 const label idx = keys_.find(enumName);
140 val = EnumType(vals_[idx]);
147 << enumName <<
" is not in enumeration: " << *
this <<
nl
155template<
class EnumType>
164 const label idx = keys_.find(enumName);
169 <<
"Lookup:" << key <<
" enumeration " << enumName
170 <<
" is not in enumeration: " << *
this <<
nl
174 return EnumType(vals_[idx]);
178template<
class EnumType>
183 const EnumType deflt,
193 const label idx = keys_.find(enumName);
197 return EnumType(vals_[idx]);
205 <<
"Lookup:" << key <<
" enumeration " << enumName
206 <<
" is not in enumeration: " << *
this <<
nl
207 <<
"using default " << get(deflt)
208 <<
" (value " << int(deflt) <<
')' <<
endl;
213 <<
"Lookup:" << key <<
" enumeration " << enumName
214 <<
" is not in enumeration: " << *
this <<
nl
223template<
class EnumType>
229 const bool mandatory,
239 const label idx = keys_.find(enumName);
243 val = EnumType(vals_[idx]);
252 <<
"Lookup:" << key <<
" enumeration " << enumName
253 <<
" is not in enumeration: " << *
this <<
nl
254 <<
"leaving value unchanged"
255 <<
" (value " << int(val) <<
')' <<
endl;
260 <<
"Lookup:" << key <<
" enumeration " << enumName
261 <<
" is not in enumeration: " << *
this <<
nl
269 <<
" not found in dictionary " <<
dict.
name() <<
nl
bool readEntry(const word &key, const dictionary &dict, EnumType &val, const bool mandatory=true, const bool warnOnly=false) const
Find entry and assign to T val.
void push_back(std::initializer_list< std::pair< EnumType, const char * > > list)
Append value/key pairs to the lists of known enumerations.
Enum() noexcept=default
Default construct, an empty list.
label size() const noexcept
The number of name/value pairs for the enumeration.
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
EnumType getOrDefault(const word &key, const dictionary &dict, const EnumType deflt, const bool warnOnly=false) const
Find the key in the dictionary and return the corresponding enumeration element based on its name.
EnumType lookup(const word &enumName, const EnumType deflt) const
The enumeration corresponding to the given name.
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)....
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const fileName & name() const noexcept
The dictionary name.
A keyword and a list of tokens is an 'entry'.
T get() const
Get a T from the stream, FatalIOError if the number of tokens is incorrect.
A class for handling words, derived from Foam::string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).