Loading...
Searching...
No Matches
Enum< EnumType > Class Template Reference

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...

#include <Enum.H>

Classes

class  const_iterator
 A const_iterator for iterating an Enum list. More...

Public Types

typedef word key_type
 The type of keys used.
typedef EnumType value_type
 The type of enumeration represented by the Enum.

Public Member Functions

 Enum () noexcept=default
 Default construct, an empty list.
 Enum (std::initializer_list< std::pair< EnumType, const char * > > list)
 Construct from a values/names list.
bool empty () const noexcept
 True if the enumeration list is empty.
label size () const noexcept
 The number of name/value pairs for the enumeration.
const List< word > & names () const noexcept
 The list of enum names, in construction order. Same as toc().
const List< int > & values () const noexcept
 The list of enum values, in construction order.
const List< word > & toc () const noexcept
 The list of enum names, in construction order. Same as names().
List< wordsortedToc () const
 The sorted list of enum names.
void clear ()
 Clear all entries.
void push_back (std::initializer_list< std::pair< EnumType, const char * > > list)
 Append value/key pairs to the lists of known enumerations.
bool contains (const word &enumName) const
 True if there is an enumeration corresponding to the given name.
bool contains (const EnumType e) const
 True if there is a name corresponding to the given enumeration.
EnumType get (const word &enumName) const
 The enumeration corresponding to the given name.
const wordget (const EnumType e) const
 The name corresponding to the given enumeration.
EnumType lookup (const word &enumName, const EnumType deflt) const
 The enumeration corresponding to the given name.
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.
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.
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.
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.
EnumType read (Istream &is) const
 Read a word from Istream and return the corresponding enumeration.
bool read (Istream &is, EnumType &val, const bool mandatory=true) const
 Read a word from Istream, lookup named enumeration.
void write (const EnumType e, Ostream &os) const
 Write the name representation of the enumeration to an Ostream.
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.
EnumType operator[] (const word &k) const
 Return the enumeration corresponding to the given name.
const wordoperator[] (EnumType e) const
 Return the first name corresponding to the given enumeration, or an empty word if not found.
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.
const_iterator find (const word &key) const
const_iterator cfind (const EnumType e) const
 Find key/value pair by enumeration value.
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().
const wordoperator() (const EnumType e) const
 Deprecated(2020-11) use get() method.
EnumType operator() (const word &key, const EnumType deflt) const
 Deprecated(2020-11) use two-parameter lookup() method.
EnumType get (const word &key, const EnumType deflt) const
 Deprecated(2020-11) use two-parameter lookup() method.
EnumType lookup (const word &key, const dictionary &dict) const
 Deprecated(2018-10) same as two-parameter get() method.
void append (std::initializer_list< std::pair< EnumType, const char * > > list)
 Append value/key pairs to the lists of known enumerations.
bool found (const word &key) const
 Same as contains().
bool found (const EnumType e) const
 Same as contains().

Detailed Description

template<class EnumType>
class Foam::Enum< EnumType >

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).

Source files

Definition at line 56 of file Enum.H.

Member Typedef Documentation

◆ key_type

template<class EnumType>
typedef word key_type

The type of keys used.

Definition at line 85 of file Enum.H.

◆ value_type

template<class EnumType>
typedef EnumType value_type

The type of enumeration represented by the Enum.

Definition at line 90 of file Enum.H.

Constructor & Destructor Documentation

◆ Enum() [1/2]

template<class EnumType>
Enum ( )
defaultnoexcept

Default construct, an empty list.

References clear(), contains(), dict, e, empty(), Enum(), get(), getOrDefault(), lookup(), names(), Foam::noexcept, os(), push_back(), read(), readEntry(), readIfPresent(), size(), sortedToc(), toc(), values(), write(), and writeList().

Referenced by Enum< EnumType >::const_iterator::const_iterator(), and Enum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Enum() [2/2]

template<class EnumType>
Enum ( std::initializer_list< std::pair< EnumType, const char * > > list)
explicit

Construct from a values/names list.

Duplicate values are permitted (eg, for aliases). Duplicate names are permitted, but won't make much sense.

Definition at line 27 of file Enum.C.

References size().

Here is the call graph for this function:

Member Function Documentation

◆ empty()

template<class EnumType>
bool empty ( ) const
inlinenoexcept

True if the enumeration list is empty.

Definition at line 24 of file EnumI.H.

References Foam::noexcept.

Referenced by Enum().

Here is the caller graph for this function:

◆ size()

template<class EnumType>
Foam::label size ( ) const
inlinenoexcept

The number of name/value pairs for the enumeration.

Definition at line 31 of file EnumI.H.

References Foam::noexcept.

Referenced by cend(), cfind(), Enum(), Enum(), Enum< EnumType >::const_iterator::good(), and push_back().

Here is the caller graph for this function:

◆ names()

template<class EnumType>
const Foam::List< Foam::word > & names ( ) const
inlinenoexcept

The list of enum names, in construction order. Same as toc().

Definition at line 39 of file EnumI.H.

References Foam::noexcept.

Referenced by Enum< injectionMethod >::contains(), and Enum().

Here is the caller graph for this function:

◆ values()

template<class EnumType>
const Foam::List< int > & values ( ) const
inlinenoexcept

The list of enum values, in construction order.

Definition at line 47 of file EnumI.H.

References Foam::noexcept.

Referenced by Enum().

Here is the caller graph for this function:

◆ toc()

template<class EnumType>
const Foam::List< Foam::word > & toc ( ) const
inlinenoexcept

The list of enum names, in construction order. Same as names().

Definition at line 55 of file EnumI.H.

References Foam::noexcept.

Referenced by Enum().

Here is the caller graph for this function:

◆ sortedToc()

template<class EnumType>
Foam::List< Foam::word > sortedToc ( ) const
inline

The sorted list of enum names.

Definition at line 63 of file EnumI.H.

References Foam::sort().

Referenced by Enum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

template<class EnumType>
void clear ( )
inline

Clear all entries.

Definition at line 74 of file EnumI.H.

References List< T >::clear().

Referenced by Enum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back()

template<class EnumType>
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 48 of file Enum.C.

References size().

Referenced by append(), and Enum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains() [1/2]

template<class EnumType>
bool contains ( const word & enumName) const
inline

True if there is an enumeration corresponding to the given name.

Definition at line 82 of file EnumI.H.

Referenced by Enum(), found(), and found().

Here is the caller graph for this function:

◆ contains() [2/2]

template<class EnumType>
bool contains ( const EnumType e) const
inline

True if there is a name corresponding to the given enumeration.

Definition at line 89 of file EnumI.H.

References e.

◆ get() [1/4]

template<class EnumType>
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.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, and Foam::nl.

Referenced by Enum(), get(), lookup(), operator()(), operator[](), and operator[]().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get() [2/4]

template<class EnumType>
const Foam::word & get ( const EnumType e) const
inline

The name corresponding to the given enumeration.

Return an empty word if there is no corresponding name for it.

Definition at line 96 of file EnumI.H.

References e, and word::null.

◆ lookup() [1/2]

template<class EnumType>
EnumType lookup ( const word & enumName,
const EnumType deflt ) const

The enumeration corresponding to the given name.

Returns
The enumeration or default if not found.
Note
Method name compatibility with HashTable

Definition at line 84 of file Enum.C.

Referenced by Enum(), get(), lookup(), and operator()().

Here is the caller graph for this function:

◆ get() [3/4]

template<class EnumType>
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.

FatalIOError if anything is incorrect.

Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary

Definition at line 149 of file Enum.C.

References dict, and keyType::LITERAL.

◆ getOrDefault()

template<class EnumType>
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.

Returns
The value found or default if not found in dictionary. FatalIOError if the enumeration is incorrect. Specifying warnOnly downgrades the FatalIOError to an IOWarning.
Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
defltfallback if not found
warnOnlyWarn (not fail) on bad enumeration

Definition at line 172 of file Enum.C.

References dict, and keyType::LITERAL.

Referenced by Enum(), and lookupOrDefault().

Here is the caller graph for this function:

◆ readEntry()

template<class EnumType>
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)

Returns
true if the entry was found.
Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
valThe value to read into
mandatoryThe keyword is mandatory
warnOnlyWarn (not fail) on bad enumeration

Definition at line 217 of file Enum.C.

References dict.

Referenced by Enum().

Here is the caller graph for this function:

◆ readIfPresent()

template<class EnumType>
bool readIfPresent ( const word & key,
const dictionary & dict,
EnumType & val,
const bool warnOnly = false ) const
inline

Find an entry if present, and assign to T val.

FatalIOError if the enumeration is incorrect. Default search: non-recursive with patterns.

Returns
true if the entry was found.
Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
valThe value to read into
warnOnlyWarn (not fail) on bad enumeration

Definition at line 110 of file EnumI.H.

References dict.

Referenced by Enum().

Here is the caller graph for this function:

◆ read() [1/2]

template<class EnumType>
EnumType read ( Istream & is) const

Read a word from Istream and return the corresponding enumeration.

Definition at line 102 of file Enum.C.

References Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, and Foam::nl.

Referenced by Enum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [2/2]

template<class EnumType>
bool read ( Istream & is,
EnumType & val,
const bool mandatory = true ) const

Read a word from Istream, lookup named enumeration.

Returns
true on success. Fatal if mandatory and not found.

Definition at line 120 of file Enum.C.

References Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, and Foam::nl.

Here is the call graph for this function:

◆ write()

template<class EnumType>
void write ( const EnumType e,
Ostream & os ) const
inline

Write the name representation of the enumeration to an Ostream.

A no-op if the enumeration does not have a corresponding name.

Definition at line 124 of file EnumI.H.

Referenced by Enum().

Here is the caller graph for this function:

◆ writeList()

template<class EnumType>
template<class OS>
OS & writeList ( OS & os,
const label ununsed = 0 ) const
inline

Write enumeration names as a list without line-breaks to an output stream.

Definition at line 137 of file EnumI.H.

References os().

Referenced by Enum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator[]() [1/2]

template<class EnumType>
EnumType operator[] ( const word & k) const
inline

Return the enumeration corresponding to the given name.

FatalError if the name is not found. Identical to get()

Definition at line 308 of file Enum.H.

References get(), and k.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<class EnumType>
const word & operator[] ( EnumType e) const
inline

Return the first name corresponding to the given enumeration, or an empty word if not found.

Identical to get()

Definition at line 316 of file Enum.H.

References e, and get().

Here is the call graph for this function:

◆ cbegin()

template<class EnumType>
Foam::Enum< EnumType >::const_iterator cbegin ( ) const
inlinenoexcept

Definition at line 220 of file EnumI.H.

References Foam::noexcept.

Referenced by begin().

Here is the caller graph for this function:

◆ cend()

template<class EnumType>
Foam::Enum< EnumType >::const_iterator cend ( ) const
inlinenoexcept

Definition at line 228 of file EnumI.H.

References Foam::noexcept, and size().

Referenced by end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

template<class EnumType>
const_iterator begin ( ) const
inlinenoexcept

Definition at line 382 of file Enum.H.

References begin(), cbegin(), and Foam::noexcept.

Referenced by begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

template<class EnumType>
const_iterator end ( ) const
inlinenoexcept

Definition at line 383 of file Enum.H.

References cend(), and Foam::noexcept.

Here is the call graph for this function:

◆ cfind() [1/2]

template<class EnumType>
Foam::Enum< EnumType >::const_iterator cfind ( const word & key) const
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.

References size().

Referenced by find(), and find().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [1/2]

template<class EnumType>
const_iterator find ( const word & key) const
inline

Definition at line 391 of file Enum.H.

References cfind(), and Enum< EnumType >::const_iterator::key().

Here is the call graph for this function:

◆ cfind() [2/2]

template<class EnumType>
Foam::Enum< EnumType >::const_iterator cfind ( const EnumType e) const
inline

Find key/value pair by enumeration value.

Equal to cend() if not found, or test if good()

Definition at line 250 of file EnumI.H.

References e.

◆ find() [2/2]

template<class EnumType>
const_iterator find ( const EnumType e) const
inline

Definition at line 399 of file Enum.H.

References cfind(), and e.

Here is the call graph for this function:

◆ lookupOrDefault()

template<class EnumType>
EnumType lookupOrDefault ( const word & key,
const dictionary & dict,
const EnumType deflt,
const bool warnOnly = false ) const
inline

Same as getOrDefault().

Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
defltfallback if not found
warnOnlyWarn (not fail) on bad enumeration

Definition at line 408 of file Enum.H.

References dict, getOrDefault(), Enum< EnumType >::const_iterator::key(), and lookupOrDefault().

Referenced by lookupOrDefault().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/2]

template<class EnumType>
const word & operator() ( const EnumType e) const
inline

Deprecated(2020-11) use get() method.

Deprecated
(2020-11) - use get() method

Definition at line 425 of file Enum.H.

References e, and get().

Here is the call graph for this function:

◆ operator()() [2/2]

template<class EnumType>
EnumType operator() ( const word & key,
const EnumType deflt ) const
inline

Deprecated(2020-11) use two-parameter lookup() method.

Deprecated
(2020-11) - use two-parameter lookup() method

Definition at line 436 of file Enum.H.

References Enum< EnumType >::const_iterator::key(), and lookup().

Here is the call graph for this function:

◆ get() [4/4]

template<class EnumType>
EnumType get ( const word & key,
const EnumType deflt ) const
inline

Deprecated(2020-11) use two-parameter lookup() method.

Deprecated
(2020-11) - use two-parameter lookup() method

Definition at line 447 of file Enum.H.

References get(), Enum< EnumType >::const_iterator::key(), and lookup().

Here is the call graph for this function:

◆ lookup() [2/2]

template<class EnumType>
EnumType lookup ( const word & key,
const dictionary & dict ) const
inline

Deprecated(2018-10) same as two-parameter get() method.

Deprecated
(2018-10) - use two-parameter get() method

Definition at line 458 of file Enum.H.

References dict, get(), Enum< EnumType >::const_iterator::key(), and lookup().

Here is the call graph for this function:

◆ append()

template<class EnumType>
void append ( std::initializer_list< std::pair< EnumType, const char * > > list)
inline

Append value/key pairs to the lists of known enumerations.

Does not check for duplicate entries

Definition at line 469 of file Enum.H.

References append(), and push_back().

Referenced by append().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ found() [1/2]

template<class EnumType>
bool found ( const word & key) const
inline

Same as contains().

Definition at line 480 of file Enum.H.

References contains(), and Enum< EnumType >::const_iterator::key().

Here is the call graph for this function:

◆ found() [2/2]

template<class EnumType>
bool found ( const EnumType e) const
inline

Same as contains().

Definition at line 485 of file Enum.H.

References contains(), and e.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
  • src/OpenFOAM/db/error/error.H
  • src/OpenFOAM/primitives/enums/Enum.H
  • src/OpenFOAM/primitives/enums/Enum.C
  • src/OpenFOAM/primitives/enums/EnumI.H