Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values. All dictionary searches use a literal (not regex). More...
Classes | |
class | const_iterator |
A const_iterator for iterating an Enum list. More... | |
Public Types | |
typedef word | key_type |
The type of keys used. More... | |
typedef EnumType | value_type |
The type of enumeration represented by the Enum. More... | |
Public Member Functions | |
Enum () noexcept=default | |
Default construct, an empty list. More... | |
Enum (std::initializer_list< std::pair< EnumType, const char *>> list) | |
Construct from a values/names list. More... | |
bool | empty () const noexcept |
True if the enumeration list is empty. More... | |
label | size () const noexcept |
The number of name/value pairs for the enumeration. More... | |
const List< word > & | names () const noexcept |
The list of enum names, in construction order. Same as toc() More... | |
const List< int > & | values () const noexcept |
The list of enum values, in construction order. More... | |
const List< word > & | toc () const noexcept |
The list of enum names, in construction order. Same as names() More... | |
List< word > | sortedToc () const |
The sorted list of enum names. More... | |
void | clear () |
Clear all entries. More... | |
void | push_back (std::initializer_list< std::pair< EnumType, const char *>> list) |
Append value/key pairs to the lists of known enumerations. More... | |
bool | contains (const word &enumName) const |
True if there is an enumeration corresponding to the given name. More... | |
bool | contains (const EnumType e) const |
True if there is a name corresponding to the given enumeration. More... | |
EnumType | get (const word &enumName) const |
The enumeration corresponding to the given name. More... | |
const word & | get (const EnumType e) const |
The name corresponding to the given enumeration. More... | |
EnumType | lookup (const word &enumName, const EnumType deflt) const |
The enumeration corresponding to the given name. More... | |
EnumType | get (const word &key, const dictionary &dict) const |
Get the key in the dictionary and return the corresponding enumeration element based on its name. More... | |
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. More... | |
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. More... | |
bool | readIfPresent (const word &key, const dictionary &dict, EnumType &val, const bool warnOnly=false) const |
Find an entry if present, and assign to T val. More... | |
EnumType | read (Istream &is) const |
Read a word from Istream and return the corresponding enumeration. More... | |
bool | read (Istream &is, EnumType &val, const bool mandatory=true) const |
Read a word from Istream, lookup named enumeration. More... | |
void | write (const EnumType e, Ostream &os) const |
Write the name representation of the enumeration to an Ostream. More... | |
template<class OS > | |
OS & | writeList (OS &os, const label ununsed=0) const |
Write enumeration names as a list without line-breaks to an output stream. More... | |
EnumType | operator[] (const word &enumName) const |
Return the enumeration corresponding to the given name. More... | |
const word & | operator[] (const EnumType e) const |
Return the first name corresponding to the given enumeration, or an empty word on failure. More... | |
const_iterator | cbegin () const noexcept |
const_iterator | cend () const noexcept |
const_iterator | begin () const noexcept |
const_iterator | end () const noexcept |
const_iterator | cfind (const word &key) const |
Find key/value pair by enumeration name. More... | |
const_iterator | find (const word &key) const |
const_iterator | cfind (const EnumType e) const |
Find key/value pair by enumeration value. More... | |
const_iterator | find (const EnumType e) const |
EnumType | lookupOrDefault (const word &key, const dictionary &dict, const EnumType deflt, const bool warnOnly=false) const |
Same as getOrDefault() More... | |
const word & | operator() (const EnumType e) const |
Deprecated(2020-11) use get() method. More... | |
EnumType | operator() (const word &key, const EnumType deflt) const |
Deprecated(2020-11) use two-parameter lookup() method. More... | |
EnumType | get (const word &key, const EnumType deflt) const |
Deprecated(2020-11) use two-parameter lookup() method. More... | |
EnumType | lookup (const word &key, const dictionary &dict) const |
Deprecated(2018-10) same as two-parameter get() method. More... | |
void | append (std::initializer_list< std::pair< EnumType, const char *>> list) |
Append value/key pairs to the lists of known enumerations. More... | |
bool | found (const word &key) const |
Same as contains() More... | |
bool | found (const EnumType e) const |
Same as contains() More... | |
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values. All dictionary searches use a literal (not regex).
typedef EnumType value_type |
|
defaultnoexcept |
Default construct, an empty list.
|
explicit |
|
inlinenoexcept |
|
inlinenoexcept |
The number of name/value pairs for the enumeration.
Definition at line 31 of file EnumI.H.
Referenced by Enum< preconditioners >::cend(), Enum< preconditioners >::cfind(), and Enum< EnumType >::const_iterator::good().
|
inlinenoexcept |
The list of enum names, in construction order. Same as toc()
Definition at line 39 of file EnumI.H.
Referenced by Enum< EnumType >::const_iterator::key().
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
The sorted list of enum names.
Definition at line 63 of file EnumI.H.
Referenced by filmTurbulenceModel::Cw().
void push_back | ( | std::initializer_list< std::pair< EnumType, const char *>> | list | ) |
Append value/key pairs to the lists of known enumerations.
Does not check for duplicate entries
Definition at line 49 of file Enum.C.
Referenced by Enum< preconditioners >::append().
|
inline |
True if there is an enumeration corresponding to the given name.
Definition at line 82 of file EnumI.H.
Referenced by Enum< preconditioners >::found().
|
inline |
EnumType get | ( | const word & | enumName | ) | const |
The enumeration corresponding to the given name.
FatalError if not found.
Definition at line 68 of file Enum.C.
Referenced by filmTurbulenceModel::filmTurbulenceModel(), limitFields::read(), externalHeatFluxSource::read(), lumpedPointMovement::readDict(), and cellBitSet::select().
|
inline |
The enumeration corresponding to the given name.
Definition at line 85 of file Enum.C.
Referenced by Enum< preconditioners >::get(), Foam::getStopAction(), Enum< preconditioners >::operator()(), and derivedFields::read().
EnumType get | ( | const word & | key, |
const dictionary & | dict | ||
) | const |
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.
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
deflt | fallback if not found |
warnOnly | Warn (not fail) on bad enumeration |
Definition at line 173 of file Enum.C.
Referenced by distributedTriSurfaceMesh::distributedTriSurfaceMesh(), Enum< preconditioners >::lookupOrDefault(), abort::read(), writeObjects::read(), and surfaceFieldValue::read().
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.
FatalIOError if the enumeration is incorrect, or when it is mandatory but was not found.
(TDB: handle IOobjectOption::readOption instead)
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
val | The value to read into |
mandatory | The keyword is mandatory |
warnOnly | Warn (not fail) on bad enumeration |
|
inline |
Find an entry if present, and assign to T val.
FatalIOError if the enumeration is incorrect. Default search: non-recursive with patterns.
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
val | The value to read into |
warnOnly | Warn (not fail) on bad enumeration |
Definition at line 111 of file EnumI.H.
Referenced by abaqusWriter::abaqusWriter(), surfaceNoise::read(), LduMatrix< Type, DType, LUType >::solver::readControls(), lduMatrix::solver::readControls(), Time::readDict(), and surfaceWriter::surfaceWriter().
EnumType read | ( | Istream & | is | ) | const |
Read a word from Istream and return the corresponding enumeration.
Definition at line 102 of file Enum.C.
Referenced by Foam::operator>>().
bool read | ( | Istream & | is, |
EnumType & | val, | ||
const bool | mandatory = true |
||
) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
Definition at line 220 of file EnumI.H.
Referenced by Enum< preconditioners >::begin().
|
inlinenoexcept |
Definition at line 228 of file EnumI.H.
Referenced by Enum< preconditioners >::end().
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Find key/value pair by enumeration name.
Equal to cend() if not found, or test if good()
Definition at line 236 of file EnumI.H.
Referenced by Enum< preconditioners >::find().
|
inline |
|
inline |
|
inline |
|
inline |
Same as getOrDefault()
key | Lookup key. Uses LITERAL (not REGEX) |
dict | dictionary |
deflt | fallback if not found |
warnOnly | Warn (not fail) on bad enumeration |
|
inline |
Deprecated(2020-11) use get() method.
|
inline |
Deprecated(2020-11) use two-parameter lookup() method.
|
inline |
Deprecated(2020-11) use two-parameter lookup() method.
|
inline |
Deprecated(2018-10) same as two-parameter get() method.
|
inline |
|
inline |
Same as contains()
Definition at line 482 of file Enum.H.
Referenced by FIREMeshReader::readGeometry().
|
inline |
Same as contains()