%module refcount %warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ,SWIGWARN_LANG_IDENTIFIER); %{ #include #include "refcount.h" %} // // using the %refobject/%unrefobject directives you can active the // ref. counting for RCObj and all its descendents at once // %refobject RCObj "$this->addref();" %unrefobject RCObj "$this->delref();" %include "refcount.h" %newobject B::create(A* a); %newobject B::cloner(); %inline %{ struct A : RCObj { A() {} ~A() { // std::cout << "deleting a" << std::endl; } #ifdef SWIGRUBY // fix strange ruby + virtual derivation problem using RCObjBase::ref_count; #endif }; struct A1 : A { protected: A1() {} }; struct A2 : A { }; struct A3 : A1, private A2 { }; %} #ifdef SWIGPYTHON %extend_smart_pointer(RCPtr); %template(RCPtr_A) RCPtr; #endif %inline %{ struct B : RCObj { B(A* a) : _a(a) {} A* get_a() { return _a; } static B* create(A* a) { return new B(a); } B* cloner() { return new B(_a); } ~B() { // std::cout << "deleting b" << std::endl; } RCPtr get_rca() { return _a; } private: RCPtr _a; }; %} #ifdef SWIGPYTHON %include %template(vector_A) std::vector >; #endif