EnumMap< E > Class Template Reference

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

#include <EnumTraits.h++>

Inheritance diagram for EnumMap< E >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

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

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 (  )  [inline]

Constructor.

~EnumMap (  )  [inline]

Destructor.


Member Function Documentation

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

Add a mapping.

const char* stringForValue ( value  )  const [inline]

Map an enum value to its string.

Parameters:
value The enum value to map.
Returns:
The corresponding string, nor NULL if there is no mapping for the given enum value.
E valueForString ( const char *  str  )  const [inline]

Map a string to its enum value.

Parameters:
str The 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:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3