首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SWIG: std/multimap.i似乎不适用于Tcl包装

SWIG: std/multimap.i似乎不适用于Tcl包装
EN

Stack Overflow用户
提问于 2019-05-08 05:24:29
回答 1查看 64关注 0票数 1

我正在尝试包装一个类ContainerMap,它公开了一个多映射数据成员:

代码语言:javascript
运行
复制
    namespace MYCLASSES {
    class ContainedAttributes {
      std::string _value;
    };
    class NameList {
    public:
      std::vector<std::string> _names;
    };
    typedef std::multimap<NameList, ContainedAttributes> ContainerMap;
    class Container {
    public:
      ContainerMap _contents;
    };
    }

显然,上述类的C++应用程序接口的复杂性更高,但在Tcl级别,我只需要遍历_contents元素并查看ContainedAttributes内部。我写了SWIG包装代码,看起来像下面这样:

代码语言:javascript
运行
复制
    %module myclasswrapper
    %nodefaultctor; // Disable creation of default constructors
    %nodefaultdtor; // Disable creation of default constructors
    %include <stl.i>
    %include <std_string.i>
    %include <std_vector.i>
    %include <std/std_multimap.i>
    %{
    #include "my_classes.h"
    #include <vector>
    #include <string>
    #include <map>
    %}
    namespace MYCLASSES {
    using namespace std;
    class NameList {
        vector<string> _names;
    };
    class Container {
    };
    class ContainedAttributes {
    };
    }
    using namespace MYCLASSES;
    using namespace std;
    %template(ContainerMap) multimap<NameList, ContainedAttributes >;
    %template(StringVector) vector<string>
    namespace MYCLASSES {
    %extend Container {
      MYCLASSES::ContainerMap & get_contents {
        return self->_contents;
      }
    }
    <more code here>
    }
    %clearnodefaultctor; // Enable the creation of default constructors again
    %clearnodefaultdtor; // Enable the creation of default constructors again

显然,还有更多的代码来包装其他类。无论我使用哪个版本的SWIG,我总是得到相同的错误:

代码语言:javascript
运行
复制
      > swig -c++ -tcl8 -ltclsh.i example.i
      .../share/swig/4.0.0/std/std_multimap.i:89: Error: Syntax error in input(3).

我做了很多尝试,包括注释std_multimap.i文件中的一些有问题的行,但是我甚至不能正确地编译它。即使在注释了使swig barf的行(第89行和第98行)之后,我仍然无法编译生成的包装器代码,因为swig似乎希望使用单个字符串向量参数为容器类生成构造器包装器。我的结论是,实际上不支持Tcl目标的multimap容器,或者我只是犯了一些愚蠢的错误,这是正确的吗?如果我的结论是正确的,你会建议如何编写swig代码,以便获得我可以用来读取multimap内容的迭代器?

EN

Stack Overflow用户

发布于 2019-05-09 22:42:03

我发现下面的link提供了一个不完美的解决方法。它并不完美,因为它没有提供对所有多map功能的全面包装,而且接口也很笨拙:例如,迭代器只能作为容器本身的扩展方法来操作。当然,没有提供写访问权限,但对我来说,这个限制是可以的。我仍然在寻找一个更好的答案。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56030654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档