|
From: Angus M. <am...@gm...> - 2009-08-25 22:31:44
|
2009/8/25 Josh Cherry <jc...@nc...>:
>
>
> On Tue, 25 Aug 2009, Angus McMorland wrote:
>
>> typedef struct {
>> int a;
>> double x;
>> } TEST_DATA;
>> ...
>> TEST_DATA cdata;
>> cdata.a = 3;
>> cdata.x = 123.456;
>> msg.SetData( &cdata, sizeof(cdata));
>>
>> where the signature for SetData is
>>
>> int Msg::SetData( void *pData, int num_bytes)
>>
>> If I wrap the struct typedef with swig, create an instance of it
>> (let's call it pydata) in Python, and pass SetData pydata.this, then
>> all works okay. The problem with that approach, however, is that I
>> can't work out how to get the size of the structure (which SetData
>> also requires), since swig doesn't expose this to Python (just a class
>> object with no size information). Nor can I work out how, in the C
>> wrapper, to calculate that size and pass it to SetData at the wrapper
>> level.
>
> You could use %extend to provide a Msg::SetData signature that takes a
> TEST_DATA. You could also use %extend to give TEST_DATA a method that
> returns its size, but the first approach would be more convenient for users.
Thanks Josh,
One issue I didn't make clear is that there are potentially hundreds
of different types of structures that we would want to feed into
SetData, with different contents, so any method would have to either
be able to handle them all generically, or automatically generatable
from the protocol's C++ header files. It sounds a bit like your
solution would be specific to TEST_DATA, or is there a way to make
this multi-purpose?
Angus.
--
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh
|