On 2 May 2012 18:40, Luc Fabresse <[email protected]> wrote:
> Hi Igor and other NB Gurus,
>
>  A group of students is trying to use NativeBoost to wrap the OpenCV C image
> library.
>  The problem we are facing is that the function cvSize return a struct.
>
>       typedef struct { int width; int height; } CvSize;
>       CV_INLINE  CvSize  cvSize( int width, int height );
>
>  But the NBExternalStructure seems to not support that if I understood
> correctly.
>
>       NBExternalStructure>>coerceReturn: gen
>       " ... should we support handling return of external structures? "
>       self error: 'returning pointer to structure?'
>
>  Did I miss something?
>  Any idea or workaround?
>

there is a workaround.
all structs in C is returned via pointer.
so, actually a true return type of a function is CvSize*

so, what you do is to change the return value to simple void*
and then copy the contents of struct into instance of corresponding
NBExternalStructure subclass
using #fromPointer: method.. to conveniently access its fields values.


but this is in general, in your case this function is actually inlined
by compiler (as CV_INLINE suggests), so there could be even no
exported symbol for it in dynamic library.
and the function is actually so simple, that you don't need to wrap it at all.
you can just create a subclass of NBExternalStructure , named CvSize,
implement fieldDesc method as:

fieldsDesc
^ #(
int width;
int height
)

and if you invoke:

CvSize new width: 1 height:2

it will be equivalent as if you will call cvSize(1,2) function.

>  Thanks,
>
> Luc



-- 
Best regards,
Igor Stasenko.

Reply via email to