[wsf-c-dev] [C++] How should this be implimented in C++?

Damitha Kumarage damitha at wso2.com
Fri Oct 19 15:36:09 PDT 2007


Hi Senaka,
The sample I worked out is not guaranteed to work portably between 
compilers. Especially when the C++ class has virtual functions most 
probably it will fail. The right way to do this is derive the C++ class 
from the C structures and when callling
C functions from within the C++ wrapper pass this pointer.
 
http://developers.sun.com/solaris/articles/mixing.html
explains it well.
Damitha

> Hi Senaka,
>
> Senaka Fernando wrote:
>
>> The code below is extracted from axiom_node.h, in Axis2/C. How should
>> this be implemented in C++? What types are returned? Is it really
>> required? Are there any alternative workarounds?
>>       /**
>>        * get the struct contained in the node
>>        * IF the node is on type AXIOM_ELEMENT , this method returns
>>        * a pointer to  axiom_element_t struct contained
>>        * @param om_node node
>>        * @returns pointer to struct contained in the node
>>        * returns NULL if no struct is contained
>>        */
>>        AXIS2_EXTERN void *AXIS2_CALL
>>        axiom_node_get_data_element(wsf_axiom_node om_node);
>>  
>>
> In Axis2/C axiom I could not find the functio you mentioned. However I 
> can see
>    AXIS2_EXTERN void *AXIS2_CALL
>    axiom_node_get_data_element(
>        axiom_node_t * om_node,
>        const axutil_env_t * env);
> May be you have made a mistake or is this something else?.
> Also I cannot understand what you mean by your question.
> Anyway when I try to sense your question I guess studying the sample I 
> created
> below may give you some facts to think about and discuss.
>
> Say I have a struct cperson type in C and I have a function called
>
> caddress_t *
> cperson_get_address(
>    cperson_t *person)
>
> implemented in C. If I write a wrapper for this in C++ I will be 
> having a classes called person and address corresponding to the 
> structs cperson and caddress in C
> and it has class variables similar to the corresponding C structures.
>
> Here is how my wrapper method in C++ would be.
> address *get_address()
> {
>        return (address *) cperson_get_address((cperson_t *) this);
> }
>
> Complete running sample is attached. Please study it and check the 
> sanity of the code with regards to compilers, specs etc.
> Damitha
>
>
>
>> Regards,
>> Senaka
>>
>>
>> _______________________________________________
>> Wsf-c-dev mailing list
>> Wsf-c-dev at wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/wsf-c-dev
>>
>>  
>>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Wsf-c-dev mailing list
>Wsf-c-dev at wso2.org
>http://wso2.org/cgi-bin/mailman/listinfo/wsf-c-dev
>  
>




More information about the Wsf-c-dev mailing list