"Syntax error in input" when SWIGging Boost.Geometry?
"Syntax error in input" when SWIGging Boost.Geometry?
错误信息:
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部分,我完全不明白哪里出了问题。我做错了什么?我该如何改正?
即使Polygon
是专门化的类型定义别名,您仍然需要将%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
指令。您还需要使您编写的类型对SWIG和c++编译器都可见,我在%inline
中这样做是为了避免重复它们。
相关文章:
- 像union_这样的 Boost.Geometry 操作如何处理浮点类型的基本不精确性?
- boost::geometry::within() 点和序列的行为
- 使用boost::geometry::intersects时出现运行时错误
- 使用 boost::geometry::追加时,自定义点类中的 ID 字段间歇性丢失
- Cythonic 方式包装 boost::geometry::P oint accessors
- 从 2D C 列表创建 boost.geometry.model.polygon
- 我可以将 Boost.Geometry.index.rtree 与线程一起使用吗?
- 如何在 boost::geometry 中找到 2 个多边形的接触长度
- 使用 boost::geometry::d ifference,为什么在使用 multi_polygon 而不是使用常规
- Boost.geometry 实现多边形概念
- 如何为 OGRPoint 和 OGRLineString 注册 Boost.Geometry 距离策略
- 使用 Boost.Geometry 偏移多边形
- 在循环中重复使用 boost::geometry:::交集
- boost::geometry::read_wkt备选方案
- 如何组合两个Boost Geometry变换器
- boost::geometry::model::模板点类型的分段构造函数
- 使用Boost.Geometry计算直线和多边形之间的交点
- 如何从boost::geometry::model::point继承
- 如何使用 boost::geometry::d istance with opencv cv::P oint.
- boost::多边形和boost/geometry/geometry/多边形差异