I have two structs (from a third party lib actually) in my swig .i file that follow this form:
typedef struct MY_STRUCT {
void* pParameter;
unsigned long pLen;
} MY_STRUCT;
%extend MY_STRUCT
{
MY_STRUCT()
{
MY_STRUCT *m= new MY_STRUCT();
m->pParameter = NULL;
m->pLen = 0;
return m;
}
}
typedef struct ANOTHER_STRUCT {
char * another;
unsigned long len;
} ANOTHER_STRUCT;
%extend ANOTHER_STRUCT
{
ANOTHER_STRUCT()
{
ANOTHER_STRUCT *p= new ANOTHER_STRUCT();
p->another = NULL;
p->len = 0;
return p;
}
unsigned long __len__()
{
return sizeof(ANOTHER_STRUCT);
}
}
The pParameter in MY_STRUCT is a void * because it can be a char * or a pointer to a struct (such as ANOTHER_STRUCT). Handling just the char * mapping is simple using %typemap(in) void* = char*;
, but any attempt to use a struct fails. Here's what I'd like to see in Python:
s = MY_STRUCT()
another = ANOTHER_STRUCT()
s.pParameter = another # this should pass the struct pointer
s.pParameter = "some string" # or a char pointer if this is provided
Is this possible? If not, do I need to declare some helper functions to assign the pointer values?