1

I'm in the process of trying to wrap a few C++ header files that have classes that use pointers in two of the following ways:

1) As arrays as data members for a class.
2) As an array as an argument for a function

These classes are to be subclassed in Python and the methods are to be overridden.

An example header file would look something like this:

struct Array{
    int * array;
    int array size;
}

class A{
    public:
        //Meant to be accessed as an array
        virtual void func( int size, double * array) = 0;
        virtual bool func2(long size1, long size2, float * array1, int * array2) = 0;
}

In all cases, the arrays are meant to be static in size. However, in some instances, the arrays have been initialized and in others, they have not( so the pointer=NULL).

What I need to figure out is:

1) How do you wrap a C++ array if it is a data member of a class?
2) How do you handle C++ arrays that are passed as arguments to a function?
3) How do you allocate and initialize the wrapped array in Python?
4) How do you wrap C++ arrays so that changes made in Python are passed back to the original array and that changes to the original array are reflected in the Python?

EDIT:
I'm not demanding that answers for all four questions be discussed for SWIG, cytpes, Cython and Boost-Python. A discussion on all four would be nice, however, I realize that is asking a bit much.

I have a preference for the response to use SWIG. However, I tagged all four because in trying to find a solution to this problem myself, I found that there is sparse information on how to achieve this for any of Python extension systems.

My hopes were to create a good starting point for a reoccurring issue when trying to wrap C++ code.

2
  • 2
    Do you expect us to enumerate answers to all four of your questions for all four Python extension systems you tagged this post with? Commented Apr 17, 2012 at 13:15
  • An old example I did for a similar question is this answer. Also note the other answer in that question about using numpy. If you still have trouble post your code. Commented Apr 18, 2012 at 2:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.