PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/director_abstract.i

#
Swig | 200 lines | 133 code | 58 blank | 9 comment | 0 complexity | db8e8c2d335923d1a133b58102311277 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module(directors="1") director_abstract
  2. %{
  3. #include <string>
  4. class Foo {
  5. public:
  6. virtual ~Foo() {}
  7. virtual std::string ping() = 0;
  8. virtual std::string pong() { return "Foo::pong();" + ping(); }
  9. };
  10. %}
  11. %include <std_string.i>
  12. %feature("director") Foo;
  13. class Foo {
  14. public:
  15. virtual ~Foo() {}
  16. virtual std::string ping() = 0;
  17. virtual std::string pong() { return "Foo::pong();" + ping(); }
  18. };
  19. %feature("director");
  20. %inline %{
  21. class Example0
  22. {
  23. protected:
  24. int xsize, ysize;
  25. public:
  26. Example0(int x, int y)
  27. : xsize(x), ysize(y) { }
  28. Example0() { }
  29. public:
  30. virtual ~Example0() {}
  31. int GetXSize() const { return xsize; }
  32. // pure virtual methods that must be overridden
  33. virtual int Color(unsigned char r, unsigned char g, unsigned char b)
  34. {
  35. return 0;
  36. }
  37. static int get_color(Example0 *ptr, unsigned char r,
  38. unsigned char g, unsigned char b) {
  39. return ptr->Color(r, g, b);
  40. }
  41. };
  42. class Example1
  43. {
  44. protected:
  45. int xsize, ysize;
  46. protected:
  47. /* this shouldn't be emitted, unless 'dirprot' is used, since they
  48. is already a public constructor */
  49. Example1(int x, int y)
  50. : xsize(x), ysize(y) { }
  51. public:
  52. Example1() { }
  53. public:
  54. virtual ~Example1() {}
  55. int GetXSize() const { return xsize; }
  56. // pure virtual methods that must be overridden
  57. virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
  58. static int get_color(Example1 *ptr, unsigned char r,
  59. unsigned char g, unsigned char b) {
  60. return ptr->Color(r, g, b);
  61. }
  62. };
  63. class Example2
  64. {
  65. protected:
  66. int xsize, ysize;
  67. protected:
  68. /* there is no default constructor, hence, all protected constructors
  69. should be emitted */
  70. Example2(int x)
  71. {
  72. }
  73. Example2(int x, int y)
  74. : xsize(x), ysize(y) { }
  75. public:
  76. virtual ~Example2() {}
  77. int GetXSize() const { return xsize; }
  78. // pure virtual methods that must be overridden
  79. virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
  80. static int get_color(Example2 *ptr, unsigned char r,
  81. unsigned char g, unsigned char b) {
  82. return ptr->Color(r, g, b);
  83. }
  84. };
  85. class Example4
  86. {
  87. protected:
  88. int xsize, ysize;
  89. protected:
  90. Example4()
  91. {
  92. }
  93. /* this is not emitted, unless dirprot is used */
  94. Example4(int x, int y)
  95. : xsize(x), ysize(y) { }
  96. public:
  97. virtual ~Example4() {}
  98. int GetXSize() const { return xsize; }
  99. // pure virtual methods that must be overridden
  100. virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
  101. static int get_color(Example4 *ptr, unsigned char r,
  102. unsigned char g, unsigned char b) {
  103. return ptr->Color(r, g, b);
  104. }
  105. };
  106. namespace ns
  107. {
  108. template <class T>
  109. class Example3
  110. {
  111. protected:
  112. /* the default constructor is always emitter, even when protected,
  113. having another public constructor, and 'dirprot' is not used.
  114. This is just for Java compatibility */
  115. Example3()
  116. {
  117. }
  118. /* this is no emitted, unless dirprot mode is used */
  119. Example3(int x) { }
  120. public:
  121. Example3(int x, int y) { }
  122. virtual ~Example3() {}
  123. // pure virtual methods that must be overridden
  124. virtual int Color(unsigned char r, unsigned char g, unsigned char b) = 0;
  125. static int get_color(Example3 *ptr, unsigned char r,
  126. unsigned char g, unsigned char b) {
  127. return ptr->Color(r, g, b);
  128. }
  129. };
  130. }
  131. %}
  132. %template(Example3_i) ns::Example3<int>;
  133. %inline %{
  134. struct A{
  135. virtual ~A() {}
  136. friend int g(A* obj);
  137. protected:
  138. A(const A&){}
  139. virtual int f() = 0;
  140. };
  141. int g(A* obj) {return 1;}
  142. %}