Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void MyFunction( Enum_Name_Here value )
{
// NOTE = also define another header, include all EnumName.h files to generate all enums on compile time
return GetStringEnum_Name_Here(value);
}
#if ( !defined(ENUM_NAME_H) || defined(GENERATE_ENUM_STRINGS) )
#if (!defined(GENERATE_ENUM_STRINGS))
#define ENUM_NAME_H
#endif
#include "EnumToStringHelper.h"
///////////////////////////////
// The enum declaration
///////////////////////////////
BEGIN_ENUM(Enum_Name_Here)
{
DECL_ENUM_ELEMENT(Enum_Elem_0),
DECL_ENUM_ELEMENT(Enum_Elem_1),
DECL_ENUM_ELEMENT(Enum_Elem_2)
}
END_ENUM(Enum_Name_Here)
#endif // (!defined(ENUM_NAME_H) || defined(GENERATE_ENUM_STRINGS))
#undef DECL_ENUM_ELEMENT
#undef BEGIN_ENUM
#undef END_ENUM
#ifndef GENERATE_ENUM_STRINGS
#define DECL_ENUM_ELEMENT( element ) element
#define BEGIN_ENUM( ENUM_NAME ) typedef enum tag##ENUM_NAME
#define END_ENUM( ENUM_NAME ) ENUM_NAME; \
char* GetString##ENUM_NAME(enum tag##ENUM_NAME index);
#else
#define DECL_ENUM_ELEMENT( element ) #element
#define BEGIN_ENUM( ENUM_NAME ) char* gs_##ENUM_NAME [] =
#define END_ENUM( ENUM_NAME ) ; char* GetString##ENUM_NAME(enum \
tag##ENUM_NAME index){ return gs_##ENUM_NAME [index]; }
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment