2010-04-14 20:13:19 +02:00
|
|
|
/** \brief enum to string conversion
|
|
|
|
*
|
|
|
|
* This is the heart of the 'automatic' enum to string conversion and taken
|
|
|
|
* from:
|
|
|
|
* <a href="http://www.codeproject.com/KB/cpp/C___enums_to_strings.aspx">http://www.codeproject.com/KB/cpp/C___enums_to_strings.aspx</a>
|
|
|
|
*
|
|
|
|
* Thanks to Marcos F. Cardoso.
|
|
|
|
*
|
|
|
|
* With the preprocessor #defines from this file and a special inclusion and
|
|
|
|
* enum definition strategy the code for enum to string conversion is
|
|
|
|
* automatically created.
|
|
|
|
*
|
|
|
|
* For an enum of name "MyEnum" the conversion function will be called
|
|
|
|
* <code>const char* GetStringMyEnum(MyEnum tagMyEnum);</code>.
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2010-11-27 20:56:38 +01:00
|
|
|
#undef DECL_ENUM_LAST
|
2010-04-05 23:38:59 +02:00
|
|
|
#undef DECL_ENUM_ELEMENT
|
|
|
|
#undef BEGIN_ENUM
|
|
|
|
#undef END_ENUM
|
|
|
|
|
|
|
|
#ifndef GENERATE_ENUM_STRINGS
|
2010-11-27 20:56:38 +01:00
|
|
|
#define DECL_ENUM_LAST( ENUM_NAME ) ENUM_NAME ## Last
|
2010-04-05 23:38:59 +02:00
|
|
|
#define DECL_ENUM_ELEMENT( element ) element
|
|
|
|
#define BEGIN_ENUM( ENUM_NAME ) typedef enum tag##ENUM_NAME
|
|
|
|
#define END_ENUM( ENUM_NAME ) ENUM_NAME; \
|
2010-06-02 13:39:39 +02:00
|
|
|
const char* GetString##ENUM_NAME(enum tag##ENUM_NAME index); \
|
|
|
|
const char* GetString##ENUM_NAME(unsigned int index);
|
2010-04-05 23:38:59 +02:00
|
|
|
#else
|
2010-11-27 20:56:38 +01:00
|
|
|
#define DECL_ENUM_LAST( ENUM_NAME ) #ENUM_NAME
|
2010-04-05 23:38:59 +02:00
|
|
|
#define DECL_ENUM_ELEMENT( element ) #element
|
|
|
|
#define BEGIN_ENUM( ENUM_NAME ) const char* gs_##ENUM_NAME [] =
|
2010-06-02 13:39:39 +02:00
|
|
|
#define END_ENUM( ENUM_NAME ) ; \
|
|
|
|
const char* GetString##ENUM_NAME(enum \
|
2010-11-27 20:56:38 +01:00
|
|
|
tag##ENUM_NAME index){ if (index < 0 || index > ENUM_NAME ## Last) return "Unknown Enum"; return gs_##ENUM_NAME [index]; } \
|
|
|
|
const char* GetString##ENUM_NAME(unsigned int index){ if (index < 0 || index > ENUM_NAME ## Last) return "Unknown Enum"; return gs_##ENUM_NAME [index]; }
|
2010-04-05 23:38:59 +02:00
|
|
|
#endif
|