%module li_std_map /* ----------------------------------------------------------------------------- * See the LICENSE file for information on copyright, usage and redistribution * of SWIG, and the README file for authors - http://www.swig.org/release.html. * * li_std_map.i * * SWIG test generator for std_map.i * Implementation by Yuval Baror (http://yuval.bar-or.org) * * Note that the basic usage of the std_map.i is: * * %include "std_map.i" * %template(Int_Vector) std::vector * %template(Int_Double_Mector) std::map * * In C#, for non-basic types a call to SWIG_STD_MAP_SPECIALIZE must be made. For example: * SWIG_STD_MAP_SPECIALIZE(MyCppKeyClass, MyCppValueClass, MyCsKeyClass, MyCsValueClass) * %template(MyCppKeyClass_Vector) std::vector; * %template(MyKeyClass_MyValueClass_Map) std::map; * * Or if the C# class names are the same as the C++ class names, you can use: * * SWIG_STD_MAP_SPECIALIZE_SIMPLE(MyKeyClass, MyValueClass) * %template(MyKeyClass_Vector) std::vector; * %template(MyKeyClass_MyValueClass_Map) std::map; * * ----------------------------------------------------------------------------- */ %include "std_map.i" %include "std_vector.i" %include "std_string.i" // Declare some vector templates to be used as keys for the maps %template(IntVector) std::vector; %template(StringVector) std::vector; %template(BoolVector) std::vector; %template(CharVector) std::vector; %template(DoubleVector) std::vector; // Declare some maps to play around with %template(IntIntMap) std::map; %template(StringIntMap) std::map; // Add an inline function to test %inline %{ double keyAverage(std::map m) { if (m.size() == 0) { return 0.0; } double a = 0.0; for (std::map::iterator i = m.begin(); i != m.end(); i++) { a += i->first; } return a / m.size(); } struct Struct { double num; Struct() : num(0.0) {} Struct(double d) : num(d) {} }; %} #if defined(SWIGCSHARP) // Specialize some more non-default map types SWIG_STD_MAP_SPECIALIZED(int, int *, int, SWIGTYPE_p_int) SWIG_STD_MAP_SPECIALIZED(int, const int *, int, SWIGTYPE_p_int) SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, Struct) SWIG_STD_MAP_SPECIALIZED(int, Struct *, int, Struct) SWIG_STD_MAP_SPECIALIZED(int, const Struct *, int, Struct) SWIG_STD_MAP_SPECIALIZED(Struct *, int, Struct, int) #endif #if !defined(SWIGR) // Test out some maps with pointer types %template(IntIntPtrMap) std::map; %template(IntConstIntPtrMap) std::map; #endif // Test out some maps with non-basic types and non-basic pointer types %template(IntStructMap) std::map; %template(IntStructPtrMap) std::map; %template(IntStructConstPtrMap) std::map; %template(StructPtrVector) std::vector; %template(StructPtrIntMap) std::map; // Test out a non-specialized map %template(LongIntMap) std::map; #if defined(SWIGRUBY) %template(LanguageVector) std::vector< swig::LANGUAGE_OBJ >; %inline { std::vector< swig::LANGUAGE_OBJ > LanguageVector; } #endif