python - What's causing this SWIG syntax error? -
error message:
error: syntax error in input(1)
my swig file:
%module interfaces %{ #include <vector> #include <list> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/geometry/geometries/linestring.hpp> typedef boost::geometry::model::d2::point_xy<double> point; typedef boost::geometry::model::polygon<point, true, false> polygon; %} %include "std_vector.i" %template(multipolygon) std::vector<polygon>; %template(pgon) polygon;
if comment out last line, compiles
// %template(pgon) polygon;
i've been re-reading swig section on templates , can't understand @ what's wrong. doing wrong , how fix it?
even though polygon
typedef or alias specialization still need use %template
actual template care about, e.g.:
%template(pgon) polygon<point, true, false>;
you'll need show swig enough of definition/declaration of types involved figure out what's going on , use right types.
thus smallest complete interface file behaves how want is:
%module poly %{ #include <vector> #include <list> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/geometry/geometries/linestring.hpp> %} %inline %{ typedef boost::geometry::model::d2::point_xy<double> point; typedef boost::geometry::model::polygon<point, true, false> polygon; %} namespace boost { namespace geometry { namespace model { template<typename p, bool cw, bool cl> struct polygon {}; namespace d2 { template <typename t> struct point_xy {}; } } } } %include "std_vector.i" %template(point) boost::geometry::model::d2::point_xy<double>; %template(pgon) boost::geometry::model::polygon<point, true, false>; %template(multipolygon) std::vector<polygon>;
this because swig needs know definition of every type wraps %template
directive. need make typedefs write visible both swig , c++ compiler, did %inline
avoid repeating them.
Comments
Post a Comment