I'm trying to make a C++ library available as a Python module. It seems SIP is the best tool for the job. (If wrong, please correct me.)
One class looks like the programmer was trying to get around c's lack of dynamic typing:
class Item{
private:
enum ITEMTYPE{TYPE_INT,TYPE_FLOAT,TYPE_INT_ARRAY,TYPE_FLOAT_ARRAY};
enum ITEMTYPE type;
int intValue;
int* intArrayValue;
float floatValue;
float* floatArrayValue;
public:
enum ITEMTYPE getType();
int getItemCount();
int getIntValue();
int* getIntArrayValue();
float getFloatValue();
float* getFloatArrayValue();
...
};
I can't find documentation anywhere that says how to handle functions that return arrays. At minimum, I'd like to be able to call getIntArrayValue() from Python. Even better would be to have a single Python function that automatically calls getType(), then calls one of the get???Value() to get the value (and if necessary, calls getItemCount() to determine the array length, treating arrays as numpy or tuples.
My current .sil file looks like this:
class Item{
%TypeHeaderCode
#include<Item.h>
%End
public:
enum ITEMTYPE{
TYPE_INT=0,
TYPE_FLOAT=1,
TYPE_INT_ARRAY=2,
TYPE_FLOAT_ARRAY=3,
};
ITEMTYPE getType();
int getItemCount();
int getIntValue();
//int*getIntArrayValue();
float getFloatValue();
//float*getFloatArrayValue();
};
Thanks in advance. I've been searching so hard, but have come up empty.
I don't know sip, but I've used swig to wrap C++ into a python module and it was pretty straightforward. swig can handle most standard C++ data types (including standard library containers) automatically.