我想知道是否可以使用SWIG将两个模块中的对象混合在一起,例如模块A的功能是否可以返回模块B的对象?
我的用例如下:
class_a.hpp:
class ClassA
{
public:
const OGRPolygon& get_geom() const;
void set_geom(OGRPolygon* geom);
protected:
OGRPolygon* _footprint;
};
class_a.cpp:
const OGRPolygon& ForCity::SPreC_cpp::ClassA::get_geom() const
{
return *(this->_footprint);
}
void ForCity::SPreC_cpp::ClassA::set_geom(OGRPolygon* geom)
{
this->_footprint = geom;
}
test.i:
%module test
%include "class_A.hpp"
然后在Python中,我希望能够执行以下操作:
A = test.ClassA()
G = ogr.Geometry(ogr.wkbLinearRing)
# filling the geometry...
A.set_geom(G) # set the geometry of A
A.get_geom().GetArea() # use the geometry of A as a usual OGR geometry
有可能吗,以及如何做到这一点?
最佳答案
通过在%import ClassB
文件中包含.i
指令,可以实现此目的。该伪指令读取类型信息,但不生成绑定。