Cover from... cover

Skip to first unread message

Aug 3, 2015, 9:11:51 AM8/3/15
to ooc-lang

I've run into a silly problem. In my project ooc-math, I have this cover, FloatPoint2D, which looks like this:

FloatPoint2D: cover {
x, y: Float
init: func@ (=x, =y)

In another project of mine, I'd like to use an external C library that has a struct that looks like this:

typedef struct CvPoint2D32f
float x;
float y;

and in my project I could cover it like so:

OocCvPoint2D32f: cover from CvPoint2D32f {
x, y: Float

So, OocCvPoint2D32f and FloatPoint2D are pretty much the same thing (a datatype with 2 32-bit floats). I could make FloatPoint2D a cover from CvPoint2D32f, but then I'd give ooc-math a dependency on the C library where CvPoint2D32f is defined, and I don't want to do that. I'd still like to be able to use pointers to arrays of CvPoint2D32f in the C library and treat them as pointers to arrays of FloatPoint2D covers in my ooc library, though, without having to run constructors every time I "convert" a CvPoint2D32f into a FloatPoint2D.

The easiest solution seems to be to typecast the pointers, hope the data member offsets are still the same for x and y, and pretend that OocCvPoint2D32f arrays and FloatPoint2D arrays are the same thing. Is there a better solution?

Reply all
Reply to author
0 new messages