mirror of https://github.com/swig/swig
Add test case for very simple director classes
Test both abstract and concrete base classes, with simple int/bool data. This level of complexity is very helpful when setting up director functionality for a new target language.
This commit is contained in:
parent
266766d7c7
commit
77cdba81ad
|
@ -214,6 +214,7 @@ CPP_TEST_CASES += \
|
||||||
director_protected_overloaded \
|
director_protected_overloaded \
|
||||||
director_redefined \
|
director_redefined \
|
||||||
director_ref \
|
director_ref \
|
||||||
|
director_simple \
|
||||||
director_smartptr \
|
director_smartptr \
|
||||||
director_thread \
|
director_thread \
|
||||||
director_unroll \
|
director_unroll \
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
%module(directors="1") director_simple
|
||||||
|
|
||||||
|
%feature("director") IntBase;
|
||||||
|
%feature("director") BoolBase;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
class IntBase {
|
||||||
|
public:
|
||||||
|
virtual ~IntBase() {}
|
||||||
|
IntBase(int i = 3) { (void)i; }
|
||||||
|
virtual int apply(int x) const { return x * 2; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class IntDerived : public IntBase {
|
||||||
|
public:
|
||||||
|
virtual int apply(int x) const { return x * 3; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int apply(const IntBase& b, int x)
|
||||||
|
{
|
||||||
|
return b.apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
class BoolBase {
|
||||||
|
public:
|
||||||
|
virtual ~BoolBase() {}
|
||||||
|
BoolBase() {}
|
||||||
|
virtual bool apply(bool a, bool b) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BoolDerived : public BoolBase {
|
||||||
|
public:
|
||||||
|
virtual bool apply(bool a, bool b) const { return a != b; }
|
||||||
|
};
|
||||||
|
|
||||||
|
bool apply(const BoolBase& base, bool a, bool b)
|
||||||
|
{
|
||||||
|
return base.apply(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
Loading…
Reference in New Issue