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

Collaboration diagram for Enum< EnumType >:
[legend]

Public Types

typedef EnumType value_type
 The type of enumeration represented by the Enum. More...
 

Public Member Functions

 Enum ()=default
 Construct null (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
 The list of enum names, in construction order. Same as toc() More...
 
const List< word > & toc () const
 The list of enum names, in construction order. Same as names() More...
 
List< wordsortedToc () const
 The sorted list of enum names. More...
 
const List< int > & values () const
 The list of enum values, in construction order. 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
 Test if there is an enumeration corresponding to the given name. More...
 
bool found (const EnumType e) const
 Test 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...
 
EnumType get (const word &enumName, const EnumType deflt) const
 The enumeration corresponding to the given name. More...
 
const wordget (const EnumType e) const
 The name corresponding to the given enumeration. 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...
 
OstreamwriteList (Ostream &os, const label shortLen=0) const
 Write the names as a list to an Ostream. More...
 
EnumType operator[] (const word &enumName) const
 Return the enumeration corresponding to the given name. More...
 
const wordoperator[] (const EnumType e) const
 
const wordoperator() (const EnumType e) const
 
EnumType operator() (const word &enumName, const EnumType deflt) const
 
EnumType lookupOrDefault (const word &key, const dictionary &dict, const EnumType deflt, const bool failsafe=false) const
 
EnumType FOAM_DEPRECATED_FOR (2018-10, "get() method") lookup(const word &key
 Deprecated(2018-10) same as two-parameter get() More...
 

Public Attributes

EnumType const dictionary &const dict
 

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 51 of file IOstreamOption.H.

Member Typedef Documentation

◆ value_type

typedef EnumType value_type

The type of enumeration represented by the Enum.

Definition at line 75 of file Enum.H.

Constructor & Destructor Documentation

◆ Enum() [1/2]

Enum ( )
default

Construct null (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 35 of file Enum.C.

Member Function Documentation

◆ empty()

bool empty ( ) const
inlinenoexcept

True if the enumeration list is empty.

Definition at line 31 of file EnumI.H.

◆ size()

Foam::label size ( ) const
inlinenoexcept

The number of name/value pairs for the enumeration.

Definition at line 38 of file EnumI.H.

◆ names()

const Foam::wordList & names ( ) const
inline

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

Definition at line 45 of file EnumI.H.

◆ toc()

const Foam::wordList & toc ( ) const
inline

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

Definition at line 52 of file EnumI.H.

◆ sortedToc()

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

The sorted list of enum names.

Definition at line 55 of file Enum.C.

◆ values()

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

The list of enum values, in construction order.

Definition at line 59 of file EnumI.H.

◆ clear()

void clear ( )
inline

Clear all entries.

Definition at line 66 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 67 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 74 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 81 of file EnumI.H.

◆ found() [1/2]

bool found ( const word enumName) const
inline

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

Definition at line 88 of file EnumI.H.

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

Here is the caller graph for this function:

◆ found() [2/2]

bool found ( const EnumType  e) const
inline

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

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

Referenced by derivedFields::read(), limitFields::read(), and lumpedPointMovement::readDict().

Here is the caller graph for this function:

◆ get() [2/4]

EnumType get ( const word enumName,
const EnumType  deflt 
) const

The enumeration corresponding to the given name.

Returns
The enumeration or default if not found.

Definition at line 103 of file Enum.C.

◆ get() [3/4]

const Foam::word & get ( const EnumType  e) const
inline

The name corresponding to the given enumeration.

Return an empty word if not found.

Definition at line 102 of file EnumI.H.

◆ get() [4/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 168 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 190 of file Enum.C.

Referenced by distributedTriSurfaceMesh::distributedTriSurfaceMesh(), and Enum< filterType >::lookupOrDefault().

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

◆ readIfPresent()

bool readIfPresent ( const word key,
const dictionary dict,
EnumType &  val 
) const

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

Referenced by 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 120 of file Enum.C.

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

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 139 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 127 of file EnumI.H.

◆ writeList()

Foam::Ostream & writeList ( Ostream os,
const label  shortLen = 0 
) const
inline

Write the names as a list to an Ostream.

Default is without line-breaks.

Definition at line 117 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 single parameter get()

Definition at line 142 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 single parameter get()

Definition at line 152 of file EnumI.H.

◆ operator()() [1/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 single parameter get()

Definition at line 162 of file EnumI.H.

◆ operator()() [2/2]

EnumType operator() ( const word enumName,
const EnumType  deflt 
) const
inline

Return the enumeration corresponding to the given name, or deflt if the name is not found.

Definition at line 172 of file EnumI.H.

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

Referenced by abort::read(), and writeObjects::read().

Here is the caller graph for this function:

◆ FOAM_DEPRECATED_FOR()

EnumType FOAM_DEPRECATED_FOR ( 2018-  10,
"get() method"   
) const &

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

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

Member Data Documentation

◆ dict

EnumType const dictionary& const dict
Initial value:
{
return get(key, dict)

Definition at line 286 of file Enum.H.

Referenced by Enum< filterType >::lookupOrDefault().


The documentation for this class was generated from the following files:
Foam::Enum::dict
EnumType const dictionary &const dict
Definition: Enum.H:286
Foam::Enum::get
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition: Enum.C:86