Improved SWIG C# wrappers for std::vector and std::map

I recently ran into the very impressing SWIG package. This package takes functions and classes written in C++ and creates wrappers for them in several languages including Perl, PHP, Python, Java, C#, Ruby and many more.

Using this package is quite easy. It comes with several examples for each language which you can just change a bit to fit your specific needs.

I used this package to wrap some C++ code I had into C# and was quite pleased with it. I started running into problems when I wanted to use STL containers like std::vector and std::map and have them translated into C# generic containers like IList and IDictionary. The C# wrappers supplied with SWIG for these types didn’t implement the relevant interfaces. The std::map wrapper was actually quite useless because it supplied only very basic functionality without even supplying a method for receiving the existing keys in the map.

So I decided to enhance the existing wrappers and have the std_vector.i wrapper implement the IList interface and have the std_map.i wrapper implement the IDictionary interface. I have attached my version of the wrappers here. If you have any comments or suggestions – please post them.

The improved std::vector wrapper: std_vector.i

The improved std::map wrapper: std_map.i

* Note: an updated version of these wrappers is available in my next post on this subject: Improved SWIG C# wrappers std_vector.i and std_map.i – part 2

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Improved SWIG C# wrappers for std::vector and std::map

  1. Pingback: Improved SWIG C# wrappers for std::vector and std::map « Yuval Baror’s Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>