1 %module extend_template_method 2 3 %include <std_string.i> 4 5 %inline %{ 6 namespace Space { 7 class ExtendMe { 8 public: ExtendMe()9 ExtendMe() {} 10 template <typename T> do_stuff_impl(int a,T b,double d)11 T do_stuff_impl(int a, T b, double d) { 12 return b; 13 } 14 }; 15 } 16 %} 17 18 %extend Space::ExtendMe { 19 template<typename T> do_stuff(int a,T b)20 T do_stuff(int a, T b) { 21 return $self->do_stuff_impl(a, b, 4.0); 22 } 23 template<typename T> do_overloaded_stuff(T b)24 T do_overloaded_stuff(T b) { 25 return $self->do_stuff_impl(0, b, 4.0); 26 } 27 template<typename T> static_method(T t)28 static T static_method(T t) { 29 return t; 30 } 31 template<typename T> ExtendMe(T x)32 ExtendMe(T x) { 33 Space::ExtendMe *em = new Space::ExtendMe(); 34 return em; 35 } 36 } 37 %template(do_stuff_double) Space::ExtendMe::do_stuff<double>; 38 %template(do_stuff_string) Space::ExtendMe::do_stuff<std::string>; 39 40 %template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff<std::string>; 41 %template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff<double>; 42 43 %template(static_method) Space::ExtendMe::static_method<int>; 44 45 %template(ExtendMe) Space::ExtendMe::ExtendMe<int>; 46 47 %inline %{ 48 namespace Space { 49 template<typename X> 50 class TemplateExtendMe { 51 public: TemplateExtendMe()52 TemplateExtendMe() {} 53 template <typename T> template_stuff_impl(X a,T b,double d)54 T template_stuff_impl(X a, T b, double d) { 55 return b; 56 } 57 }; 58 } 59 %} 60 61 %extend Space::TemplateExtendMe { 62 template<typename T> do_template_stuff(int a,T b)63 T do_template_stuff(int a, T b) { 64 return $self->template_stuff_impl(a, b, 4.0); 65 } 66 template<typename T> do_template_overloaded_stuff(T b)67 T do_template_overloaded_stuff(T b) { 68 return $self->template_stuff_impl(0, b, 4.0); 69 } 70 template<typename T> static_template_method(T t)71 static T static_template_method(T t) { 72 return t; 73 } 74 template<typename T> TemplateExtendMe(T x)75 TemplateExtendMe(T x) { 76 Space::TemplateExtendMe<X> *em = new Space::TemplateExtendMe<X>(); 77 return em; 78 } 79 80 %template(do_template_stuff_double) do_template_stuff<double>; 81 %template(do_template_stuff_string) do_template_stuff<std::string>; 82 83 %template(do_template_overloaded_stuff) do_template_overloaded_stuff<std::string>; 84 %template(do_template_overloaded_stuff) do_template_overloaded_stuff<double>; 85 86 %template(static_template_method) static_template_method<int>; 87 88 %template(TemplateExtendMe) Space::TemplateExtendMe::TemplateExtendMe<int>; 89 } 90 91 %template(TemplateExtend) Space::TemplateExtendMe<int>; 92 93