I am trying to wrap a class ContainerMap which exposes a single multimap data member:
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;
};
}
Obviously, the C++ API to the said classes have more complexity in them, but at the Tcl level, I would just need to iterate over _contents elements and look at the inside of ContainedAttributes. I wrote SWIG wrapping code that looks like the following:
%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
Obviously there is further code to wrap the other classes. Regardless of which version of SWIG I use, I always get the same error:
> swig -c++ -tcl8 -ltclsh.i example.i
.../share/swig/4.0.0/std/std_multimap.i:89: Error: Syntax error in input(3).
I have done a lot of trials including commenting some offending lines in the std_multimap.i file, but I cannot get this to even compile properly. Even after commenting the lines that make swig barf (lines 89 and 98), I still cannot compile the generated wrapper code as swig seems to want to generate contructor wrappers for the container class with a single string vector argument. Am I correct in concluding that there is in fact no support for multimap containers for a Tcl target, or am I just making some stupid mistake? If my conclusion is correct, how would you advise to write swig code in order to get iterators that I can use to read the contents of the multimap?