PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 82 lines | 70 code | 12 blank | 0 comment | 0 complexity | 84d8a12135fd18f9b4878c197d154c70 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This test is to check the intermediary class name can be changed (C# and Java only use intermediary classes at time of writing)
  2. %module(directors="1", jniclassname="intermediary_classname", imclassname="intermediary_classname") "intermediary_classname"
  3. %warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR);
  4. // change the access to the intermediary class for testing purposes
  5. %pragma(java) jniclassclassmodifiers="public class";
  6. %pragma(csharp) imclassclassmodifiers="public class";
  7. %feature("director") Base;
  8. %feature("director") Derived;
  9. // Test the throws attribute in these typemaps
  10. %typemap(javadirectorout, throws="InstantiationException/*javadirectorout Base&*/") Base&
  11. "$javaclassname.getCPtr($javacall)/* XYZ& typemap directorout*/"
  12. %typemap(javadirectorin, throws="ClassNotFoundException/*javadirectorin Base&*/") Base&
  13. "new $javaclassname($jniinput, false)/*javadirectorin*/"
  14. %typemap(out, throws="IllegalAccessException/*out Base&*/") Base& {
  15. // XYZ& typemap out
  16. $result = 0; // remove unused variable warning
  17. }
  18. %inline %{
  19. template<class T> T maximum(const T a, const T b) { return a>b ? a : b; }
  20. template<class T> class vector {
  21. T *v;
  22. int sz;
  23. public:
  24. vector(int _sz) {
  25. v = new T[_sz];
  26. sz = _sz;
  27. }
  28. T &get(int index) {
  29. return v[index];
  30. }
  31. void set(int index, T &val) {
  32. v[index] = val;
  33. }
  34. void testconst(const T x) { }
  35. };
  36. #if defined(_MSC_VER)
  37. #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  38. #endif
  39. class Base {
  40. public:
  41. Base() : mVectInt(0) {}
  42. Base(Base *b) : mVectInt(0) {}
  43. virtual ~Base() {}
  44. virtual Base& m1(Base &b) { return b; }
  45. virtual Base& m1out() { static Base b; return b; }
  46. virtual Base* m2(Base *b) { return b; }
  47. // virtual Base m3(Base b) { return b; }
  48. vector<int> mVectInt;
  49. int mInt;
  50. enum en { en1, en2 };
  51. en enummethod(en e) { return e; }
  52. };
  53. class Derived : public Base {
  54. public:
  55. Derived(Base *b) : Base(b) {}
  56. virtual Base& m1(Base &b) { return b; }
  57. virtual Base* m2(Base *b) { return b; }
  58. // virtual Base m3(Base b) { return b; }
  59. void throwspec() throw (int, Base) {}
  60. };
  61. #if defined(_MSC_VER)
  62. #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  63. #endif
  64. %}
  65. %template(maxint) maximum<int>;
  66. %template(maxdouble) maximum<double>;
  67. %template(vecint) vector<int>;
  68. %template(vecdouble) vector<double>;
  69. %template(maxintp) maximum<int (*)[10]>;
  70. %template(vecintp) vector<int (*)[10]>;