PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 84 lines | 67 code | 16 blank | 1 comment | 0 complexity | 6c0b478f4a5aa0d3e05aa1f651dbafdb MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* Tests the use of %template with namespaces */
  2. %module namespace_template
  3. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<int>; /* Ruby, wrong class name */
  4. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) test2::vector<short>; /* Ruby, wrong class name */
  5. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) test3::vector<long>; /* Ruby, wrong class name */
  6. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<test4::Integer>; /* Ruby, wrong class name */
  7. %{
  8. #ifdef max
  9. #undef max
  10. #endif
  11. %}
  12. %{
  13. namespace test {
  14. template<typename T> T max(T a, T b) { return (a > b) ? a : b; }
  15. template<typename T> class vector {
  16. public:
  17. vector() { }
  18. ~vector() { }
  19. char * blah(T x) {
  20. return (char *) "vector::blah";
  21. }
  22. };
  23. }
  24. namespace test2 {
  25. using namespace test;
  26. }
  27. namespace test3 {
  28. using test::max;
  29. using test::vector;
  30. }
  31. using namespace test2;
  32. namespace T4 = test;
  33. %}
  34. namespace test {
  35. template<typename T> T max(T a, T b) { return (a > b) ? a : b; }
  36. template<typename T> class vector {
  37. public:
  38. vector() { }
  39. ~vector() { }
  40. char * blah(T x) {
  41. return (char *) "vector::blah";
  42. }
  43. };
  44. }
  45. using namespace test;
  46. %template(maxint) max<int>;
  47. %template(vectorint) vector<int>;
  48. namespace test2 {
  49. using namespace test;
  50. %template(maxshort) max<short>;
  51. %template(vectorshort) vector<short>;
  52. }
  53. namespace test3 {
  54. using test::max;
  55. using test::vector;
  56. %template(maxlong) max<long>;
  57. %template(vectorlong) vector<long>;
  58. }
  59. %inline %{
  60. namespace test4 {
  61. using namespace test;
  62. typedef int Integer;
  63. }
  64. %}
  65. namespace test4 {
  66. %template(maxInteger) max<Integer>;
  67. %template(vectorInteger) vector<Integer>;
  68. }