1 // This file was GENERATED by command:
2 // pump.py bind.h.pump
3 // DO NOT EDIT BY HAND!!!
4
5 /*
6 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
7 *
8 * Use of this source code is governed by a BSD-style license
9 * that can be found in the LICENSE file in the root of the source
10 * tree. An additional intellectual property rights grant can be found
11 * in the file PATENTS. All contributing project authors may
12 * be found in the AUTHORS file in the root of the source tree.
13 */
14
15 // To generate bind.h from bind.h.pump, execute:
16 // /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump
17
18 // Bind() is an overloaded function that converts method calls into function
19 // objects (aka functors). It captures any arguments to the method by value
20 // when Bind is called, producing a stateful, nullary function object. Care
21 // should be taken about the lifetime of objects captured by Bind(); the
22 // returned functor knows nothing about the lifetime of the method's object or
23 // any arguments passed by pointer, and calling the functor with a destroyed
24 // object will surely do bad things.
25 //
26 // Example usage:
27 // struct Foo {
28 // int Test1() { return 42; }
29 // int Test2() const { return 52; }
30 // int Test3(int x) { return x*x; }
31 // float Test4(int x, float y) { return x + y; }
32 // };
33 //
34 // int main() {
35 // Foo foo;
36 // cout << rtc::Bind(&Foo::Test1, &foo)() << endl;
37 // cout << rtc::Bind(&Foo::Test2, &foo)() << endl;
38 // cout << rtc::Bind(&Foo::Test3, &foo, 3)() << endl;
39 // cout << rtc::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl;
40 // }
41
42 #ifndef WEBRTC_BASE_BIND_H_
43 #define WEBRTC_BASE_BIND_H_
44
45 #define NONAME
46
47 namespace rtc {
48 namespace detail {
49 // This is needed because the template parameters in Bind can't be resolved
50 // if they're used both as parameters of the function pointer type and as
51 // parameters to Bind itself: the function pointer parameters are exact
52 // matches to the function prototype, but the parameters to bind have
53 // references stripped. This trick allows the compiler to dictate the Bind
54 // parameter types rather than deduce them.
55 template <class T> struct identity { typedef T type; };
56 } // namespace detail
57
58 template <class ObjectT, class MethodT, class R>
59 class MethodFunctor0 {
60 public:
MethodFunctor0(MethodT method,ObjectT * object)61 MethodFunctor0(MethodT method, ObjectT* object)
62 : method_(method), object_(object) {}
operator()63 R operator()() const {
64 return (object_->*method_)(); }
65 private:
66 MethodT method_;
67 ObjectT* object_;
68 };
69
70 template <class FunctorT, class R>
71 class Functor0 {
72 public:
Functor0(const FunctorT & functor)73 explicit Functor0(const FunctorT& functor)
74 : functor_(functor) {}
operator()75 R operator()() const {
76 return functor_(); }
77 private:
78 FunctorT functor_;
79 };
80
81
82 #define FP_T(x) R (ObjectT::*x)()
83
84 template <class ObjectT, class R>
85 MethodFunctor0<ObjectT, FP_T(NONAME), R>
Bind(FP_T (method),ObjectT * object)86 Bind(FP_T(method), ObjectT* object) {
87 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
88 method, object);
89 }
90
91 #undef FP_T
92 #define FP_T(x) R (ObjectT::*x)() const
93
94 template <class ObjectT, class R>
95 MethodFunctor0<const ObjectT, FP_T(NONAME), R>
Bind(FP_T (method),const ObjectT * object)96 Bind(FP_T(method), const ObjectT* object) {
97 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>(
98 method, object);
99 }
100
101 #undef FP_T
102 #define FP_T(x) R (*x)()
103
104 template <class R>
105 Functor0<FP_T(NONAME), R>
Bind(FP_T (function))106 Bind(FP_T(function)) {
107 return Functor0<FP_T(NONAME), R>(
108 function);
109 }
110
111 #undef FP_T
112
113 template <class ObjectT, class MethodT, class R,
114 class P1>
115 class MethodFunctor1 {
116 public:
MethodFunctor1(MethodT method,ObjectT * object,P1 p1)117 MethodFunctor1(MethodT method, ObjectT* object,
118 P1 p1)
119 : method_(method), object_(object),
120 p1_(p1) {}
operator()121 R operator()() const {
122 return (object_->*method_)(p1_); }
123 private:
124 MethodT method_;
125 ObjectT* object_;
126 P1 p1_;
127 };
128
129 template <class FunctorT, class R,
130 class P1>
131 class Functor1 {
132 public:
Functor1(const FunctorT & functor,P1 p1)133 Functor1(const FunctorT& functor, P1 p1)
134 : functor_(functor),
135 p1_(p1) {}
operator()136 R operator()() const {
137 return functor_(p1_); }
138 private:
139 FunctorT functor_;
140 P1 p1_;
141 };
142
143
144 #define FP_T(x) R (ObjectT::*x)(P1)
145
146 template <class ObjectT, class R,
147 class P1>
148 MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
Bind(FP_T (method),ObjectT * object,typename detail::identity<P1>::type p1)149 Bind(FP_T(method), ObjectT* object,
150 typename detail::identity<P1>::type p1) {
151 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
152 method, object, p1);
153 }
154
155 #undef FP_T
156 #define FP_T(x) R (ObjectT::*x)(P1) const
157
158 template <class ObjectT, class R,
159 class P1>
160 MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>
Bind(FP_T (method),const ObjectT * object,typename detail::identity<P1>::type p1)161 Bind(FP_T(method), const ObjectT* object,
162 typename detail::identity<P1>::type p1) {
163 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>(
164 method, object, p1);
165 }
166
167 #undef FP_T
168 #define FP_T(x) R (*x)(P1)
169
170 template <class R,
171 class P1>
172 Functor1<FP_T(NONAME), R, P1>
Bind(FP_T (function),typename detail::identity<P1>::type p1)173 Bind(FP_T(function),
174 typename detail::identity<P1>::type p1) {
175 return Functor1<FP_T(NONAME), R, P1>(
176 function, p1);
177 }
178
179 #undef FP_T
180
181 template <class ObjectT, class MethodT, class R,
182 class P1,
183 class P2>
184 class MethodFunctor2 {
185 public:
MethodFunctor2(MethodT method,ObjectT * object,P1 p1,P2 p2)186 MethodFunctor2(MethodT method, ObjectT* object,
187 P1 p1,
188 P2 p2)
189 : method_(method), object_(object),
190 p1_(p1),
191 p2_(p2) {}
operator()192 R operator()() const {
193 return (object_->*method_)(p1_, p2_); }
194 private:
195 MethodT method_;
196 ObjectT* object_;
197 P1 p1_;
198 P2 p2_;
199 };
200
201 template <class FunctorT, class R,
202 class P1,
203 class P2>
204 class Functor2 {
205 public:
Functor2(const FunctorT & functor,P1 p1,P2 p2)206 Functor2(const FunctorT& functor, P1 p1, P2 p2)
207 : functor_(functor),
208 p1_(p1),
209 p2_(p2) {}
operator()210 R operator()() const {
211 return functor_(p1_, p2_); }
212 private:
213 FunctorT functor_;
214 P1 p1_;
215 P2 p2_;
216 };
217
218
219 #define FP_T(x) R (ObjectT::*x)(P1, P2)
220
221 template <class ObjectT, class R,
222 class P1,
223 class P2>
224 MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
Bind(FP_T (method),ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2)225 Bind(FP_T(method), ObjectT* object,
226 typename detail::identity<P1>::type p1,
227 typename detail::identity<P2>::type p2) {
228 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
229 method, object, p1, p2);
230 }
231
232 #undef FP_T
233 #define FP_T(x) R (ObjectT::*x)(P1, P2) const
234
235 template <class ObjectT, class R,
236 class P1,
237 class P2>
238 MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>
Bind(FP_T (method),const ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2)239 Bind(FP_T(method), const ObjectT* object,
240 typename detail::identity<P1>::type p1,
241 typename detail::identity<P2>::type p2) {
242 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>(
243 method, object, p1, p2);
244 }
245
246 #undef FP_T
247 #define FP_T(x) R (*x)(P1, P2)
248
249 template <class R,
250 class P1,
251 class P2>
252 Functor2<FP_T(NONAME), R, P1, P2>
Bind(FP_T (function),typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2)253 Bind(FP_T(function),
254 typename detail::identity<P1>::type p1,
255 typename detail::identity<P2>::type p2) {
256 return Functor2<FP_T(NONAME), R, P1, P2>(
257 function, p1, p2);
258 }
259
260 #undef FP_T
261
262 template <class ObjectT, class MethodT, class R,
263 class P1,
264 class P2,
265 class P3>
266 class MethodFunctor3 {
267 public:
MethodFunctor3(MethodT method,ObjectT * object,P1 p1,P2 p2,P3 p3)268 MethodFunctor3(MethodT method, ObjectT* object,
269 P1 p1,
270 P2 p2,
271 P3 p3)
272 : method_(method), object_(object),
273 p1_(p1),
274 p2_(p2),
275 p3_(p3) {}
operator()276 R operator()() const {
277 return (object_->*method_)(p1_, p2_, p3_); }
278 private:
279 MethodT method_;
280 ObjectT* object_;
281 P1 p1_;
282 P2 p2_;
283 P3 p3_;
284 };
285
286 template <class FunctorT, class R,
287 class P1,
288 class P2,
289 class P3>
290 class Functor3 {
291 public:
Functor3(const FunctorT & functor,P1 p1,P2 p2,P3 p3)292 Functor3(const FunctorT& functor, P1 p1, P2 p2, P3 p3)
293 : functor_(functor),
294 p1_(p1),
295 p2_(p2),
296 p3_(p3) {}
operator()297 R operator()() const {
298 return functor_(p1_, p2_, p3_); }
299 private:
300 FunctorT functor_;
301 P1 p1_;
302 P2 p2_;
303 P3 p3_;
304 };
305
306
307 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
308
309 template <class ObjectT, class R,
310 class P1,
311 class P2,
312 class P3>
313 MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
Bind(FP_T (method),ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3)314 Bind(FP_T(method), ObjectT* object,
315 typename detail::identity<P1>::type p1,
316 typename detail::identity<P2>::type p2,
317 typename detail::identity<P3>::type p3) {
318 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
319 method, object, p1, p2, p3);
320 }
321
322 #undef FP_T
323 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const
324
325 template <class ObjectT, class R,
326 class P1,
327 class P2,
328 class P3>
329 MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>
Bind(FP_T (method),const ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3)330 Bind(FP_T(method), const ObjectT* object,
331 typename detail::identity<P1>::type p1,
332 typename detail::identity<P2>::type p2,
333 typename detail::identity<P3>::type p3) {
334 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>(
335 method, object, p1, p2, p3);
336 }
337
338 #undef FP_T
339 #define FP_T(x) R (*x)(P1, P2, P3)
340
341 template <class R,
342 class P1,
343 class P2,
344 class P3>
345 Functor3<FP_T(NONAME), R, P1, P2, P3>
Bind(FP_T (function),typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3)346 Bind(FP_T(function),
347 typename detail::identity<P1>::type p1,
348 typename detail::identity<P2>::type p2,
349 typename detail::identity<P3>::type p3) {
350 return Functor3<FP_T(NONAME), R, P1, P2, P3>(
351 function, p1, p2, p3);
352 }
353
354 #undef FP_T
355
356 template <class ObjectT, class MethodT, class R,
357 class P1,
358 class P2,
359 class P3,
360 class P4>
361 class MethodFunctor4 {
362 public:
MethodFunctor4(MethodT method,ObjectT * object,P1 p1,P2 p2,P3 p3,P4 p4)363 MethodFunctor4(MethodT method, ObjectT* object,
364 P1 p1,
365 P2 p2,
366 P3 p3,
367 P4 p4)
368 : method_(method), object_(object),
369 p1_(p1),
370 p2_(p2),
371 p3_(p3),
372 p4_(p4) {}
operator()373 R operator()() const {
374 return (object_->*method_)(p1_, p2_, p3_, p4_); }
375 private:
376 MethodT method_;
377 ObjectT* object_;
378 P1 p1_;
379 P2 p2_;
380 P3 p3_;
381 P4 p4_;
382 };
383
384 template <class FunctorT, class R,
385 class P1,
386 class P2,
387 class P3,
388 class P4>
389 class Functor4 {
390 public:
Functor4(const FunctorT & functor,P1 p1,P2 p2,P3 p3,P4 p4)391 Functor4(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4)
392 : functor_(functor),
393 p1_(p1),
394 p2_(p2),
395 p3_(p3),
396 p4_(p4) {}
operator()397 R operator()() const {
398 return functor_(p1_, p2_, p3_, p4_); }
399 private:
400 FunctorT functor_;
401 P1 p1_;
402 P2 p2_;
403 P3 p3_;
404 P4 p4_;
405 };
406
407
408 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
409
410 template <class ObjectT, class R,
411 class P1,
412 class P2,
413 class P3,
414 class P4>
415 MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
Bind(FP_T (method),ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3,typename detail::identity<P4>::type p4)416 Bind(FP_T(method), ObjectT* object,
417 typename detail::identity<P1>::type p1,
418 typename detail::identity<P2>::type p2,
419 typename detail::identity<P3>::type p3,
420 typename detail::identity<P4>::type p4) {
421 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
422 method, object, p1, p2, p3, p4);
423 }
424
425 #undef FP_T
426 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const
427
428 template <class ObjectT, class R,
429 class P1,
430 class P2,
431 class P3,
432 class P4>
433 MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
Bind(FP_T (method),const ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3,typename detail::identity<P4>::type p4)434 Bind(FP_T(method), const ObjectT* object,
435 typename detail::identity<P1>::type p1,
436 typename detail::identity<P2>::type p2,
437 typename detail::identity<P3>::type p3,
438 typename detail::identity<P4>::type p4) {
439 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
440 method, object, p1, p2, p3, p4);
441 }
442
443 #undef FP_T
444 #define FP_T(x) R (*x)(P1, P2, P3, P4)
445
446 template <class R,
447 class P1,
448 class P2,
449 class P3,
450 class P4>
451 Functor4<FP_T(NONAME), R, P1, P2, P3, P4>
Bind(FP_T (function),typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3,typename detail::identity<P4>::type p4)452 Bind(FP_T(function),
453 typename detail::identity<P1>::type p1,
454 typename detail::identity<P2>::type p2,
455 typename detail::identity<P3>::type p3,
456 typename detail::identity<P4>::type p4) {
457 return Functor4<FP_T(NONAME), R, P1, P2, P3, P4>(
458 function, p1, p2, p3, p4);
459 }
460
461 #undef FP_T
462
463 template <class ObjectT, class MethodT, class R,
464 class P1,
465 class P2,
466 class P3,
467 class P4,
468 class P5>
469 class MethodFunctor5 {
470 public:
MethodFunctor5(MethodT method,ObjectT * object,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5)471 MethodFunctor5(MethodT method, ObjectT* object,
472 P1 p1,
473 P2 p2,
474 P3 p3,
475 P4 p4,
476 P5 p5)
477 : method_(method), object_(object),
478 p1_(p1),
479 p2_(p2),
480 p3_(p3),
481 p4_(p4),
482 p5_(p5) {}
operator()483 R operator()() const {
484 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); }
485 private:
486 MethodT method_;
487 ObjectT* object_;
488 P1 p1_;
489 P2 p2_;
490 P3 p3_;
491 P4 p4_;
492 P5 p5_;
493 };
494
495 template <class FunctorT, class R,
496 class P1,
497 class P2,
498 class P3,
499 class P4,
500 class P5>
501 class Functor5 {
502 public:
Functor5(const FunctorT & functor,P1 p1,P2 p2,P3 p3,P4 p4,P5 p5)503 Functor5(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
504 : functor_(functor),
505 p1_(p1),
506 p2_(p2),
507 p3_(p3),
508 p4_(p4),
509 p5_(p5) {}
operator()510 R operator()() const {
511 return functor_(p1_, p2_, p3_, p4_, p5_); }
512 private:
513 FunctorT functor_;
514 P1 p1_;
515 P2 p2_;
516 P3 p3_;
517 P4 p4_;
518 P5 p5_;
519 };
520
521
522 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
523
524 template <class ObjectT, class R,
525 class P1,
526 class P2,
527 class P3,
528 class P4,
529 class P5>
530 MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
Bind(FP_T (method),ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3,typename detail::identity<P4>::type p4,typename detail::identity<P5>::type p5)531 Bind(FP_T(method), ObjectT* object,
532 typename detail::identity<P1>::type p1,
533 typename detail::identity<P2>::type p2,
534 typename detail::identity<P3>::type p3,
535 typename detail::identity<P4>::type p4,
536 typename detail::identity<P5>::type p5) {
537 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
538 method, object, p1, p2, p3, p4, p5);
539 }
540
541 #undef FP_T
542 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const
543
544 template <class ObjectT, class R,
545 class P1,
546 class P2,
547 class P3,
548 class P4,
549 class P5>
550 MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
Bind(FP_T (method),const ObjectT * object,typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3,typename detail::identity<P4>::type p4,typename detail::identity<P5>::type p5)551 Bind(FP_T(method), const ObjectT* object,
552 typename detail::identity<P1>::type p1,
553 typename detail::identity<P2>::type p2,
554 typename detail::identity<P3>::type p3,
555 typename detail::identity<P4>::type p4,
556 typename detail::identity<P5>::type p5) {
557 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
558 method, object, p1, p2, p3, p4, p5);
559 }
560
561 #undef FP_T
562 #define FP_T(x) R (*x)(P1, P2, P3, P4, P5)
563
564 template <class R,
565 class P1,
566 class P2,
567 class P3,
568 class P4,
569 class P5>
570 Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>
Bind(FP_T (function),typename detail::identity<P1>::type p1,typename detail::identity<P2>::type p2,typename detail::identity<P3>::type p3,typename detail::identity<P4>::type p4,typename detail::identity<P5>::type p5)571 Bind(FP_T(function),
572 typename detail::identity<P1>::type p1,
573 typename detail::identity<P2>::type p2,
574 typename detail::identity<P3>::type p3,
575 typename detail::identity<P4>::type p4,
576 typename detail::identity<P5>::type p5) {
577 return Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>(
578 function, p1, p2, p3, p4, p5);
579 }
580
581 #undef FP_T
582
583 } // namespace rtc
584
585 #undef NONAME
586
587 #endif // WEBRTC_BASE_BIND_H_
588