libcommonc++  0.7
EnumMap< E > Class Template Reference

A bidirectional mapping between enum values and static string constants. More...

#include <EnumTraits.h++>

Inheritance diagram for EnumMap< E >:
Collaboration diagram for EnumMap< E >:

Public Member Functions

 EnumMap ()
 Constructor. More...
 
 ~EnumMap ()
 Destructor. More...
 
EnumMapadd (E value, const char *str)
 Add a mapping. More...
 
valueForString (const char *str) const
 Map a string to its enum value. More...
 
const char * stringForValue (E value) const
 Map an enum value to its string. More...
 

Private Attributes

elements
 STL member. More...
 

Detailed Description

template<typename E>
class ccxx::EnumMap< E >

A bidirectional mapping between enum values and static string constants.

An EnumMap can be constructed as follows:

enum FileType { TypeFile, TypeDirectory, TypeSymLink };
EnumMap<FileType> fileTypeMap;
fileTypeMap.add(TypeFile,      "file")
           .add(TypeDirectory, "directory")
           .add(TypeSymLink,   "symlink");
Author
Mark Lindner

Constructor & Destructor Documentation

◆ EnumMap()

EnumMap ( )
inline

Constructor.

◆ ~EnumMap()

~EnumMap ( )
inline

Destructor.

Member Function Documentation

◆ add()

EnumMap& add ( value,
const char *  str 
)
inline

Add a mapping.

◆ stringForValue()

const char* stringForValue ( value) const
inline

Map an enum value to its string.

Parameters
valueThe enum value to map.
Returns
The corresponding string, nor NULL if there is no mapping for the given enum value.

◆ valueForString()

E valueForString ( const char *  str) const
inline

Map a string to its enum value.

Parameters
strThe string to map.
Returns
The corresponding enumeration value, or EnumTraits<E>::defval() if there is no mapping for the given string.

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