blob: 622cc679db1219cd4bbb011c2ba196d47afb9ad9 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// This file was GENERATED by command:
2// pump.py bind.h.pump
3// DO NOT EDIT BY HAND!!!
4
5/*
6 * libjingle
7 * Copyright 2012 Google Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32// To generate bind.h from bind.h.pump, execute:
33// /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump
34
35// Bind() is an overloaded function that converts method calls into function
36// objects (aka functors). It captures any arguments to the method by value
37// when Bind is called, producing a stateful, nullary function object. Care
38// should be taken about the lifetime of objects captured by Bind(); the
39// returned functor knows nothing about the lifetime of the method's object or
40// any arguments passed by pointer, and calling the functor with a destroyed
41// object will surely do bad things.
42//
43// Example usage:
44// struct Foo {
45// int Test1() { return 42; }
46// int Test2() const { return 52; }
47// int Test3(int x) { return x*x; }
48// float Test4(int x, float y) { return x + y; }
49// };
50//
51// int main() {
52// Foo foo;
53// cout << talk_base::Bind(&Foo::Test1, &foo)() << endl;
54// cout << talk_base::Bind(&Foo::Test2, &foo)() << endl;
55// cout << talk_base::Bind(&Foo::Test3, &foo, 3)() << endl;
56// cout << talk_base::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl;
57// }
58
59#ifndef TALK_BASE_BIND_H_
60#define TALK_BASE_BIND_H_
61
62#define NONAME
63
64namespace talk_base {
65namespace detail {
66// This is needed because the template parameters in Bind can't be resolved
67// if they're used both as parameters of the function pointer type and as
68// parameters to Bind itself: the function pointer parameters are exact
69// matches to the function prototype, but the parameters to bind have
70// references stripped. This trick allows the compiler to dictate the Bind
71// parameter types rather than deduce them.
72template <class T> struct identity { typedef T type; };
73} // namespace detail
74
75template <class ObjectT, class MethodT, class R>
76class MethodFunctor0 {
77 public:
78 MethodFunctor0(MethodT method, ObjectT* object)
79 : method_(method), object_(object) {}
80 R operator()() const {
81 return (object_->*method_)(); }
82 private:
83 MethodT method_;
84 ObjectT* object_;
85};
86
87#define FP_T(x) R (ObjectT::*x)()
88
89template <class ObjectT, class R>
90MethodFunctor0<ObjectT, FP_T(NONAME), R>
91Bind(FP_T(method), ObjectT* object) {
92 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
93 method, object);
94}
95
96#undef FP_T
97#define FP_T(x) R (ObjectT::*x)() const
98
99template <class ObjectT, class R>
100MethodFunctor0<const ObjectT, FP_T(NONAME), R>
101Bind(FP_T(method), const ObjectT* object) {
102 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>(
103 method, object);
104}
105
106#undef FP_T
107
108template <class ObjectT, class MethodT, class R,
109 class P1>
110class MethodFunctor1 {
111 public:
112 MethodFunctor1(MethodT method, ObjectT* object,
113 P1 p1)
114 : method_(method), object_(object),
115 p1_(p1) {}
116 R operator()() const {
117 return (object_->*method_)(p1_); }
118 private:
119 MethodT method_;
120 ObjectT* object_;
121 P1 p1_;
122};
123
124#define FP_T(x) R (ObjectT::*x)(P1)
125
126template <class ObjectT, class R,
127 class P1>
128MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
129Bind(FP_T(method), ObjectT* object,
130 typename detail::identity<P1>::type p1) {
131 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
132 method, object, p1);
133}
134
135#undef FP_T
136#define FP_T(x) R (ObjectT::*x)(P1) const
137
138template <class ObjectT, class R,
139 class P1>
140MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>
141Bind(FP_T(method), const ObjectT* object,
142 typename detail::identity<P1>::type p1) {
143 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>(
144 method, object, p1);
145}
146
147#undef FP_T
148
149template <class ObjectT, class MethodT, class R,
150 class P1,
151 class P2>
152class MethodFunctor2 {
153 public:
154 MethodFunctor2(MethodT method, ObjectT* object,
155 P1 p1,
156 P2 p2)
157 : method_(method), object_(object),
158 p1_(p1),
159 p2_(p2) {}
160 R operator()() const {
161 return (object_->*method_)(p1_, p2_); }
162 private:
163 MethodT method_;
164 ObjectT* object_;
165 P1 p1_;
166 P2 p2_;
167};
168
169#define FP_T(x) R (ObjectT::*x)(P1, P2)
170
171template <class ObjectT, class R,
172 class P1,
173 class P2>
174MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
175Bind(FP_T(method), ObjectT* object,
176 typename detail::identity<P1>::type p1,
177 typename detail::identity<P2>::type p2) {
178 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
179 method, object, p1, p2);
180}
181
182#undef FP_T
183#define FP_T(x) R (ObjectT::*x)(P1, P2) const
184
185template <class ObjectT, class R,
186 class P1,
187 class P2>
188MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>
189Bind(FP_T(method), const ObjectT* object,
190 typename detail::identity<P1>::type p1,
191 typename detail::identity<P2>::type p2) {
192 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>(
193 method, object, p1, p2);
194}
195
196#undef FP_T
197
198template <class ObjectT, class MethodT, class R,
199 class P1,
200 class P2,
201 class P3>
202class MethodFunctor3 {
203 public:
204 MethodFunctor3(MethodT method, ObjectT* object,
205 P1 p1,
206 P2 p2,
207 P3 p3)
208 : method_(method), object_(object),
209 p1_(p1),
210 p2_(p2),
211 p3_(p3) {}
212 R operator()() const {
213 return (object_->*method_)(p1_, p2_, p3_); }
214 private:
215 MethodT method_;
216 ObjectT* object_;
217 P1 p1_;
218 P2 p2_;
219 P3 p3_;
220};
221
222#define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
223
224template <class ObjectT, class R,
225 class P1,
226 class P2,
227 class P3>
228MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
229Bind(FP_T(method), ObjectT* object,
230 typename detail::identity<P1>::type p1,
231 typename detail::identity<P2>::type p2,
232 typename detail::identity<P3>::type p3) {
233 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
234 method, object, p1, p2, p3);
235}
236
237#undef FP_T
238#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const
239
240template <class ObjectT, class R,
241 class P1,
242 class P2,
243 class P3>
244MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>
245Bind(FP_T(method), const ObjectT* object,
246 typename detail::identity<P1>::type p1,
247 typename detail::identity<P2>::type p2,
248 typename detail::identity<P3>::type p3) {
249 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>(
250 method, object, p1, p2, p3);
251}
252
253#undef FP_T
254
255template <class ObjectT, class MethodT, class R,
256 class P1,
257 class P2,
258 class P3,
259 class P4>
260class MethodFunctor4 {
261 public:
262 MethodFunctor4(MethodT method, ObjectT* object,
263 P1 p1,
264 P2 p2,
265 P3 p3,
266 P4 p4)
267 : method_(method), object_(object),
268 p1_(p1),
269 p2_(p2),
270 p3_(p3),
271 p4_(p4) {}
272 R operator()() const {
273 return (object_->*method_)(p1_, p2_, p3_, p4_); }
274 private:
275 MethodT method_;
276 ObjectT* object_;
277 P1 p1_;
278 P2 p2_;
279 P3 p3_;
280 P4 p4_;
281};
282
283#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
284
285template <class ObjectT, class R,
286 class P1,
287 class P2,
288 class P3,
289 class P4>
290MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
291Bind(FP_T(method), ObjectT* object,
292 typename detail::identity<P1>::type p1,
293 typename detail::identity<P2>::type p2,
294 typename detail::identity<P3>::type p3,
295 typename detail::identity<P4>::type p4) {
296 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
297 method, object, p1, p2, p3, p4);
298}
299
300#undef FP_T
301#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const
302
303template <class ObjectT, class R,
304 class P1,
305 class P2,
306 class P3,
307 class P4>
308MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
309Bind(FP_T(method), const ObjectT* object,
310 typename detail::identity<P1>::type p1,
311 typename detail::identity<P2>::type p2,
312 typename detail::identity<P3>::type p3,
313 typename detail::identity<P4>::type p4) {
314 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
315 method, object, p1, p2, p3, p4);
316}
317
318#undef FP_T
319
320template <class ObjectT, class MethodT, class R,
321 class P1,
322 class P2,
323 class P3,
324 class P4,
325 class P5>
326class MethodFunctor5 {
327 public:
328 MethodFunctor5(MethodT method, ObjectT* object,
329 P1 p1,
330 P2 p2,
331 P3 p3,
332 P4 p4,
333 P5 p5)
334 : method_(method), object_(object),
335 p1_(p1),
336 p2_(p2),
337 p3_(p3),
338 p4_(p4),
339 p5_(p5) {}
340 R operator()() const {
341 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); }
342 private:
343 MethodT method_;
344 ObjectT* object_;
345 P1 p1_;
346 P2 p2_;
347 P3 p3_;
348 P4 p4_;
349 P5 p5_;
350};
351
352#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
353
354template <class ObjectT, class R,
355 class P1,
356 class P2,
357 class P3,
358 class P4,
359 class P5>
360MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
361Bind(FP_T(method), ObjectT* object,
362 typename detail::identity<P1>::type p1,
363 typename detail::identity<P2>::type p2,
364 typename detail::identity<P3>::type p3,
365 typename detail::identity<P4>::type p4,
366 typename detail::identity<P5>::type p5) {
367 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
368 method, object, p1, p2, p3, p4, p5);
369}
370
371#undef FP_T
372#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const
373
374template <class ObjectT, class R,
375 class P1,
376 class P2,
377 class P3,
378 class P4,
379 class P5>
380MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
381Bind(FP_T(method), const ObjectT* object,
382 typename detail::identity<P1>::type p1,
383 typename detail::identity<P2>::type p2,
384 typename detail::identity<P3>::type p3,
385 typename detail::identity<P4>::type p4,
386 typename detail::identity<P5>::type p5) {
387 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
388 method, object, p1, p2, p3, p4, p5);
389}
390
391#undef FP_T
392
393} // namespace talk_base
394
395#undef NONAME
396
397#endif // TALK_BASE_BIND_H_