Skip to content

Instantly share code, notes, and snippets.

@Aegean-Homines
Created May 21, 2016 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aegean-Homines/0d090538a7b6ebc2eb404071da741afb to your computer and use it in GitHub Desktop.
Save Aegean-Homines/0d090538a7b6ebc2eb404071da741afb to your computer and use it in GitHub Desktop.
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