~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/test-suite/python/li_std_pair.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-09-01 18:35:55 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050901183555-eq59uwhq8b62e44c
Tags: 1.3.24-1ubuntu4
* Use php5-dev instead of php4-dev, to kick php4 out of main.
* Drop support for generation of pike bindings, as nothing uses it,
  and swig is the only thing keeping pike7.6 in main (Ubuntu #13796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%module li_std_pair
 
2
 
 
3
//
 
4
// activate the automatic comparison methods generation (==,!=,...) 
 
5
//
 
6
 
 
7
%{
 
8
#include <algorithm>                   // for std::swap
 
9
%}
 
10
 
 
11
 
 
12
%include std_pair.i
 
13
%include std_string.i
 
14
%include std_complex.i
 
15
 
 
16
%inline
 
17
%{
 
18
  struct A 
 
19
  {
 
20
    int val;
 
21
    
 
22
    A(int v = 0): val(v)
 
23
    {
 
24
    }
 
25
    
 
26
  };
 
27
  struct B
 
28
  {
 
29
  };
 
30
%}
 
31
 
 
32
%std_comp_methods(std::pair<std::string, int>);
 
33
 
 
34
namespace std {
 
35
  %template(CIntPair) pair<const int, const int>;
 
36
  %template() pair<double, double>;
 
37
  %template(IntPair) pair<int, int>;
 
38
  %template(SIPair) pair<std::string, int>;
 
39
  %template(CIPair) pair<std::complex<double>, int>;
 
40
  %template(SIIPair) pair<std::pair<std::string, int>, int>;
 
41
  %template(AIntPair) pair<A, int>;
 
42
 
 
43
  %template(CCIntPair) pair<const A, const pair<int, int> >;
 
44
 
 
45
  %template(ABPair) pair<A, B>;
 
46
  %template(IntAPair) pair<int, A>;
 
47
 
 
48
  %template(pairP1) pair<int, A*>;
 
49
  %template(pairP2) pair<A*, int>;
 
50
  %template(pairP3) pair<A*, A*>;
 
51
  %template(pairP4) pair<int, int*>;
 
52
  %template(pairP5) pair<int*, int>;
 
53
  %template(pairP6) pair<int*, int*>;
 
54
  
 
55
}
 
56
%std_comp_methods(std::pair<std::pair<std::string, int>, int>);
 
57
 
 
58
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
 
59
 
 
60
%inline %{
 
61
 
 
62
/* Test the "out" typemap for pair<T, U> */
 
63
std::pair<int, int> makeIntPair(int a, int b) {
 
64
    return std::make_pair(a, b);
 
65
}
 
66
 
 
67
/**
 
68
 * There is no "out" typemap for a pointer to a pair, so
 
69
 * this should return a wrapped instance of a std::pair
 
70
 * instead of the native "array" type for the target language.
 
71
 */
 
72
std::pair<int, int> * makeIntPairPtr(int a, int b) {
 
73
    static std::pair<int, int> p = std::make_pair(a, b);
 
74
    return &p;
 
75
}
 
76
 
 
77
/**
 
78
 * There is no "out" typemap for a non-const reference to a pair, so
 
79
 * this should return a wrapped instance of a std::pair instead of
 
80
 * the native "array" type for the target language.
 
81
 */
 
82
std::pair<int, int>& makeIntPairRef(int a, int b) {
 
83
    static std::pair<int, int> p = std::make_pair(a, b);
 
84
    return p;
 
85
}
 
86
 
 
87
/**
 
88
 * There is no "out" typemap for a const reference to a pair, so
 
89
 * this should return a wrapped instance of a std::pair
 
90
 * instead of the native "array" type for the target language.
 
91
 */
 
92
const std::pair<int, int> & makeIntPairConstRef(int a, int b) {
 
93
    static std::pair<int, int> p = std::make_pair(a, b);
 
94
    return p;
 
95
}
 
96
 
 
97
/* Test the "in" typemap for pair<T, U> */
 
98
int product1(std::pair<int, int> p) {
 
99
    return p.first*p.second;
 
100
}
 
101
 
 
102
/* Test the "in" typemap for const pair<T, U>& */
 
103
int product2(const std::pair<int, int>& p) {
 
104
    return p.first*p.second;
 
105
}
 
106
 
 
107
std::pair<int, int> 
 
108
  p_ident(std::pair<int, int> p, const std::pair<int, int>& q) {
 
109
  return p;
 
110
}
 
111
 
 
112
 
 
113
std::pair<int, A*> 
 
114
p_identa(const std::pair<int, A*>& p) {
 
115
  return p;
 
116
}
 
117
 
 
118
void
 
119
d_inout(double *INOUT) {
 
120
  *INOUT += *INOUT;
 
121
}
 
122
 
 
123
void
 
124
d_inout(int *INOUT) {
 
125
  *INOUT += *INOUT;
 
126
}
 
127
 
 
128
int
 
129
d_inout2(double *INOUT) {
 
130
  *INOUT += *INOUT;
 
131
  return 1;
 
132
}
 
133
 
 
134
void
 
135
p_inout(std::pair<int, int> *INOUT) {
 
136
  std::swap(INOUT->first, INOUT->second);
 
137
}
 
138
 
 
139
int
 
140
p_inout2(std::pair<int, int> *INOUT) {
 
141
  std::swap(INOUT->first, INOUT->second);
 
142
  return 1;
 
143
}
 
144
 
 
145
void
 
146
  p_inout3(std::pair<int,int> *INOUT, std::pair<int,int> *INOUT2) {
 
147
  std::swap(*INOUT, *INOUT2);
 
148
 
149
 
 
150
void
 
151
p_inoutd(std::pair<double, double> *INOUT) {
 
152
  std::swap(INOUT->first, INOUT->second);
 
153
}
 
154
 
 
155
std::string
 
156
  s_ident(const std::string& s) {
 
157
  return s;
 
158
}
 
159
 
 
160
#if 0
 
161
std::pair<char, char> 
 
162
  p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
 
163
  return p;
 
164
}
 
165
 
 
166
/* Test the "in" typemap for const pair<T, U>* */
 
167
std::pair<A, B> 
 
168
  p_ident(std::pair<A, B> p, const std::pair<A, B>& q) {
 
169
  return q;
 
170
}
 
171
 
 
172
/* Test the "in" typemap for const pair<T, U>* */
 
173
std::pair<int, A> 
 
174
  p_ident(std::pair<int, A> p, const std::pair<int, A>& q) {
 
175
  return p;
 
176
}
 
177
 
 
178
 
 
179
std::pair<int, int> 
 
180
  p_ident(std::pair<int, int> p, const std::pair<A, int>& q) {
 
181
  return p;
 
182
}
 
183
 
 
184
std::pair<int, int> 
 
185
  p_ident(std::pair<int, int> p, const std::pair<A, B>& q) {
 
186
  return p;
 
187
}
 
188
 
 
189
 
 
190
 
 
191
#endif
 
192
%}
 
193
 
 
194
 
 
195
namespace std
 
196
{
 
197
  %template(paircA1) pair<const int, A*>;
 
198
  %template(paircA2) pair<const int, const A*>;
 
199
  %template(pairiiA) pair<int,pair<int, A*> >;
 
200
}
 
201