add the factory library for UTL
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8865 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6c41e29d12
commit
44264e5544
8 changed files with 128 additions and 0 deletions
37
Examples/test-suite/li_factory.i
Normal file
37
Examples/test-suite/li_factory.i
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
%module li_factory
|
||||
%include factory.i
|
||||
|
||||
%newobject Geometry::create;
|
||||
%factory(Geometry *Geometry::create, Point, Circle);
|
||||
|
||||
%inline {
|
||||
struct Geometry {
|
||||
enum GeomType{
|
||||
POINT,
|
||||
CIRCLE
|
||||
};
|
||||
|
||||
virtual ~Geometry() {}
|
||||
virtual int draw() = 0;
|
||||
static Geometry *create(GeomType i);
|
||||
};
|
||||
|
||||
struct Point : Geometry {
|
||||
int draw() { return 1; }
|
||||
double width() { return 1.0; }
|
||||
};
|
||||
|
||||
struct Circle : Geometry {
|
||||
int draw() { return 2; }
|
||||
double radius() { return 1.5; }
|
||||
};
|
||||
|
||||
Geometry *Geometry::create(GeomType type) {
|
||||
switch (type) {
|
||||
case POINT: return new Point();
|
||||
case CIRCLE: return new Circle();
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +31,7 @@ CPP_TEST_CASES += \
|
|||
kwargs \
|
||||
li_cstring \
|
||||
li_cwstring \
|
||||
li_factory \
|
||||
li_implicit \
|
||||
li_std_vectora \
|
||||
li_std_map \
|
||||
|
|
|
|||
11
Examples/test-suite/python/li_factory_runme.py
Normal file
11
Examples/test-suite/python/li_factory_runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from li_factory import *
|
||||
|
||||
circle = Geometry.create(Geometry.CIRCLE)
|
||||
r = circle.radius()
|
||||
if (r != 1.5):
|
||||
raise RuntimeError
|
||||
|
||||
point = Geometry.create(Geometry.POINT)
|
||||
w = point.width()
|
||||
if (w != 1.0):
|
||||
raise RuntimeError
|
||||
Loading…
Add table
Add a link
Reference in a new issue