18 #ifndef ION_BASE_ENUMHELPER_H_
19 #define ION_BASE_ENUMHELPER_H_
21 #include "base/integral_types.h"
59 template <
typename EnumType>
static const char*
GetString(EnumType e) {
60 const EnumData<EnumType> data = GetEnumData<EnumType>();
61 return e >= 0 &&
static_cast<size_t>(e) < data.index_map.GetCount() ?
62 data.strings[e] :
"<INVALID>";
69 template <
typename EnumType>
71 return GetEnumData<EnumType>().index_map;
75 template <
typename EnumType>
static size_t GetCount() {
76 return GetIndexMap<EnumType>().
GetCount();
80 template <
typename EnumType>
static uint32
GetConstant(EnumType e) {
81 return GetIndexMap<EnumType>().GetUnorderedIndex(e);
85 template <
typename EnumType>
static EnumType
GetEnum(uint32 c) {
86 return GetIndexMap<EnumType>().GetOrderedIndex(c);
92 template <
typename EnumType>
98 const char* strings_in[])
99 : index_map(index_map_in), strings(strings_in) {}
100 const IndexMap<EnumType, uint32> index_map;
101 const char** strings;
106 template <
typename EnumType>
static const EnumData<EnumType> GetEnumData();
112 #endif // ION_BASE_ENUMHELPER_H_
static uint32 GetConstant(EnumType e)
Returns the constant value corresponding to an enum.
}; static const char* kStrings[] = { "Value1", "Value2", "Value3" }; return EnumData<Values>(IndexMap...
static const char * GetString(EnumType e)
Returns a string corresponding to an enum.
static size_t GetCount()
Returns the number of values corresponding to an enum.
static EnumType GetEnum(uint32 c)
Returns the enum corresponding to a constant value.
static const IndexMap< EnumType, uint32 > GetIndexMap()
Creates and returns an IndexMap instance that can be used to convert between enums of the given type ...