代码之家  ›  专栏  ›  技术社区  ›  StormRider

SWIG:从另一个模块返回对象的函数

  •  0
  • StormRider  · 技术社区  · 9 年前

    我想知道是否可以使用SWIG混合来自两个模块的对象,例如,模块a的函数是否可以返回模块B的对象?

    我的用例如下:

    类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;
    }
    

    测试.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
    

    这是可能的吗?请怎么做?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Alexander Solovets    9 年前

    这可以通过包括 %import ClassB 您的指令 .i 文件此指令读取类型信息,但不生成绑定。