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

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< wordsortedToc () 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 wordget (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 wordoperator[] (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 the enumeration by name. More...
 
const_iterator find (const word &key) const
 
EnumType lookupOrDefault (const word &key, const dictionary &dict, const EnumType deflt, const bool warnOnly=false) const
 Same as getOrDefault() More...
 
const wordoperator() (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...
 

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 64 of file error.H.

Member Typedef Documentation

◆ key_type

typedef word key_type

The type of keys used.

Definition at line 76 of file Enum.H.

◆ value_type

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]

Enum ( )
defaultnoexcept

Default construct, an empty list.

◆ Enum() [2/2]

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 28 of file Enum.C.

Member Function Documentation

◆ empty()

bool empty ( ) const
inlinenoexcept

True if the enumeration list is empty.

Definition at line 24 of file EnumI.H.

◆ size()

Foam::label size ( ) const
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().

Here is the caller graph for this function:

◆ names()

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.

Referenced by Enum< EnumType >::const_iterator::key().

Here is the caller graph for this function:

◆ values()

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

The list of enum values, in construction order.

Definition at line 47 of file EnumI.H.

◆ toc()

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.

◆ sortedToc()

Foam::List< Foam::word > sortedToc ( ) const
inline

The sorted list of enum names.

Definition at line 63 of file EnumI.H.

Referenced by filmTurbulenceModel::Cw().

Here is the caller graph for this function:

◆ clear()

void clear ( )
inline

Clear all entries.

Definition at line 74 of file EnumI.H.

◆ push_back()

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

Here is the caller graph for this function:

◆ contains() [1/2]

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< preconditioners >::found().

Here is the caller graph for this function:

◆ contains() [2/2]

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.

◆ get() [1/4]

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

Here is the caller graph for this function:

◆ get() [2/4]

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.

◆ lookup() [1/2]

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 85 of file Enum.C.

Referenced by Enum< preconditioners >::get(), Foam::getStopAction(), Enum< preconditioners >::operator()(), and derivedFields::read().

Here is the caller graph for this function:

◆ get() [3/4]

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 150 of file Enum.C.

◆ getOrDefault()

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 173 of file Enum.C.

Referenced by distributedTriSurfaceMesh::distributedTriSurfaceMesh(), Enum< preconditioners >::lookupOrDefault(), abort::read(), writeObjects::read(), and surfaceFieldValue::read().

Here is the caller graph for this function:

◆ readEntry()

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 218 of file Enum.C.

◆ readIfPresent()

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

Here is the caller graph for this function:

◆ read() [1/2]

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

Here is the caller graph for this function:

◆ read() [2/2]

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 121 of file Enum.C.

◆ write()

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.

◆ writeList()

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.

◆ operator[]() [1/2]

EnumType operator[] ( const word enumName) const
inline

Return the enumeration corresponding to the given name.

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

Definition at line 252 of file EnumI.H.

◆ operator[]() [2/2]

const Foam::word & operator[] ( const EnumType  e) const
inline

Return the first name corresponding to the given enumeration, or an empty word on failure.

Identical to get()

Definition at line 262 of file EnumI.H.

◆ cbegin()

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

Definition at line 220 of file EnumI.H.

Referenced by Enum< preconditioners >::begin().

Here is the caller graph for this function:

◆ cend()

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

Definition at line 228 of file EnumI.H.

Referenced by Enum< preconditioners >::end().

Here is the caller graph for this function:

◆ begin()

const_iterator begin ( ) const
inlinenoexcept

Definition at line 384 of file Enum.H.

◆ end()

const_iterator end ( ) const
inlinenoexcept

Definition at line 385 of file Enum.H.

◆ cfind()

Foam::Enum< EnumType >::const_iterator cfind ( const word key) const
inline

Find the enumeration by name.

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

Definition at line 236 of file EnumI.H.

Referenced by Enum< preconditioners >::find().

Here is the caller graph for this function:

◆ find()

const_iterator find ( const word key) const
inline

Definition at line 393 of file Enum.H.

◆ lookupOrDefault()

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 403 of file Enum.H.

◆ operator()() [1/2]

const word& operator() ( const EnumType  e) const
inline

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

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

Definition at line 419 of file Enum.H.

◆ operator()() [2/2]

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 430 of file Enum.H.

◆ get() [4/4]

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 441 of file Enum.H.

◆ lookup() [2/2]

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 452 of file Enum.H.

◆ append()

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 464 of file Enum.H.

◆ found() [1/2]

bool found ( const word key) const
inline

Same as contains()

Definition at line 474 of file Enum.H.

Referenced by FIREMeshReader::readGeometry().

Here is the caller graph for this function:

◆ found() [2/2]

bool found ( const EnumType  e) const
inline

Same as contains()

Definition at line 479 of file Enum.H.


The documentation for this class was generated from the following files: