NamedEnum< EnumType, nEnum > Class Template Reference

A NamedEnum is a wrapper around a list of names that represent particular enumeration values. More...

Public Types

typedef EnumType value_type
 The type of enumeration wrapped by NamedEnum. More...
 

Public Member Functions

 NamedEnum () FOAM_DEPRECATED_FOR(2017-05
 Construct from names. More...
 
label size () const
 The number of lookup names for the enumeration. More...
 
wordList toc () const
 The list of enum names. More...
 
wordList sortedToc () const
 The sorted list of enum names. More...
 
wordList words () const
 The list of enum names, in construction order. More...
 
List< int > values () const
 The list of enum values, in construction order. More...
 
bool found (const word &enumName) const
 Test if there is an enumeration corresponding to the given name. More...
 
bool hasEnum (const word &enumName) const
 Test if there is an enumeration corresponding to the given name. More...
 
bool hasName (const EnumType e) const
 Test if there is a name corresponding to the given enumeration. More...
 
EnumType lookup (const word &key, const dictionary &dict) const
 Lookup the key in the dictionary and return the corresponding. More...
 
EnumType lookupOrDefault (const word &key, const dictionary &dict, const EnumType deflt) const
 Find the key in the dictionary and return the corresponding. More...
 
EnumType read (Istream &is) const
 Read a word from Istream and return the corresponding enumeration. More...
 
void write (const EnumType e, Ostream &os) const
 Write the name representation of the enumeration to an Ostream. More...
 
const EnumType operator[] (const word &name) const
 Return the enumeration element corresponding to the given name. More...
 
const char * operator[] (const EnumType e) const
 Return the name of the given enumeration element. More...
 

Static Public Attributes

static const char * names [nEnum]
 The set of names corresponding to the enumeration EnumType. More...
 

Friends

Ostreamoperator (Ostream &os, const NamedEnum< EnumType, nEnum > &wrapped)
 Write names to Ostream, as per writeKeys() with shortListLen=10. More...
 

Detailed Description

template<class EnumType, int nEnum>
class Foam::NamedEnum< EnumType, nEnum >

A NamedEnum is a wrapper around a list of names that represent particular enumeration values.

Deprecated:
(2017-05) This class is retained for compatibility only and should be used for any new code. The Foam::Enum class is robuster, more flexible, easier to use.
See also
Foam::Enum
Source files

Definition at line 58 of file NamedEnum.H.

Member Typedef Documentation

◆ value_type

typedef EnumType value_type

The type of enumeration wrapped by NamedEnum.

Definition at line 92 of file NamedEnum.H.

Constructor & Destructor Documentation

◆ NamedEnum()

NamedEnum ( )

Construct from names.

Definition at line 36 of file NamedEnum.C.

References Foam::abort(), Foam::endl(), Foam::FatalError, FatalErrorInFunction, HashTable< T, Key, Hash >::insert(), NamedEnum< EnumType, nEnum >::names, and Foam::nl.

Here is the call graph for this function:

Member Function Documentation

◆ size()

Foam::label size ( ) const
inline

The number of lookup names for the enumeration.

Definition at line 31 of file NamedEnumI.H.

◆ toc()

Foam::wordList toc ( ) const
inline

The list of enum names.

Definition at line 38 of file NamedEnumI.H.

◆ sortedToc()

Foam::wordList sortedToc ( ) const
inline

The sorted list of enum names.

Definition at line 45 of file NamedEnumI.H.

◆ words()

Foam::wordList words ( ) const

The list of enum names, in construction order.

Definition at line 70 of file NamedEnum.C.

References Foam::BitOps::count(), and List< T >::setSize().

Here is the call graph for this function:

◆ values()

Foam::List< int > values ( ) const

The list of enum values, in construction order.

Definition at line 89 of file NamedEnum.C.

References Foam::BitOps::count(), and List< T >::setSize().

Here is the call graph for this function:

◆ found()

bool found ( const word enumName) const
inline

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

Definition at line 53 of file NamedEnumI.H.

◆ hasEnum()

bool hasEnum ( const word enumName) const
inline

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

Definition at line 63 of file NamedEnumI.H.

◆ hasName()

bool hasName ( const EnumType  e) const

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

Definition at line 113 of file NamedEnum.C.

References Foam::constant::electromagnetic::e, and forAllConstIters().

Here is the call graph for this function:

◆ lookup()

EnumType lookup ( const word key,
const dictionary dict 
) const

Lookup the key in the dictionary and return the corresponding.

enumeration element based on its name. Fatal if anything is incorrect.

Definition at line 130 of file NamedEnum.C.

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

Here is the call graph for this function:

◆ lookupOrDefault()

EnumType lookupOrDefault ( const word key,
const dictionary dict,
const EnumType  deflt 
) const

Find the key in the dictionary and return the corresponding.

enumeration element based on its name. Return the default value if the key was not found in the dictionary. Fatal if enumerated name was incorrect.

Definition at line 152 of file NamedEnum.C.

References dict, dictionary::found(), and Foam::cellModeller::lookup().

Here is the call graph for this function:

◆ read()

EnumType read ( Istream is) const

Read a word from Istream and return the corresponding enumeration.

Definition at line 168 of file NamedEnum.C.

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

Here is the call graph for this function:

◆ write()

void write ( const EnumType  e,
Ostream os 
) const

Write the name representation of the enumeration to an Ostream.

A noop if the enumeration wasn't found.

Definition at line 187 of file NamedEnum.C.

References Foam::constant::electromagnetic::e.

◆ operator[]() [1/2]

const EnumType operator[] ( const word name) const
inline

Return the enumeration element corresponding to the given name.

Definition at line 75 of file NamedEnumI.H.

References Foam::name().

Here is the call graph for this function:

◆ operator[]() [2/2]

const char * operator[] ( const EnumType  e) const
inline

Return the name of the given enumeration element.

Definition at line 85 of file NamedEnumI.H.

References Foam::constant::electromagnetic::e.

Friends And Related Function Documentation

◆ operator

Ostream& operator ( Ostream os,
const NamedEnum< EnumType, nEnum > &  wrapped 
)
friend

Write names to Ostream, as per writeKeys() with shortListLen=10.

Member Data Documentation

◆ names

const char* names[nEnum]
static

The set of names corresponding to the enumeration EnumType.

Definition at line 98 of file NamedEnum.H.

Referenced by NamedEnum< EnumType, nEnum >::NamedEnum().


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