CEnumDictionary Class Template Reference

#include <EnumDictionary.h>

List of all members.

Public Member Functions

  CEnumDictionary (SI_Char const **in_ppStringArray)
  Constructor.
const SI_Char *  ToString (Enum in_Value) const
  Convert from enum to string.
SI_Bool  ToEnum (Enum &out_rEnum, const SI_Char *in_pValue) const
  Convert from string to enum.


Detailed Description

template<class Enum, size_t size>
class CEnumDictionary< Enum, size >

Template class that converts strings to enums, or enums to strings.

Parameters:
Enum  Enumerated type
size  Value of the last valid entry of the enumerated type
Example:
        // the enum type
        enum MyEnum
        {
            SomeValue = 1,
            SomeOtherValue = 2,
            TheLastValue = 4
        };

        // the strings matching the enum values
        static const SI_Char* g_szMyEnumStrings[] =
        {
            "SomeValue",
            "SomeOtherValue",
            "TheLastValue"
        };

        // The Enum dictionary to convert from enum to string
        // or string to enum
        CEnumDictionary<MyEnum, TheLastValue> l_dict( g_szMyEnumStrings );


Constructor & Destructor Documentation

CEnumDictionary ( SI_Char const **  in_ppStringArray  )  [inline]

Constructor.

Parameters:
in_ppStringArray  Array containing the strings.
Warning:
in_ppStringArray is not freed upon destruction.
Example:
        // example of typical in_ppStringArray
        static const SI_Char* g_szMyEnumStrings[] =
        {
            "SomeValue",
            "SomeOtherValue",
            "TheLastValue"
        };


Member Function Documentation

const SI_Char* ToString ( Enum  in_Value  )  const [inline]

Convert from enum to string.

Parameters:
in_Value  Enum value to convert
Returns:
String representation of the enum value
Warning:
The returned string should not be modified
Example:
        CEnumDictionary<EnumType, LastEnumValue> l_EnumDict(g_szMyEnumStrings);
        const SI_Char *l_szStringValue = l_EnumDict.ToString(LastEnumValue);

SI_Bool ToEnum ( Enum &  out_rEnum,
const SI_Char *  in_pValue  
) const [inline]

Convert from string to enum.

Parameters:
out_rEnum  Resulting enum value
in_pValue  String value to convert
Return values:
false  There is no matching enum value
true  The matching enum value was found
Example:
        CEnumDictionary<EnumType, LastEnumValue> l_EnumDict(g_szMyEnumStrings);
        EnumType l_EnumValue;
        if (!l_EnumDict.ToEnum(l_EnumValue, "LastEnumValue"))
        {
            // conversion failed
        }


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