1 /* ------------------------------------------------------------------------- 2 * Special user directives 3 * ------------------------------------------------------------------------- */ 4 5 /* ------------------------------------------------------------------------- */ 6 /* 7 Implicit Conversion using the C++ constructor mechanism 8 */ 9 10 #define %implicitconv %feature("implicitconv") 11 #define %noimplicitconv %feature("implicitconv", "0") 12 #define %clearimplicitconv %feature("implicitconv", "") 13 14 15 /* ------------------------------------------------------------------------- */ 16 /* 17 %extend_smart_pointer extend the smart pointer support. 18 19 For example, if you have a smart pointer as: 20 21 template <class Type> class RCPtr { 22 public: 23 ... 24 RCPtr(Type *p); 25 Type * operator->() const; 26 ... 27 }; 28 29 you use the %extend_smart_pointer directive as: 30 31 %extend_smart_pointer(RCPtr<A>); 32 %template(RCPtr_A) RCPtr<A>; 33 34 then, if you have something like: 35 36 RCPtr<A> make_ptr(); 37 int foo(A *); 38 39 you can do the following: 40 41 a = make_ptr(); 42 b = foo(a); 43 44 ie, swig will accept a RCPtr<A> object where a 'A *' is 45 expected. 46 47 Also, when using vectors 48 49 %extend_smart_pointer(RCPtr<A>); 50 %template(RCPtr_A) RCPtr<A>; 51 %template(vector_A) std::vector<RCPtr<A> >; 52 53 you can type 54 55 a = A(); 56 v = vector_A(2) 57 v[0] = a 58 59 ie, an 'A *' object is accepted, via implicit conversion, 60 where a RCPtr<A> object is expected. Additionally 61 62 x = v[0] 63 64 returns (and sets 'x' as) a copy of v[0], making reference 65 counting possible and consistent. 66 */ 67 68 %define %extend_smart_pointer(Type...) 69 %implicitconv Type; 70 %apply const SWIGTYPE& SMARTPOINTER { const Type& }; 71 %apply SWIGTYPE SMARTPOINTER { Type }; 72 %enddef 73