SWIGging Boost.Geometry时“输入中的语法错误”?

问题描述 投票:2回答:1

错误信息:

Error: Syntax error in input(1)

我的Swig文件:

%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;

如果我注释掉最后一行,它会编译

// %template(pgon) Polygon;

我一直在重读模板上的swig部分,我根本无法理解什么是错的。我做错了什么,我该如何解决?

python c++ boost swig boost-geometry
1个回答
0
投票

即使Polygon是专业化的typedef或别名,你仍然需要使用%template和你关心的实际模板,例如:

%template(pgon) polygon<Point, true, false>;

您还需要向SWIG展示足够的相关类型的定义/声明,以便弄清楚发生了什么并使用正确的类型。

因此,最小的完整接口文件的行为方式如下:

%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>;

这是因为SWIG需要知道它包装的每种类型的定义以及%template指令。您还需要使您编写的typedef对SWIG和C ++编译器都可见,我使用%inline来避免重复它们。

© www.soinside.com 2019 - 2024. All rights reserved.