From: Stephane R. <ste...@rw...> - 2007-06-04 16:21:21
|
Hello, I'm trying to make some polymorphic code (C++ code returning a pointer to a base object in a factory ) I found http://thread.gmane.org/gmane.comp.programming.swig/3659 from 2004 on the archives. Is there any new feature of SWIG I can use ? At the moment, I'm planning to do something like in C++ (psuedocode): enum ShapeType { st_Invalid, st_Box, st_Sphere } class Shape { ShapeType GetShapeType(); }; class Box : public Shape { } class Sphere : public Shape { Sphere(Shape* shp) { if ( !shp->iskindof(Sphere) ) type = st_Invalid; else { type = st_Sphere; Sphere* s = (Sphere*)shp; this->_radius = s->_radius; } } } Shape* CreateShape(const std::string& name); in C# (pseudocode): Shape shp = CreateShape("sphere"); if ( shp.GetShapeType() == ShapeType.st_Sphere) { shp = new Sphere(shp); } any other idea ? Thanks , Stephane Routelous http://www.exotk.org |