Wrapping C++ struct template in SWIG -


i have c++ code wraps existing object probability follows:

template< typename object > struct roll {     object object;               double probability;       roll( object p, double s )         : object( p )         , probability( s )     { } } 

later, defined in same .h file as:

typedef roll< color > rollcolor; 

there's instruction around how wrap c++ struct primitive type in swig 1 has template also, don't know how wrap in interface file. have idea how can ? thank much.

in .i file, use:

%template(rollcolor) roll<color>; 

more info @ http://www.swig.org/doc1.3/python.html#python_nn26.

assuming have template defined in roll.h , color defined in color.h, need use:

%{    #include "roll.h"    #include "color.h" %}  #include "roll.h" #include "color.h"  %template(rollcolor) roll<color>; 

update, in response op's comment

you can use:

%template(rollcolors) std::vector<roll<color>>; 

however, need implement default constructor in roll first. without can't create std::vector of roll<t>s.

you can use

%template(rollcolors) std::vector<rollcolor>; 

only if have c++ typedef.

%{    #include "roll.h"    #include "color.h"    typedef roll<color> rollcolor; %} 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -