You can wrap this header without changing it, buying something like:
%module status %immutable; %inline %{ template <typename Type, size_t N> struct wrapped_array { Type (&data)[N]; wrapped_array(Type (&data)[N]) : data(data) { } }; %} %mutable; %{ #include "status.h" %} %include "typemaps.i" %include "std_except.i"
This is basically the same as my answer here , but instead of changing the header to use wrapped_array , we used %ignore to tell SWIG we will provide our own definition of STATUS to wrap it. (This is completely legal; the created SWIG shell will still use the real definition from status.h)
We insert into this modified definition a getSubStatus() , which returns an object that acts as a proxy for the real array in STATUS . This proxy, in turn, provides __getitem__ , __setitem__ and __len__ , which python is looking for to use the index operator.
There may be a way to do this correctly in Python without requiring getSubStatus() by making SWIG set __swig_setmethods__["SubStatus"] and __swig_getmethods__["SubStatus"] appropriately, but I'm not sure if I can make python SWIG do this.
If you are using C but not using C ++, you need to drop the pattern in favor of a simple struct and use a pointer instead of an array reference.
source share