import source from 1.3.40
[external/swig.git] / Examples / test-suite / operator_overload_break.i
1 %module operator_overload_break
2
3 #if defined(SWIGPYTHON)
4 %warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS);
5 #endif
6
7 #if !defined(SWIGLUA) && !defined(SWIGR) && !defined(SWIGPERL)
8 %rename(Plus) operator +;
9 %rename(Minus) operator -;
10 %rename(EqualEqual) operator ==;
11 %rename(PlusPlusPrefix) operator++();
12 %rename(PlusPlusPostfix) operator++(int);
13 #endif
14
15 %{
16 #include <iostream>
17 using namespace std;
18 %}
19
20 %inline %{
21
22 class Op
23 {
24 public:
25     Op(int n) {k = n;}
26     Op(const Op& other) {
27       std::cerr << "COPY: "<< other.k << std::endl;
28       k = other.k;
29     }
30
31     bool operator==(const Op& rhs) {
32        std::cerr << "Op: " << k << std::endl;
33        std::cerr << "obj: " << rhs.k << std::endl;
34        return (k == rhs.k);
35     }
36     bool operator==(int i) {
37        std::cerr << "Op: " << k << std::endl;
38        std::cerr << "other: " << i << std::endl;
39        return (k == i);
40     }
41
42     Op operator+(const Op& rhs) {return Op(k + rhs.k);}
43     Op operator+(int rhs) {return Op(k + rhs);}
44
45     Op operator-(const Op& rhs) {return Op(k - rhs.k);}
46     Op operator-(int rhs) {
47       std::cerr << "sub: " << rhs << std::endl;
48       return Op(k - rhs);
49     }
50
51     Op __rsub__(int lhs) {
52       std::cerr << "sub: " << lhs << std::endl;
53       return Op(lhs - k);
54     }
55
56     Op& operator++() {k++; return *this;}
57
58     void PrintK() {std::cerr << k << std::endl;}
59
60     int k;
61 };
62
63 %}