import source from 1.3.40
[external/swig.git] / Examples / test-suite / rename4.i
1 // Test %rename directive with the 'using' keyword and within the class definition
2 %module rename4
3
4 %{
5 #include "rename.h"
6 %}
7
8 namespace Space {
9 struct Klass {
10   Klass(int i) {}
11   Klass() {}
12 };
13 }
14
15 namespace AnotherSpace {
16   class Another {};
17 }
18
19 namespace Space {
20   %rename(opAnother1) XYZ::operator Another() const;
21   %rename(opAnother2) XYZ<int>::operator Another() const;
22   %rename(opAnother3) XYZ<Space::Klass>::operator Another() const;
23   %rename(opAnother4) XYZ<Space::Enu>::operator Another() const;
24 }
25
26 // Test %rename - no namespace, but specific templated type in the parameter, is used over the generic type T
27 %rename(tMethod2) templateT(int i);
28 %rename(tMethodNotXYZ2) templateNotXYZ(NotXYZ<int>);
29 %rename(tMethodXYZ2) templateXYZ(XYZ<int>);
30 %rename(opT2) operator int();
31 %rename(opNotXYZ2) operator NotXYZ<int>() const;
32 %rename(opXYZ2) operator XYZ<int>() const;
33
34 %rename(tMethod3) templateT(Space::Klass i);
35 %rename(tMethodNotXYZ3) templateNotXYZ(NotXYZ<Space::Klass>);
36 %rename(tMethodXYZ3) templateXYZ(XYZ<Space::Klass>);
37 %rename(opT3) operator Space::Klass();
38 %rename(opNotXYZ3) operator NotXYZ<Space::Klass>() const;
39 %rename(opXYZ3) operator XYZ<Space::Klass>() const;
40
41 %rename(tMethod4) templateT(Space::Enu i);
42 %rename(tMethodNotXYZ4) templateNotXYZ(NotXYZ<Space::Enu>);
43 %rename(tMethodXYZ4) templateXYZ(XYZ<Space::Enu>);
44 %rename(opT4) operator Space::Enu();
45 %rename(opNotXYZ4) operator NotXYZ<Space::Enu>() const;
46 %rename(opXYZ4) operator XYZ<Space::Enu>() const;
47
48 namespace Space {
49   using namespace AnotherSpace;
50   enum Enu { En1, En2, En3 };
51   template<typename T> struct NotXYZ {};
52   template<typename T> class XYZ {
53
54     // Test %rename within the class
55     %rename(opIntPtrA) operator NotXYZ<int>*() const;
56     %rename(opIntPtrB) operator XYZ<int>*() const;
57
58     %rename(tMethod1) templateT(T i);
59     %rename(tMethodNotXYZ1) templateNotXYZ(NotXYZ<T>);
60     %rename(tMethodXYZ1) templateXYZ(XYZ<T>);
61     %rename(opT1) operator T();
62     %rename(opNotXYZ1) operator NotXYZ<T>() const;
63     %rename(opXYZ1) operator XYZ<T>() const;
64
65     NotXYZ<int> *m_int;
66     T m_t;
67     NotXYZ<T> m_notxyz;
68   public:
69     operator NotXYZ<int>*() const { return m_int; }
70     operator XYZ<int>*() const { return 0; }
71     operator Another() const { Another an; return an; }
72     void templateT(T i) {}
73     void templateNotXYZ(NotXYZ<T> i) {}
74     void templateXYZ(XYZ<T> i) {}
75     operator T() { return m_t; }
76     operator NotXYZ<T>() const { return m_notxyz; }
77     operator XYZ<T>() const { XYZ<T> xyz; return xyz; }
78   };
79 }
80
81 namespace Space {
82 // non-templated class using itself in method and operator
83 class ABC {
84   public:
85
86     %rename(methodABC) method(ABC a) const;
87     %rename(opABC) operator ABC() const;
88     %rename(methodKlass) method(Klass k) const;
89     %rename(opKlass) operator Klass() const;
90
91     void method(ABC a) const {}
92     void method(Klass k) const {}
93     operator ABC() const { ABC a; return a; }
94     operator Klass() const { Klass k; return k; }
95 };
96 }
97
98
99 %template(XYZInt) Space::XYZ<int>;
100 %template(XYZDouble) Space::XYZ<double>;
101 %template(XYZKlass) Space::XYZ<Space::Klass>;
102 %template(XYZEnu) Space::XYZ<Space::Enu>;
103
104 %template(NotXYZInt) Space::NotXYZ<int>;
105 %template(NotXYZDouble) Space::NotXYZ<double>;
106 %template(NotXYZKlass) Space::NotXYZ<Space::Klass>;
107 %template(NotXYZEnu) Space::NotXYZ<Space::Enu>;
108