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>;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public class extend_template_method_runme {
|
|||
if (!ret_string.equals("hello there"))
|
||||
throw new RuntimeException("string failed " + ret_string);
|
||||
}
|
||||
if (ExtendMe.static_method(123) != 123)
|
||||
throw new RuntimeException("static_method failed");
|
||||
}
|
||||
{
|
||||
TemplateExtend em = new TemplateExtend();
|
||||
|
|
@ -52,6 +54,8 @@ public class extend_template_method_runme {
|
|||
if (!ret_string.equals("hello there"))
|
||||
throw new RuntimeException("string failed " + ret_string);
|
||||
}
|
||||
if (TemplateExtend.static_template_method(123) != 123)
|
||||
throw new RuntimeException("static_template_method failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ ret_string = em.do_overloaded_stuff("hello there")
|
|||
if ret_string != "hello there":
|
||||
raise RuntimeError("string failed " + ret_string)
|
||||
|
||||
if ExtendMe.static_method(123) != 123:
|
||||
raise RuntimeError("static_method failed");
|
||||
|
||||
em = TemplateExtend()
|
||||
|
||||
|
|
@ -34,3 +36,6 @@ if ret_double != 1.1:
|
|||
ret_string = em.do_template_overloaded_stuff("hello there")
|
||||
if ret_string != "hello there":
|
||||
raise RuntimeError("string failed " + ret_string)
|
||||
|
||||
if TemplateExtend.static_template_method(123) != 123:
|
||||
raise RuntimeError("static_template_method failed");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue