
Zachary Turner a écrit :
I wrote some code to perform both compile-time and runtime translation between enums and their corresponding string values. The only direction that isn't possible is string->enum at compile time.
Is there any interest in this? You can use it as follows:
typedef enum { ValueA1, ValueA2 } EnumA; typedef enum { ValueB1, ValueB2 } EnumB;
BEGIN_ENUM_MAP_DECLS() BEGIN_ENUM_MAP(EnumA, a_map) ENUM_MAP(ValueA1) //maps ValueA1 to the string "ValueA1", provides both compile-time and run-time lookups. ENUM_MAP_NAME(ValueA2, "custom name") //maps ValueA2 to the string "custom name", provides both compile-time and run-time lookups END_ENUM_MAP()
BEGIN_ENUM_MAP(EnumB, b_map) ENUM_MAP(ValueB1) ENUM_MAP(ValueB2) END_ENUM_MAP() END_ENUM_MAP_DECLS()
So that means I'll have a copy of the runtime map in every translation unit?