fix director + abstract + constructors, reported by Brian Kelley
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6478 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f7ae968d6b
commit
df9fa977a8
9 changed files with 258 additions and 38 deletions
|
|
@ -1,4 +1,4 @@
|
|||
%module(directors="1") director_abstract
|
||||
%module(directors="1",dirprot="1") director_abstract
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
|
|
@ -17,36 +17,122 @@ public:
|
|||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() = 0;
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
virtual ~Foo() {}
|
||||
virtual std::string ping() = 0;
|
||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
%feature("director") Example1;
|
||||
%feature("director");
|
||||
|
||||
%inline %{
|
||||
class Example1
|
||||
class Example0
|
||||
{
|
||||
private:
|
||||
|
||||
protected:
|
||||
int xsize, ysize;
|
||||
int fontsize;
|
||||
int fontdim[23];
|
||||
int xsize, ysize;
|
||||
|
||||
public:
|
||||
|
||||
Example0(int x, int y)
|
||||
: xsize(x), ysize(y) { }
|
||||
|
||||
Example0() { }
|
||||
|
||||
public:
|
||||
Example1()
|
||||
: xsize(200), ysize(200) { }
|
||||
virtual ~Example0() {}
|
||||
|
||||
int GetXSize() const { return xsize; }
|
||||
|
||||
// pure virtual methods that must be overridden
|
||||
virtual int Color(unsigned char r, unsigned char g, unsigned char b)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual ~Example1() {}
|
||||
|
||||
int GetXSize() const { return xsize; }
|
||||
|
||||
// pure virtual methods that must be overridden
|
||||
virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
|
||||
static int get_color(Example0 *ptr, unsigned char r,
|
||||
unsigned char g, unsigned char b) {
|
||||
return ptr->Color(r, g, b);
|
||||
}
|
||||
};
|
||||
|
||||
class Example1
|
||||
{
|
||||
protected:
|
||||
int xsize, ysize;
|
||||
|
||||
public:
|
||||
|
||||
Example1(int x, int y)
|
||||
: xsize(x), ysize(y) { }
|
||||
|
||||
Example1() { }
|
||||
|
||||
public:
|
||||
virtual ~Example1() {}
|
||||
|
||||
int GetXSize() const { return xsize; }
|
||||
|
||||
// pure virtual methods that must be overridden
|
||||
virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
|
||||
|
||||
static int get_color(Example1 *ptr, unsigned char r,
|
||||
unsigned char g, unsigned char b) {
|
||||
return ptr->Color(r, g, b);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Example2
|
||||
{
|
||||
protected:
|
||||
int xsize, ysize;
|
||||
|
||||
protected:
|
||||
Example2(int x, int y)
|
||||
: xsize(x), ysize(y) { }
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Example2() {}
|
||||
|
||||
int GetXSize() const { return xsize; }
|
||||
|
||||
// pure virtual methods that must be overridden
|
||||
virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
|
||||
|
||||
static int get_color(Example2 *ptr, unsigned char r,
|
||||
unsigned char g, unsigned char b) {
|
||||
return ptr->Color(r, g, b);
|
||||
}
|
||||
};
|
||||
|
||||
namespace ns
|
||||
{
|
||||
template <class T>
|
||||
class Example3
|
||||
{
|
||||
public:
|
||||
Example3()
|
||||
{
|
||||
}
|
||||
|
||||
Example3(int x, int y) { }
|
||||
|
||||
virtual ~Example3() {}
|
||||
|
||||
// pure virtual methods that must be overridden
|
||||
virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
|
||||
|
||||
static int get_color(Example3 *ptr, unsigned char r,
|
||||
unsigned char g, unsigned char b) {
|
||||
return ptr->Color(r, g, b);
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%template(Example3_i) ns::Example3<int>;
|
||||
|
|
|
|||
|
|
@ -16,15 +16,47 @@ if a.pong() != "Foo::pong();MyFoo::ping()":
|
|||
raise RuntimeError, a.pong()
|
||||
|
||||
|
||||
class MyExample(director_abstract.Example1):
|
||||
def __init__(self):
|
||||
director_abstract.Example1.__init__(self)
|
||||
pass
|
||||
|
||||
class MyExample1(director_abstract.Example1):
|
||||
def Color(self, r, g, b):
|
||||
return r
|
||||
|
||||
me = MyExample()
|
||||
class MyExample2(director_abstract.Example2):
|
||||
def Color(self, r, g, b):
|
||||
return g
|
||||
|
||||
print me.Color(1,2,3)
|
||||
class MyExample3(director_abstract.Example3_i):
|
||||
def Color(self, r, g, b):
|
||||
return b
|
||||
|
||||
me1 = MyExample1()
|
||||
if MyExample1.get_color(me1, 1,2,3) != 1:
|
||||
raise RuntimeError
|
||||
|
||||
me2 = MyExample2(1,2)
|
||||
if MyExample2.get_color(me2, 1,2,3) != 2:
|
||||
raise RuntimeError
|
||||
|
||||
me3 = MyExample3()
|
||||
if MyExample3.get_color(me3, 1,2,3) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
error = 1
|
||||
try:
|
||||
me1 = director_abstract.Example1()
|
||||
except:
|
||||
error = 0
|
||||
if (error): raise RuntimeError
|
||||
|
||||
error = 1
|
||||
try:
|
||||
me2 = director_abstract.Example2()
|
||||
except:
|
||||
error = 0
|
||||
if (error): raise RuntimeError
|
||||
|
||||
error = 1
|
||||
try:
|
||||
me3 = director_abstract.Example3_i()
|
||||
except:
|
||||
error = 0
|
||||
if (error): raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -18,3 +18,14 @@ if a.pong != "Foo::pong();MyFoo::ping()"
|
|||
end
|
||||
|
||||
|
||||
class MyExample1 < Director_abstract::Example1
|
||||
def color(r,g,b)
|
||||
r
|
||||
end
|
||||
end
|
||||
|
||||
#m1 = MyExample1.new
|
||||
#
|
||||
#if m1.color(1,2,3) != 1
|
||||
# raise RuntimeError, m1.color
|
||||
#end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue