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 append (std::initializer_list< std::pair< EnumType, const char * > > list)
 Append value/key pairs to the lists of known enumerations. More...
 
label find (const word &enumName) const
 Find the index of the given name. More...
 
label find (const EnumType e) const
 Find the first index of given enumeration. More...
 
bool found (const word &enumName) const
 True if there is an enumeration corresponding to the given name. More...
 
bool found (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
 
EnumType getOrDefault (const word &key, const dictionary &dict, const EnumType deflt, const bool failsafe=false) const
 
bool readEntry (const word &key, const dictionary &dict, EnumType &val, const bool mandatory=true) const
 Find entry and assign to T val. More...
 
bool readIfPresent (const word &key, const dictionary &dict, EnumType &val) 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
 
EnumType operator[] (const word &enumName) const
 Return the enumeration corresponding to the given name. More...
 
const wordoperator[] (const EnumType e) const
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
EnumType lookupOrDefault (const word &key, const dictionary &dict, const EnumType deflt, const bool failsafe=false) const
 
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...
 

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

Member Typedef Documentation

◆ key_type

typedef word key_type

The type of keys used.

Definition at line 83 of file Enum.H.

◆ value_type

typedef EnumType value_type

The type of enumeration represented by the Enum.

Definition at line 86 of file Enum.H.

Constructor & Destructor Documentation

◆ Enum() [1/2]

Enum ( )
defaultnoexcept

Default construct, an empty list.

References Foam::operator!=(), Foam::operator*(), and Foam::operator==().

Here is the call graph for this function:

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

Member Function Documentation

◆ empty()

bool empty
inlinenoexcept

True if the enumeration list is empty.

Definition at line 31 of file EnumI.H.

◆ size()

Foam::label size
inlinenoexcept

The number of name/value pairs for the enumeration.

Definition at line 38 of file EnumI.H.

Referenced by Enum< EnumType >::cend().

Here is the caller graph for this function:

◆ names()

const Foam::List< Foam::word > & names
inlinenoexcept

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

Definition at line 46 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
inlinenoexcept

The list of enum values, in construction order.

Definition at line 54 of file EnumI.H.

◆ toc()

const Foam::List< Foam::word > & toc
inlinenoexcept

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

Definition at line 62 of file EnumI.H.

◆ sortedToc()

Foam::List< Foam::word > sortedToc
inline

The sorted list of enum names.

Definition at line 70 of file EnumI.H.

References Foam::sort().

Referenced by filmTurbulenceModel::Cw(), and humidityTemperatureCoupledMixedFvPatchScalarField::humidityTemperatureCoupledMixedFvPatchScalarField().

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

◆ clear()

void clear
inline

Clear all entries.

Definition at line 81 of file EnumI.H.

◆ append()

void append ( 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 55 of file Enum.C.

◆ find() [1/2]

Foam::label find ( const word enumName) const
inline

Find the index of the given name.

Returns
position in list or -1 if not found.

Definition at line 89 of file EnumI.H.

◆ find() [2/2]

Foam::label find ( const EnumType  e) const
inline

Find the first index of given enumeration.

Returns
position in list or -1 if not found.

Definition at line 96 of file EnumI.H.

References e.

◆ found() [1/2]

bool found ( const word enumName) const
inline

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

Definition at line 103 of file EnumI.H.

Referenced by inputMode::execute(), IOstreamOption::formatEnum(), and FIREMeshReader::readGeometry().

Here is the caller graph for this function:

◆ found() [2/2]

bool found ( const EnumType  e) const
inline

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

Definition at line 110 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 75 of file Enum.C.

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

Referenced by parcelSelection::calculateFilter(), inputMode::execute(), externalCoupledTemperatureMixedFvPatchScalarField::externalCoupledTemperatureMixedFvPatchScalarField(), Enum< EnumType >::lookup(), Enum< EnumType >::operator()(), Enum< EnumType >::operator[](), Enum< injectionMethod >::operator[](), cellBitSet::select(), and shellSurfaces::shellSurfaces().

Here is the call graph for this function:
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 117 of file EnumI.H.

References e.

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

Referenced by Foam::getStopAction().

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

◆ getOrDefault()

EnumType getOrDefault ( const word key,
const dictionary dict,
const EnumType  deflt,
const bool  failsafe = 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 failsafe downgrades the FatalIOError to an IOWarning.
Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
defltfallback if not found
failsafeWarn only on bad enumeration

Definition at line 178 of file Enum.C.

Referenced by distributedTriSurfaceMesh::distributedTriSurfaceMesh(), abort::read(), sampledPatchInternalField::sampledPatchInternalField(), and surfaceIntersection::surfaceIntersection().

Here is the caller graph for this function:

◆ readEntry()

bool readEntry ( const word key,
const dictionary dict,
EnumType &  val,
const bool  mandatory = true 
) const

Find entry and assign to T val.

FatalIOError if the enumeration is incorrect, or when it is mandatory but was not found.

Returns
true if the entry was found.
Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
valthe value to read into
mandatorythe keyword is mandatory

Definition at line 221 of file Enum.C.

◆ readIfPresent()

bool readIfPresent ( const word key,
const dictionary dict,
EnumType &  val 
) 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

Definition at line 131 of file EnumI.H.

References dict.

Referenced by blockMesh::blockMesh(), colourTable::colourTable(), distributedTriSurfaceMesh::distributedTriSurfaceMesh(), humidityTemperatureCoupledMixedFvPatchScalarField::humidityTemperatureCoupledMixedFvPatchScalarField(), mappedPatchBase::mappedPatchBase(), and Time::readDict().

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

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

Referenced by Foam::operator>>(), and addcommsTypeToOpt::readData().

Here is the call graph for this function:
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 127 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 noop if the enumeration wasn't found.

Definition at line 144 of file EnumI.H.

References e.

◆ 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 157 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 250 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 260 of file EnumI.H.

References e, and Enum< EnumType >::get().

Here is the call graph for this function:

◆ cbegin()

Foam::Enum< EnumType >::const_iterator cbegin
inlinenoexcept

Definition at line 233 of file EnumI.H.

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

Here is the caller graph for this function:

◆ cend()

Foam::Enum< EnumType >::const_iterator cend
inlinenoexcept

Definition at line 241 of file EnumI.H.

References Enum< EnumType >::size().

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

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

◆ begin()

const_iterator begin ( ) const
inlinenoexcept

Definition at line 299 of file Enum.H.

References Enum< EnumType >::cbegin().

Here is the call graph for this function:

◆ end()

const_iterator end ( ) const
inlinenoexcept

Definition at line 300 of file Enum.H.

References Enum< EnumType >::cend().

Here is the call graph for this function:

◆ lookupOrDefault()

EnumType lookupOrDefault ( const word key,
const dictionary dict,
const EnumType  deflt,
const bool  failsafe = false 
) const
inline

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. FatalError (or Warning) if the enumeration was incorrect.
Parameters
keyLookup key. Uses LITERAL (not REGEX)
dictdictionary
defltfallback if not found
failsafeWarn only on bad enumeration

Definition at line 310 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 325 of file Enum.H.

References e, and Enum< EnumType >::get().

Here is the call graph for this function:

◆ 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 333 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 341 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 349 of file Enum.H.

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

Here is the call graph for this function:

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