Improved SWIG C# wrappers std_vector.i and std_map.i – part 2

* Note: since posting this a new version of SWIG has been released (version 1.3.40). This version includes the improved C# wrappers discussed here. A simple explanation about these wrappers can be found here.

After posting my previous post on the improved SWIG C# wrappers for std::vector (std_vector.i) and std::map (std_map.i) I was contacted by one of the main developers of SWIG, William Fulton. This led me to discover the extensive testing suite that SWIG is delivered with.

I tested my improved std_vector.i wrapper against the testing suite, and this went well. Then I wanted to test my std_map.i wrapper, as it is a complete rewrite of the existing wrapper.  Since there was no existing test suite for the std_map.i wrapper, I created my own test suite for this wrapper. This flushed out a lot of bugs, and the wrapper is hopefully in much better shape now.

Here is the new version of std_vector.i wrapper: std_vector.i

And the new version of the std_map.i wrapper: std_map.i

The two files relevant for the testing suite of std_map.i are: li_std_map.i and li_std_map_runme.cs

These can be incorporated in the existing SWIG testing suite. I tested them on Windows using Visual Studio. I’m also attaching my C++ and C# solutions for this testing suite. To use them – first rebuild the C++ solution, and then rebuild the C# solution and run it. std_map_test.zip

These wrappers will now hopefully be included in the next release of SWIG, though a good code review wouldn’t hurt…

This entry was posted in Uncategorized. Bookmark the permalink.

8 Responses to Improved SWIG C# wrappers std_vector.i and std_map.i – part 2

  1. Dave says:

    Please update with your improvement SWIG # Wrapper. Keep it up!

  2. Dave says:

    Please update ME with your improvement SWIG # Wrapper. Keep it up!

  3. Truman says:

    What version of swig are you using? I tried using the std_map.i but I am running into an error using swig 1.3.38.

    I am using a very basic file:

    %module test

    %include “std_map.i”

    %template(IntIntMap) std::map

  4. yuval says:

    I tested using version 1.3.39, though I think it might be enough to download the updated version of std_vector.i and use:

    %module test

    %include “std_vector.i”
    %include “std_map.i”

    %template(IntVector) std::vector<int>
    %template(IntIntMap) std::map<int, int>

  5. Truman says:

    Got it working. Thanks.

  6. Danny says:

    Could you update your example uisng the 1.3.40, I would like to learn how to use. Especially the distribution does not come with an example that can be compile right out of the box. Thanks

  7. Danny says:

    Could you update your example (zip) to 1.3.40. Appreciate

  8. yuval says:

    Hi Danny,
    Check out this post for some examples using swig version 1.3.40.
    If you have any more questions – feel free to contact me.
    Yuval.

Leave a Reply

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