added a reference polymorphic return type case, and
some extra test for the Java side. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5596 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
36a25d1f78
commit
b45d143ea2
3 changed files with 41 additions and 0 deletions
|
|
@ -37,5 +37,25 @@ public class virtual_poly_runme {
|
||||||
virtual_poly.incr(ic);
|
virtual_poly.incr(ic);
|
||||||
if ( (i.get() + 1) != ic.get() )
|
if ( (i.get() + 1) != ic.get() )
|
||||||
throw new RuntimeException("incr test failed");
|
throw new RuntimeException("incr test failed");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Checking a pure user downcast
|
||||||
|
//
|
||||||
|
NNumber n1 = d.copy();
|
||||||
|
NNumber n2 = d.nnumber();
|
||||||
|
NDouble dn1 = NDouble.narrow(n1);
|
||||||
|
NDouble dn2 = NDouble.narrow(n2);
|
||||||
|
|
||||||
|
if ( (dn1.get()) != dn2.get() )
|
||||||
|
throw new RuntimeException("copy/narrow test failed");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Checking the ref polymorphic case
|
||||||
|
//
|
||||||
|
NNumber nr = d.ref_this();
|
||||||
|
NDouble dr1 = NDouble.narrow(nr);
|
||||||
|
NDouble dr2 = (NDouble)d.ref_this();
|
||||||
|
if ( dr1.get() != dr2.get() )
|
||||||
|
throw new RuntimeException("copy/narrow test failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ if (i.get() + 1) != ic.get():
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
dr = d.ref_this()
|
||||||
|
if d.get() != dr.get():
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# 'narrowing' also works
|
# 'narrowing' also works
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,18 @@
|
||||||
{
|
{
|
||||||
virtual ~NNumber() {};
|
virtual ~NNumber() {};
|
||||||
virtual NNumber* copy() const = 0;
|
virtual NNumber* copy() const = 0;
|
||||||
|
virtual NNumber& ref_this()
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NNumber* nnumber()
|
NNumber* nnumber()
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -57,8 +63,14 @@
|
||||||
return new NInt(val);
|
return new NInt(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual NInt& ref_this()
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
/* See below */
|
/* See below */
|
||||||
static NInt* narrow(NNumber* nn);
|
static NInt* narrow(NNumber* nn);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int val;
|
int val;
|
||||||
|
|
@ -85,6 +97,11 @@
|
||||||
return new NDouble(val);
|
return new NDouble(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual NDouble& ref_this()
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
/* See below */
|
/* See below */
|
||||||
static NDouble* narrow(NNumber* nn);
|
static NDouble* narrow(NNumber* nn);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue