blob: 5b4eaac943be2e12f67dfcd804792e5bf241b26f [file] [log] [blame]
henrike@webrtc.org0e118e72013-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
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +000087template <class FunctorT, class R>
88class Functor0 {
89 public:
90 explicit Functor0(const FunctorT& functor)
91 : functor_(functor) {}
92 R operator()() const {
93 return functor_(); }
94 private:
95 FunctorT functor_;
96};
97
98
henrike@webrtc.org0e118e72013-07-10 00:45:36 +000099#define FP_T(x) R (ObjectT::*x)()
100
101template <class ObjectT, class R>
102MethodFunctor0<ObjectT, FP_T(NONAME), R>
103Bind(FP_T(method), ObjectT* object) {
104 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
105 method, object);
106}
107
108#undef FP_T
109#define FP_T(x) R (ObjectT::*x)() const
110
111template <class ObjectT, class R>
112MethodFunctor0<const ObjectT, FP_T(NONAME), R>
113Bind(FP_T(method), const ObjectT* object) {
114 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>(
115 method, object);
116}
117
118#undef FP_T
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000119#define FP_T(x) R (*x)()
120
121template <class R>
122Functor0<FP_T(NONAME), R>
123Bind(FP_T(function)) {
124 return Functor0<FP_T(NONAME), R>(
125 function);
126}
127
128#undef FP_T
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000129
130template <class ObjectT, class MethodT, class R,
131 class P1>
132class MethodFunctor1 {
133 public:
134 MethodFunctor1(MethodT method, ObjectT* object,
135 P1 p1)
136 : method_(method), object_(object),
137 p1_(p1) {}
138 R operator()() const {
139 return (object_->*method_)(p1_); }
140 private:
141 MethodT method_;
142 ObjectT* object_;
143 P1 p1_;
144};
145
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000146template <class FunctorT, class R,
147 class P1>
148class Functor1 {
149 public:
150 Functor1(const FunctorT& functor, P1 p1)
151 : functor_(functor),
152 p1_(p1) {}
153 R operator()() const {
154 return functor_(p1_); }
155 private:
156 FunctorT functor_;
157 P1 p1_;
158};
159
160
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000161#define FP_T(x) R (ObjectT::*x)(P1)
162
163template <class ObjectT, class R,
164 class P1>
165MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
166Bind(FP_T(method), ObjectT* object,
167 typename detail::identity<P1>::type p1) {
168 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
169 method, object, p1);
170}
171
172#undef FP_T
173#define FP_T(x) R (ObjectT::*x)(P1) const
174
175template <class ObjectT, class R,
176 class P1>
177MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>
178Bind(FP_T(method), const ObjectT* object,
179 typename detail::identity<P1>::type p1) {
180 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>(
181 method, object, p1);
182}
183
184#undef FP_T
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000185#define FP_T(x) R (*x)(P1)
186
187template <class R,
188 class P1>
189Functor1<FP_T(NONAME), R, P1>
190Bind(FP_T(function),
191 typename detail::identity<P1>::type p1) {
192 return Functor1<FP_T(NONAME), R, P1>(
193 function, p1);
194}
195
196#undef FP_T
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000197
198template <class ObjectT, class MethodT, class R,
199 class P1,
200 class P2>
201class MethodFunctor2 {
202 public:
203 MethodFunctor2(MethodT method, ObjectT* object,
204 P1 p1,
205 P2 p2)
206 : method_(method), object_(object),
207 p1_(p1),
208 p2_(p2) {}
209 R operator()() const {
210 return (object_->*method_)(p1_, p2_); }
211 private:
212 MethodT method_;
213 ObjectT* object_;
214 P1 p1_;
215 P2 p2_;
216};
217
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000218template <class FunctorT, class R,
219 class P1,
220 class P2>
221class Functor2 {
222 public:
223 Functor2(const FunctorT& functor, P1 p1, P2 p2)
224 : functor_(functor),
225 p1_(p1),
226 p2_(p2) {}
227 R operator()() const {
228 return functor_(p1_, p2_); }
229 private:
230 FunctorT functor_;
231 P1 p1_;
232 P2 p2_;
233};
234
235
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000236#define FP_T(x) R (ObjectT::*x)(P1, P2)
237
238template <class ObjectT, class R,
239 class P1,
240 class P2>
241MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
242Bind(FP_T(method), ObjectT* object,
243 typename detail::identity<P1>::type p1,
244 typename detail::identity<P2>::type p2) {
245 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
246 method, object, p1, p2);
247}
248
249#undef FP_T
250#define FP_T(x) R (ObjectT::*x)(P1, P2) const
251
252template <class ObjectT, class R,
253 class P1,
254 class P2>
255MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>
256Bind(FP_T(method), const ObjectT* object,
257 typename detail::identity<P1>::type p1,
258 typename detail::identity<P2>::type p2) {
259 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>(
260 method, object, p1, p2);
261}
262
263#undef FP_T
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000264#define FP_T(x) R (*x)(P1, P2)
265
266template <class R,
267 class P1,
268 class P2>
269Functor2<FP_T(NONAME), R, P1, P2>
270Bind(FP_T(function),
271 typename detail::identity<P1>::type p1,
272 typename detail::identity<P2>::type p2) {
273 return Functor2<FP_T(NONAME), R, P1, P2>(
274 function, p1, p2);
275}
276
277#undef FP_T
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000278
279template <class ObjectT, class MethodT, class R,
280 class P1,
281 class P2,
282 class P3>
283class MethodFunctor3 {
284 public:
285 MethodFunctor3(MethodT method, ObjectT* object,
286 P1 p1,
287 P2 p2,
288 P3 p3)
289 : method_(method), object_(object),
290 p1_(p1),
291 p2_(p2),
292 p3_(p3) {}
293 R operator()() const {
294 return (object_->*method_)(p1_, p2_, p3_); }
295 private:
296 MethodT method_;
297 ObjectT* object_;
298 P1 p1_;
299 P2 p2_;
300 P3 p3_;
301};
302
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000303template <class FunctorT, class R,
304 class P1,
305 class P2,
306 class P3>
307class Functor3 {
308 public:
309 Functor3(const FunctorT& functor, P1 p1, P2 p2, P3 p3)
310 : functor_(functor),
311 p1_(p1),
312 p2_(p2),
313 p3_(p3) {}
314 R operator()() const {
315 return functor_(p1_, p2_, p3_); }
316 private:
317 FunctorT functor_;
318 P1 p1_;
319 P2 p2_;
320 P3 p3_;
321};
322
323
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000324#define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
325
326template <class ObjectT, class R,
327 class P1,
328 class P2,
329 class P3>
330MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
331Bind(FP_T(method), ObjectT* object,
332 typename detail::identity<P1>::type p1,
333 typename detail::identity<P2>::type p2,
334 typename detail::identity<P3>::type p3) {
335 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
336 method, object, p1, p2, p3);
337}
338
339#undef FP_T
340#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const
341
342template <class ObjectT, class R,
343 class P1,
344 class P2,
345 class P3>
346MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>
347Bind(FP_T(method), const ObjectT* object,
348 typename detail::identity<P1>::type p1,
349 typename detail::identity<P2>::type p2,
350 typename detail::identity<P3>::type p3) {
351 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>(
352 method, object, p1, p2, p3);
353}
354
355#undef FP_T
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000356#define FP_T(x) R (*x)(P1, P2, P3)
357
358template <class R,
359 class P1,
360 class P2,
361 class P3>
362Functor3<FP_T(NONAME), R, P1, P2, P3>
363Bind(FP_T(function),
364 typename detail::identity<P1>::type p1,
365 typename detail::identity<P2>::type p2,
366 typename detail::identity<P3>::type p3) {
367 return Functor3<FP_T(NONAME), R, P1, P2, P3>(
368 function, p1, p2, p3);
369}
370
371#undef FP_T
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000372
373template <class ObjectT, class MethodT, class R,
374 class P1,
375 class P2,
376 class P3,
377 class P4>
378class MethodFunctor4 {
379 public:
380 MethodFunctor4(MethodT method, ObjectT* object,
381 P1 p1,
382 P2 p2,
383 P3 p3,
384 P4 p4)
385 : method_(method), object_(object),
386 p1_(p1),
387 p2_(p2),
388 p3_(p3),
389 p4_(p4) {}
390 R operator()() const {
391 return (object_->*method_)(p1_, p2_, p3_, p4_); }
392 private:
393 MethodT method_;
394 ObjectT* object_;
395 P1 p1_;
396 P2 p2_;
397 P3 p3_;
398 P4 p4_;
399};
400
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000401template <class FunctorT, class R,
402 class P1,
403 class P2,
404 class P3,
405 class P4>
406class Functor4 {
407 public:
408 Functor4(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4)
409 : functor_(functor),
410 p1_(p1),
411 p2_(p2),
412 p3_(p3),
413 p4_(p4) {}
414 R operator()() const {
415 return functor_(p1_, p2_, p3_, p4_); }
416 private:
417 FunctorT functor_;
418 P1 p1_;
419 P2 p2_;
420 P3 p3_;
421 P4 p4_;
422};
423
424
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000425#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
426
427template <class ObjectT, class R,
428 class P1,
429 class P2,
430 class P3,
431 class P4>
432MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
433Bind(FP_T(method), ObjectT* object,
434 typename detail::identity<P1>::type p1,
435 typename detail::identity<P2>::type p2,
436 typename detail::identity<P3>::type p3,
437 typename detail::identity<P4>::type p4) {
438 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
439 method, object, p1, p2, p3, p4);
440}
441
442#undef FP_T
443#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const
444
445template <class ObjectT, class R,
446 class P1,
447 class P2,
448 class P3,
449 class P4>
450MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
451Bind(FP_T(method), const ObjectT* object,
452 typename detail::identity<P1>::type p1,
453 typename detail::identity<P2>::type p2,
454 typename detail::identity<P3>::type p3,
455 typename detail::identity<P4>::type p4) {
456 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
457 method, object, p1, p2, p3, p4);
458}
459
460#undef FP_T
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000461#define FP_T(x) R (*x)(P1, P2, P3, P4)
462
463template <class R,
464 class P1,
465 class P2,
466 class P3,
467 class P4>
468Functor4<FP_T(NONAME), R, P1, P2, P3, P4>
469Bind(FP_T(function),
470 typename detail::identity<P1>::type p1,
471 typename detail::identity<P2>::type p2,
472 typename detail::identity<P3>::type p3,
473 typename detail::identity<P4>::type p4) {
474 return Functor4<FP_T(NONAME), R, P1, P2, P3, P4>(
475 function, p1, p2, p3, p4);
476}
477
478#undef FP_T
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000479
480template <class ObjectT, class MethodT, class R,
481 class P1,
482 class P2,
483 class P3,
484 class P4,
485 class P5>
486class MethodFunctor5 {
487 public:
488 MethodFunctor5(MethodT method, ObjectT* object,
489 P1 p1,
490 P2 p2,
491 P3 p3,
492 P4 p4,
493 P5 p5)
494 : method_(method), object_(object),
495 p1_(p1),
496 p2_(p2),
497 p3_(p3),
498 p4_(p4),
499 p5_(p5) {}
500 R operator()() const {
501 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); }
502 private:
503 MethodT method_;
504 ObjectT* object_;
505 P1 p1_;
506 P2 p2_;
507 P3 p3_;
508 P4 p4_;
509 P5 p5_;
510};
511
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000512template <class FunctorT, class R,
513 class P1,
514 class P2,
515 class P3,
516 class P4,
517 class P5>
518class Functor5 {
519 public:
520 Functor5(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
521 : functor_(functor),
522 p1_(p1),
523 p2_(p2),
524 p3_(p3),
525 p4_(p4),
526 p5_(p5) {}
527 R operator()() const {
528 return functor_(p1_, p2_, p3_, p4_, p5_); }
529 private:
530 FunctorT functor_;
531 P1 p1_;
532 P2 p2_;
533 P3 p3_;
534 P4 p4_;
535 P5 p5_;
536};
537
538
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000539#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
540
541template <class ObjectT, class R,
542 class P1,
543 class P2,
544 class P3,
545 class P4,
546 class P5>
547MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
548Bind(FP_T(method), ObjectT* object,
549 typename detail::identity<P1>::type p1,
550 typename detail::identity<P2>::type p2,
551 typename detail::identity<P3>::type p3,
552 typename detail::identity<P4>::type p4,
553 typename detail::identity<P5>::type p5) {
554 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
555 method, object, p1, p2, p3, p4, p5);
556}
557
558#undef FP_T
559#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const
560
561template <class ObjectT, class R,
562 class P1,
563 class P2,
564 class P3,
565 class P4,
566 class P5>
567MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
568Bind(FP_T(method), const ObjectT* object,
569 typename detail::identity<P1>::type p1,
570 typename detail::identity<P2>::type p2,
571 typename detail::identity<P3>::type p3,
572 typename detail::identity<P4>::type p4,
573 typename detail::identity<P5>::type p5) {
574 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
575 method, object, p1, p2, p3, p4, p5);
576}
577
578#undef FP_T
sergeyu@chromium.org70022fa2014-02-07 19:03:26 +0000579#define FP_T(x) R (*x)(P1, P2, P3, P4, P5)
580
581template <class R,
582 class P1,
583 class P2,
584 class P3,
585 class P4,
586 class P5>
587Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>
588Bind(FP_T(function),
589 typename detail::identity<P1>::type p1,
590 typename detail::identity<P2>::type p2,
591 typename detail::identity<P3>::type p3,
592 typename detail::identity<P4>::type p4,
593 typename detail::identity<P5>::type p5) {
594 return Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>(
595 function, p1, p2, p3, p4, p5);
596}
597
598#undef FP_T
henrike@webrtc.org0e118e72013-07-10 00:45:36 +0000599
600} // namespace talk_base
601
602#undef NONAME
603
604#endif // TALK_BASE_BIND_H_