Enhance %extend to extend a class with static template methods
This commit is contained in:
parent
83519138e8
commit
481ebfab45
4 changed files with 33 additions and 9 deletions
|
|
@ -3,6 +3,7 @@
|
|||
%include <std_string.i>
|
||||
|
||||
%inline %{
|
||||
namespace Space {
|
||||
class ExtendMe {
|
||||
public:
|
||||
template <typename T>
|
||||
|
|
@ -10,9 +11,10 @@ public:
|
|||
return b;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%extend ExtendMe {
|
||||
%extend Space::ExtendMe {
|
||||
template<typename T>
|
||||
T do_stuff(int a, T b) {
|
||||
return $self->do_stuff_impl(a, b, 4.0);
|
||||
|
|
@ -21,15 +23,19 @@ public:
|
|||
T do_overloaded_stuff(T b) {
|
||||
return $self->do_stuff_impl(0, b, 4.0);
|
||||
}
|
||||
template<typename T>
|
||||
static T static_method(T t) { return t; }
|
||||
}
|
||||
%template(do_stuff_double) ExtendMe::do_stuff<double>;
|
||||
%template(do_stuff_string) ExtendMe::do_stuff<std::string>;
|
||||
%template(do_stuff_double) Space::ExtendMe::do_stuff<double>;
|
||||
%template(do_stuff_string) Space::ExtendMe::do_stuff<std::string>;
|
||||
|
||||
%template(do_overloaded_stuff) ExtendMe::do_overloaded_stuff<std::string>;
|
||||
%template(do_overloaded_stuff) ExtendMe::do_overloaded_stuff<double>;
|
||||
%template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff<std::string>;
|
||||
%template(do_overloaded_stuff) Space::ExtendMe::do_overloaded_stuff<double>;
|
||||
|
||||
%template(static_method) Space::ExtendMe::static_method<int>;
|
||||
|
||||
%inline %{
|
||||
namespace Space {
|
||||
template<typename X>
|
||||
class TemplateExtendMe {
|
||||
public:
|
||||
|
|
@ -38,9 +44,10 @@ public:
|
|||
return b;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%extend TemplateExtendMe {
|
||||
%extend Space::TemplateExtendMe {
|
||||
template<typename T>
|
||||
T do_template_stuff(int a, T b) {
|
||||
return $self->template_stuff_impl(a, b, 4.0);
|
||||
|
|
@ -49,6 +56,8 @@ public:
|
|||
T do_template_overloaded_stuff(T b) {
|
||||
return $self->template_stuff_impl(0, b, 4.0);
|
||||
}
|
||||
template<typename T>
|
||||
static T static_template_method(T t) { return t; }
|
||||
|
||||
%template(do_template_stuff_double) do_template_stuff<double>;
|
||||
%template(do_template_stuff_string) do_template_stuff<std::string>;
|
||||
|
|
@ -56,7 +65,8 @@ public:
|
|||
%template(do_template_overloaded_stuff) do_template_overloaded_stuff<std::string>;
|
||||
%template(do_template_overloaded_stuff) do_template_overloaded_stuff<double>;
|
||||
|
||||
%template(static_template_method) static_template_method<int>;
|
||||
}
|
||||
|
||||
%template(TemplateExtend) TemplateExtendMe<int>;
|
||||
%template(TemplateExtend) Space::TemplateExtendMe<int>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue