C++ SWIG:std/multimap。我似乎因为Tcl包装而崩溃了
我试图包装一个类ContainerMap,它公开一个multimap数据成员:C++ SWIG:std/multimap。我似乎因为Tcl包装而崩溃了,c++,tcl,swig,readonly,multimap,C++,Tcl,Swig,Readonly,Multimap,我试图包装一个类ContainerMap,它公开一个multimap数据成员: namespace MYCLASSES { class ContainedAttributes { std::string _value; }; class NameList { public: std::vector<std::string> _names; }; typedef std::multimap<NameL
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;
};
}
我已经做了很多尝试,包括在std_multimap.I文件中注释了一些有问题的行,但我甚至无法正确编译这些行。即使在注释了使swigbarf的行(第89行和第98行)之后,我仍然无法编译生成的包装器代码,因为swig似乎希望使用单个字符串向量参数为容器类生成constructor包装器。
我得出的结论是正确的,事实上不支持Tcl目标的multimap容器,还是我犯了一些愚蠢的错误?
如果我的结论是正确的,您会建议如何编写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 -c++ -tcl8 -ltclsh.i example.i
.../share/swig/4.0.0/std/std_multimap.i:89: Error: Syntax error in input(3).