NetSim Source Code Help
v14.4
All 13 Components
Loading...
Searching...
No Matches
EnumString.h
1
// File name: "EnumToString.h"
2
#undef DECL_ENUM_ELEMENT
3
#undef BEGIN_ENUM
4
#undef END_ENUM
5
#undef DECL_ENUM_ELEMENT_WITH_VAL
6
7
#ifndef GENERATE_ENUM_STRINGS
8
#define DECL_ENUM_ELEMENT( element ) element
9
#define DECL_ENUM_ELEMENT_WITH_VAL( element, val ) element = val
10
#define BEGIN_ENUM( ENUM_NAME ) typedef enum tag##ENUM_NAME
11
#define END_ENUM( ENUM_NAME ) ENUM_NAME; \
12
char* GetString##ENUM_NAME(enum tag##ENUM_NAME index);
13
#else
14
typedef
struct
{
char
* desc;
int
type;} EnumDesc_t;
15
#define DECL_ENUM_ELEMENT( element ) { #element, (int)(element) }
16
#define DECL_ENUM_ELEMENT_WITH_VAL( element, val ) { #element, val }
17
#define BEGIN_ENUM( ENUM_NAME ) EnumDesc_t gs_##ENUM_NAME [] =
18
#define END_ENUM( ENUM_NAME ) ; \
19
char* GetString##ENUM_NAME(enum tag##ENUM_NAME index) \
20
{ int i; \
21
for (i = 0; i < sizeof(gs_##ENUM_NAME)/sizeof(EnumDesc_t); i++) { \
22
if ((int)index == gs_##ENUM_NAME [i].type) return gs_##ENUM_NAME [i].desc; } \
23
return "Unknown Enum type!!"; }
24
#endif
ALL
Component 1
Part 4
Include
EnumString.h
Generated by
1.13.2