swig:std/multimap.i似乎打破了TCL包装
SWIG: std/multimap.i seems broken for Tcl wrapping
我正在尝试包装一个containermap,该类contermap暴露了单个多胶合数据成员:
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 API在其中具有更复杂的性能,但是在TCL级别上,我只需要迭代_contents元素,然后查看含有术的内部即可。我写了Swig包装代码,如以下内容:
%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,我总是会遇到相同的错误:
> 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似乎想要使用单个字符串矢量参数为容器类生成Contructor包装器。我是否正确地得出结论,实际上不支持用于TCL目标的多胶合容器,还是我只是犯了一些愚蠢的错误?如果我的结论是正确的,您将如何建议编写SWIG代码以获取我可以用来阅读多件内容的迭代器?
我找到了以下链接,该链接提供了不完美的解决方法。从某种意义上说,它不提供所有多映射功能的完整包装,并且接口很尴尬:例如,迭代器只能作为容器本身的扩展方法操纵。当然,没有提供写入访问,但是出于我的目的,此限制还可以。我仍然有一个更好的答案。
相关文章:
- 如何在c++17中制作一个模板包装器/装饰器
- std::vector的包装器,使数组的结构看起来像结构的数组
- 如何在c++迭代器类型中包装std::chrono
- 是否可以用"iostream"包装现有的TCP/OOpenSSL会话
- 用pybind11包装C++抽象类时出错
- 为左值和右值的包装器实现C++范围
- C结构,其指针将被包装在unique_ptr中
- 如何包装第三方DLL在R中使用
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 将 N-arg 函数包装到另一个函数中
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 包装一个对象并假装它是一个 int
- 使用 Python Extension API 包装复杂C++类
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 包装C++类时不完整的类型 GLFWwindow
- 将函数包装器转换为 std::function
- C++函数包装器来捕获某些信号
- swig:std/multimap.i似乎打破了TCL包装
- 编译 TCL-DLL 包装器时出现的问题
- 改进make函数的Swig-tcl包装