%module li_std_pair_extra // // activate the automatic comparison methods generation (==,!=,...) // %{ #include // for std::swap %} %include std_pair.i %include std_string.i %include std_complex.i %inline %{ struct A { int val; A(int v = 0): val(v) { } }; struct B { }; %} %std_comp_methods(std::pair); namespace std { %template(CIntPair) pair; %template() pair; %template(ShortPair) pair; %template(IntPair) pair; %extend pair { %template(pair) pair; } %template(SIPair) pair; %template(CIPair) pair, int>; %template(SIIPair) pair, int>; %template(AIntPair) pair; %template(CCIntPair) pair >; %template(ABPair) pair; %template(IntAPair) pair; %template(pairP1) pair; %template(pairP2) pair; %template(pairP3) pair; %template(pairP4) pair; %template(pairP5) pair; %template(pairP6) pair; } %std_comp_methods(std::pair, int>); %apply std::pair *INOUT {std::pair *INOUT2}; %inline %{ /* Test the "out" typemap for pair */ std::pair makeIntPair(int a, int b) { return std::make_pair(a, b); } /** * There is no "out" typemap for a pointer to a pair, so * this should return a wrapped instance of a std::pair * instead of the native "array" type for the target language. */ std::pair * makeIntPairPtr(int a, int b) { static std::pair p = std::make_pair(a, b); return &p; } /** * There is no "out" typemap for a non-const reference to a pair, so * this should return a wrapped instance of a std::pair instead of * the native "array" type for the target language. */ std::pair& makeIntPairRef(int a, int b) { static std::pair p = std::make_pair(a, b); return p; } /** * There is no "out" typemap for a const reference to a pair, so * this should return a wrapped instance of a std::pair * instead of the native "array" type for the target language. */ const std::pair & makeIntPairConstRef(int a, int b) { static std::pair p = std::make_pair(a, b); return p; } /* Test the "in" typemap for pair */ int product1(std::pair p) { return p.first*p.second; } /* Test the "in" typemap for const pair& */ int product2(const std::pair& p) { return p.first*p.second; } std::pair p_ident(std::pair p, const std::pair& q) { return p; } std::pair p_identa(const std::pair& p) { return p; } void d_inout(double *INOUT) { *INOUT += *INOUT; } void d_inout(int *INOUT) { *INOUT += *INOUT; } int d_inout2(double *INOUT) { *INOUT += *INOUT; return 1; } void p_inout(std::pair *INOUT) { std::swap(INOUT->first, INOUT->second); } int p_inout2(std::pair *INOUT) { std::swap(INOUT->first, INOUT->second); return 1; } void p_inout3(std::pair *INOUT, std::pair *INOUT2) { std::swap(*INOUT, *INOUT2); } void p_inoutd(std::pair *INOUT) { std::swap(INOUT->first, INOUT->second); } std::string s_ident(const std::string& s) { return s; } #if 0 std::pair p_ident(std::pair p, const std::pair& q) { return p; } /* Test the "in" typemap for const pair* */ std::pair p_ident(std::pair p, const std::pair& q) { return q; } /* Test the "in" typemap for const pair* */ std::pair p_ident(std::pair p, const std::pair& q) { return p; } std::pair p_ident(std::pair p, const std::pair& q) { return p; } std::pair p_ident(std::pair p, const std::pair& q) { return p; } #endif %} namespace std { %template(paircA1) pair; %template(paircA2) pair; %template(pairiiA) pair >; }