Re: Correct way to map C #define to version

2012-10-29 Thread Sumit Raja

On Monday, 22 October 2012 at 12:44:35 UTC, Regan Heath wrote:
On Mon, 22 Oct 2012 12:39:48 +0100, bearophile 
bearophileh...@lycos.com wrote:



Sumit Raja:


Am I using version correctly? How is this done usually?


I think version is usually meant to be given as compiler 
switch. Maybe a simple enum + static if is enough in your case.


Good suggestion.  I was curious so I had a tinker and produced 
this example which might be useful to you.


import core.stdc.stdint;
import std.stdio;

enum LIBAVFILTER_VERSION_MAJOR = 2;  	\\ change this to 3 to 
see a difference in size below

enum LIBAVFILTER_VERSION_MINOR = 77;
enum LIBAVFILTER_VERSION_MICRO = 100;

enum FF_API_PACKING = (LIBAVFILTER_VERSION_MAJOR  3);

struct AVFilterBufferRefAudioProps {
uint64_t channel_layout;/// channel layout of audio 
buffer
int nb_samples; /// number of audio samples 
per channel

int sample_rate;/// audio buffer sample rate
static if(FF_API_PACKING) {
int planar;  /// audio buffer - planar or 
packed

}
}

void main()
{
writefln(size of AVFilterBufferRefAudioProps = %s, 
AVFilterBufferRefAudioProps.sizeof);

}

R


Thanks both this works great for structs. Anything similar I can 
do for enums?


Re: Correct way to map C #define to version

2012-10-29 Thread Regan Heath

On Mon, 29 Oct 2012 11:31:33 -, Sumit Raja sumitr...@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..)

R

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


Re: Correct way to map C #define to version

2012-10-29 Thread Sumit Raja

On Monday, 29 October 2012 at 12:31:56 UTC, Regan Heath wrote:
On Mon, 29 Oct 2012 11:31:33 -, Sumit Raja 
sumitr...@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...

.
.
.
};



Re: Correct way to map C #define to version

2012-10-29 Thread Regan Heath

On Mon, 29 Oct 2012 13:47:46 -, Sumit Raja sumitr...@gmail.com wrote:

On Monday, 29 October 2012 at 12:31:56 UTC, Regan Heath wrote:
On Mon, 29 Oct 2012 11:31:33 -, Sumit Raja sumitr...@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/


Re: Correct way to map C #define to version

2012-10-29 Thread Mike Wey

On 10/29/2012 03:14 PM, Regan Heath wrote:

On Mon, 29 Oct 2012 13:47:46 -, Sumit Raja sumitr...@gmail.com wrote:

On Monday, 29 October 2012 at 12:31:56 UTC, Regan Heath wrote:

On Mon, 29 Oct 2012 11:31:33 -, Sumit Raja sumitr...@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



You could mixin the entire enum, like this:
https://github.com/MikeWey/DMagick/blob/master/dmagick/c/distort.d#L239

--
Mike Wey


Re: Correct way to map C #define to version

2012-10-22 Thread bearophile

Sumit Raja:


Am I using version correctly? How is this done usually?


I think version is usually meant to be given as compiler 
switch. Maybe a simple enum + static if is enough in your case.


And keep in mind that C int and D int are different on 64 bit 
systems, the D int is always 32 bit. In Phobos there are ints of 
the size of C.


Bye,
bearophile


Re: Correct way to map C #define to version

2012-10-22 Thread Regan Heath
On Mon, 22 Oct 2012 12:39:48 +0100, bearophile bearophileh...@lycos.com  
wrote:



Sumit Raja:


Am I using version correctly? How is this done usually?


I think version is usually meant to be given as compiler switch. Maybe  
a simple enum + static if is enough in your case.


Good suggestion.  I was curious so I had a tinker and produced this  
example which might be useful to you.


import core.stdc.stdint;
import std.stdio;

enum LIBAVFILTER_VERSION_MAJOR = 2;  	\\ change this to 3 to see a  
difference in size below

enum LIBAVFILTER_VERSION_MINOR = 77;
enum LIBAVFILTER_VERSION_MICRO = 100;

enum FF_API_PACKING = (LIBAVFILTER_VERSION_MAJOR  3);

struct AVFilterBufferRefAudioProps {
uint64_t channel_layout;/// channel layout of audio buffer
int nb_samples; /// number of audio samples per channel
int sample_rate;/// audio buffer sample rate
static if(FF_API_PACKING) {
int planar;  /// audio buffer - planar or packed
}
}

void main()
{
writefln(size of AVFilterBufferRefAudioProps = %s,  
AVFilterBufferRefAudioProps.sizeof);

}

R

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