Python &引用;“输入”中的语法错误;当猛击助推时。几何?

Python &引用;“输入”中的语法错误;当猛击助推时。几何?,python,c++,boost,swig,boost-geometry,Python,C++,Boost,Swig,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/p

错误消息:

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;

我一直在重读关于模板的swig部分,我根本不明白哪里出了问题。我做错了什么?如何修复它?

即使
Polygon
是专门化的类型定义或别名,您仍然需要将
%template
与您关心的实际模板一起使用,例如:

%template(pgon) polygon<Point, true, false>;
%模板(pgon)多边形;
您还需要向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>;
%module poly
%{
#包括
#包括
#包括
#包括
#包括
#包括
%}
%内联%{
typedef boost::geometry::model::d2::point_xy point;
typedef boost::geometry::model::polygon;
%}
名称空间提升{
命名空间几何体{
名称空间模型{
模板结构多边形{};
命名空间d2{
模板结构点_xy{};
}
}
}
}
%包括“标准向量i”
%模板(点)boost::几何体::模型::d2::点xy;
%模板(pgon)boost::geometry::model::polygon;
%模板(多边形)std::vector;

这是因为SWIG需要知道它所包装的每种类型的定义以及
%模板
指令。您还需要使您对SWIG和C++编译器都能看到的Type Debug,我用%InLe> <代码>避免重复它们。

错误信息是什么?…代码>多边形< /COD>不再是模板,它是一个具体的类型,那么为什么您需要<代码> %模板(PGON)< /代码>?如果您希望在Python世界中调用
Polygon
pgon
,SWIG可能还有一些其他语法来创建别名。@Praetorian Polygon还不是一个模板类吗?在阅读Swig的文档时,我的印象是,任何定义中包含的类都需要包装在%template()@KarolyHorvath Error:input(1)中的语法错误。
polygon
是类模板,
polygon
或其别名,不再是模板,您已经通过提供所有模板参数对其进行了专门化,现在它是一个真正的类型。
%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>;