octuserdir.swg 1.8 KB

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