Help writing a glue function to house a c OpenCV preprocessor macro?

asked 2013-11-02 23:16:47 -0500

joeish80829 gravatar image

Im writing a glue function to house this macro(CV_GET_SEQ_ELEM) because im building an opencv wrapper

here it is defined

#define  CV_SEQ_ELEM( seq, elem_type, index )                    \
/* assert gives some guarantee that <seq> parameter is valid */  \
(   assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) &&      \
    (seq)->elem_size == sizeof(elem_type)),                      \
    (elem_type*)((seq)->first && (unsigned)index <               \
    (unsigned)((seq)->first->count) ?                            \
    (seq)->first->data + (index) * sizeof(elem_type) :           \
    cvGetSeqElem( (CvSeq*)(seq), (index) )))
#define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )

i know how it works ie replace

 CV_SEQ_ELEM(mytype,int,1)

 with

 ( assert(sizeof((mytype)->first[0]) == sizeof(CvSeqBlock) &&
   (mytype)->elem_size == sizeof(int)), (int*)((mytype)->first &&
 (unsigned)1 < (unsigned)((mytype)->first->count) ? (mytype)->first->data +
 (1) * sizeof(int) : cvGetSeqElem( (CvSeq*)(mytype), (1) )))

but what do i cast the return value to for CV_GET_SEQ_ELEM when I write my glue function because the documentation for it says...."The macro checks first whether the desired element belongs to the first block of the sequence and returns it if it does; otherwise the macro calls the main function GetSeqElem" the documentation for cvGetSeqElem says "Returns a pointer to a sequence element according to its index." so the macro seems to have ability to return 2 separate values but the function cvGetseqElem does not....cvGetSeqElems return is usually cast to other types when its used though....I was hoping you could help me figure out how to cast its return and how to get by the parameters not being declared here i/e to int or double etc

  #define CV_GET_SEQ_ELEM( elem_type, seq, index ) 
      CV_SEQ_ELEM( (seq), elem_type, (index) )

I know what these variables are i/e elem_type is an int and seq is a CvSeq*, index is an int....but i have alot glue code to write for macros like this....so if i didnt know what the variables should be declared as ....what do i do.....this will help me master this part of writing my library(glue code for macros) if you could answer this for me... Cheers!=)

edit retag flag offensive close merge delete

Comments

if it was a function, you'd have to specify the return type of it. there's a reason, why this is a macro.

berak gravatar imageberak ( 2013-11-04 05:21:23 -0500 )edit