I am hoping someone here is able to help me.  My company has decided to wrap the vector class, stlVector.  It contains a couple of extra convenience methods, but I really have no interest in wrapping those extra functions if they make things harder for me.

 

I would like to be able to gain the same benefits that swig provides when using std::vector.  Being able to pass a list as input, or iterate through a stlVector in python more natuarally. 

 

I’ve been scouring the web trying to figure out how to do this, and I did find this response for William Fulton with regard to doing the same for std::string:

 

>Wrapping strings is a little quirky. As you should have worked out by 
>now SWIG deals with types and strings are an unusual type as they are 
>not simple primitive types, like int, double and they are not 
>classes/structs which are wrapped with proxy classes in the target 
>language. They are something in between the C/C++ string is mapped to an 
>immutable target language string. The wrappers for strings are therefore 
>a bit unusual and simply having your own String type that derives from 
>std::string does not make it easy to re-use the library code that SWIG 
>ships for std::string. The quickest and easiest way is to run swig -E on 
>std_string.i, take the preprocessed output, tidy it up and change 
>std::string to String, and pop that in your own interface file. 

 

I’ve done this, and it works great for me.  I was hoping to apply this to vector as well, but it looks to be trickier. 

 

Is this the right way to go with vector?  Or should I just be looking to do something else?

 

If I am going in the right direction, I’ve done the following:

 

-          Replaced all std::vector and std_vector with stlVector

-          Searched for the whole word  (and case-sensitive) vector and replaced with stlVector

-          Removed the ‘namespace std {‘ (and corresponding ‘}’) that wrapped the vector class

-          Because I removed the std namespace, I add to qualify the std allocator:

template <class _Tp, class _Alloc=std::allocator<_Tp> >

class stlVector …

 

Now, when I run swig, I get the following error:

 

Error: Can't copy typemap (directorout) stlVector< myClass< DEFAULT_POLICY > *,std::allocator< myClass< > * > > = stlVector< myClass< DEFAULT_POLICY > *,std::allocator< myClass< > * > > &DIRECTOROUT

 

I have no idea what this means.. The only reference I found online had to do with a internal swig bug. Any ideas about the error, or if I should proceed differently here in any way? 

 

By the way - I am using swig 2.0.10… And generating python bindings..

 

 

Thanks!