From: Sören F. <fr...@ir...> - 2009-11-26 18:54:01
|
Hello again (sorry about last confusing email) I have big problems with shared pointers. My goal is to add some shared pointers of a derived class to a vector that contains shared pointers to the base class. But it won't work right now. Any ideas (swig version 1.3.40)? Here a dummy code (a.cxx,run. rb, and a.i) ########################################################## #### some simle cxx-code ### class Base{ public: Base() {} }; typedef boost::shared_ptr<Base> BasePtr; class Derived : public Base{ public: Derived() {} }; typedef boost::shared_ptr<Derived> >DerivedPtr; ########################################################## #### ruby script ### my ruby script: vec = VectorBasePtr.new vec << Derived.new() ########################################################## #### swig interface (first try) ### swig interface: namespace boost{ template<class T> class shared_ptr{ public: shared_ptr(); shared_ptr(T* p ); }; } %template(BasePtr) boost::shared_ptr<Base>; %template(DerivedPtr) boost::shared_ptr<Derived>; %template(VectorBasePtr) std::vector< boost::shared_ptr<Base> >; ==> ruby script failes because missing information, that I'm using shared pointers and DerivedPtr can be casted to BasePtr ########################################################## #### swig interface (second try) ### %SWIG_SHARED_PTR(BasePtr , Base); %SWIG_SHARED_PTR_DERIVED(DerivedPtr, Base, Derived); %template(VectorBasePtr) std::vector< boost::shared_ptr<Base> >; ==> BasePtr and DerivedPtr are unknown types in ruby Q: How can this simple example be realized in ruby using swig? Is it possible? Aren't the SWIG_SHARED_PTR macros supported by the ruby parser? Best, SirAnn |