PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/Examples/test-suite/refcount.i

#
Swig | 123 lines | 92 code | 31 blank | 0 comment | 0 complexity | f6b1cfe9b08e82c6e27bcc044bbbcaf5 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module refcount
  2. %warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ,SWIGWARN_LANG_IDENTIFIER);
  3. %{
  4. #include <iostream>
  5. #include "refcount.h"
  6. %}
  7. //
  8. // using the %refobject/%unrefobject directives you can activate the
  9. // reference counting for RCObj and all its descendents at once
  10. //
  11. %refobject RCObj "$this->addref();"
  12. %unrefobject RCObj "$this->delref();"
  13. %include "refcount.h"
  14. %newobject B::create(A* a);
  15. %newobject global_create(A* a);
  16. %newobject B::cloner();
  17. %newobject Factory::create(A* a);
  18. %newobject Factory::create2(A* a);
  19. %inline %{
  20. struct A : RCObj
  21. {
  22. A() {}
  23. ~A()
  24. {
  25. // std::cout << "deleting a" << std::endl;
  26. }
  27. #ifdef SWIGRUBY
  28. // fix strange ruby + virtual derivation problem
  29. using RCObjBase::ref_count;
  30. #endif
  31. };
  32. struct A1 : A
  33. {
  34. protected:
  35. A1() {}
  36. };
  37. struct A2 : A
  38. {
  39. };
  40. struct A3 : A1, private A2
  41. {
  42. };
  43. %}
  44. #if defined(SWIGPYTHON)
  45. %extend_smart_pointer(RCPtr<A>);
  46. %template(RCPtr_A) RCPtr<A>;
  47. #endif
  48. %inline %{
  49. struct B : RCObj
  50. {
  51. B(A* a) : _a(a) {}
  52. A* get_a()
  53. {
  54. return _a;
  55. }
  56. static B* create(A* a)
  57. {
  58. return new B(a);
  59. }
  60. B* cloner()
  61. {
  62. return new B(_a);
  63. }
  64. ~B()
  65. {
  66. // std::cout << "deleting b" << std::endl;
  67. }
  68. RCPtr<A> get_rca() {
  69. return _a;
  70. }
  71. private:
  72. RCPtr<A> _a;
  73. };
  74. class B* global_create(A* a)
  75. {
  76. return new B(a);
  77. }
  78. struct Factory {
  79. static B* create(A* a)
  80. {
  81. return new B(a);
  82. }
  83. B* create2(A* a)
  84. {
  85. return new B(a);
  86. }
  87. };
  88. %}
  89. #if defined(SWIGPYTHON) || defined(SWIGOCTAVE)
  90. %include <std_vector.i>
  91. %template(vector_A) std::vector<RCPtr<A> >;
  92. #endif