|
Boost : |
Subject: Re: [boost] enum / string translation
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-07-22 08:56:42
On Wed, Jul 22, 2009 at 6:52 AM, Mathias
Gaunard<mathias.gaunard_at_[hidden]> wrote:
> 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?
Not if you declare it in a cpp file, but if you declare it in a highly
visible .h file then yes. Do you have a way around this so that it
can be declared in a .h file?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk