Correct way to map C #define to version

Regan Heath regan at netmail.co.nz
Mon Oct 29 07:14:15 PDT 2012


On Mon, 29 Oct 2012 13:47:46 -0000, Sumit Raja <sumitraja at gmail.com> wrote:
> On Monday, 29 October 2012 at 12:31:56 UTC, Regan Heath wrote:
>> On Mon, 29 Oct 2012 11:31:33 -0000, Sumit Raja <sumitraja at gmail.com>  
>> wrote:
>>> Thanks both this works great for structs. Anything similar I can do  
>>> for enums?
>>
>> Example?  (The C/C++ code you're trying to convert..)
>
> Yeah that might help... One example here (though it seems slightly  
> inconsistent as the enum following the second if seems to be padded for  
> the values inside the ifdef):
>
> enum PixelFormat {
>      PIX_FMT_NONE= -1,
> .
> .
> .
> #ifdef AV_PIX_FMT_ABI_GIT_MASTER
>      PIX_FMT_RGBA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G,  
> 16B, 16A, the 2-byte value for each R/G/B/A component is stored as  
> big-endian
>      PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G,  
> 16B, 16A, the 2-byte value for each R/G/B/A component is stored as  
> little-endian
>      PIX_FMT_BGRA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G,  
> 16R, 16A, the 2-byte value for each R/G/B/A component is stored as  
> big-endian
>      PIX_FMT_BGRA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G,  
> 16R, 16A, the 2-byte value for each R/G/B/A component is stored as  
> little-endian
> #endif
>      PIX_FMT_GBRP,      ///< planar GBR 4:4:4 24bpp
> .
> .
> .
>      PIX_FMT_GBRP16LE,  ///< planar GBR 4:4:4 48bpp, little endian
>
> #ifndef AV_PIX_FMT_ABI_GIT_MASTER
>      PIX_FMT_RGBA64BE=0x123,  ///< packed RGBA 16:16:16:16, 64bpp, 16R,  
> 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as  
> big-endian
>      PIX_FMT_RGBA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G,  
> 16B, 16A, the 2-byte value for each R/G/B/A component is stored as  
> little-endian
>      PIX_FMT_BGRA64BE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G,  
> 16R, 16A, the 2-byte value for each R/G/B/A component is stored as  
> big-endian
>      PIX_FMT_BGRA64LE,  ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G,  
> 16R, 16A, the 2-byte value for each R/G/B/A component is stored as  
> little-endian
> #endif
>      PIX_FMT_0RGB=0x123+4,      ///< packed RGB 8:8:8, 32bpp, 0RGB0RGB...
> .
> .
> .
> };

Well, I can't see a way to do that in D without duplicating most of the  
enum.  :(

If no-one else can think of a way, I reckon we want an enhancement request  
to allow "version" or "static if" or perhaps "mixin" inside enums...

http://d.puremagic.com/issues/

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list