blob: 2d8114052d1fb34d83f592579f9f32a61efc18c4 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001// 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
Magnus Jedvertd3de9c52015-08-20 16:03:52 +020019// objects (aka functors). The method object is captured as a scoped_refptr<> if
20// possible, and as a raw pointer otherwise. Any arguments to the method are
21// captured by value. The return value of Bind is a stateful, nullary function
22// object. Care should be taken about the lifetime of objects captured by
23// Bind(); the returned functor knows nothing about the lifetime of a non
24// ref-counted method object or any arguments passed by pointer, and calling the
25// functor with a destroyed object will surely do bad things.
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000026//
27// Example usage:
28// struct Foo {
29// int Test1() { return 42; }
30// int Test2() const { return 52; }
31// int Test3(int x) { return x*x; }
32// float Test4(int x, float y) { return x + y; }
33// };
34//
35// int main() {
36// Foo foo;
37// cout << rtc::Bind(&Foo::Test1, &foo)() << endl;
38// cout << rtc::Bind(&Foo::Test2, &foo)() << endl;
39// cout << rtc::Bind(&Foo::Test3, &foo, 3)() << endl;
40// cout << rtc::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl;
41// }
Magnus Jedvertd3de9c52015-08-20 16:03:52 +020042//
43// Example usage of ref counted objects:
44// struct Bar {
45// int AddRef();
46// int Release();
47//
48// void Test() {}
49// void BindThis() {
50// // The functor passed to AsyncInvoke() will keep this object alive.
51// invoker.AsyncInvoke(rtc::Bind(&Bar::Test, this));
52// }
53// };
54//
55// int main() {
56// rtc::scoped_refptr<Bar> bar = new rtc::RefCountedObject<Bar>();
57// auto functor = rtc::Bind(&Bar::Test, bar);
58// bar = nullptr;
59// // The functor stores an internal scoped_refptr<Bar>, so this is safe.
60// functor();
61// }
62//
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000063
64#ifndef WEBRTC_BASE_BIND_H_
65#define WEBRTC_BASE_BIND_H_
66
Magnus Jedvertd3de9c52015-08-20 16:03:52 +020067#include "webrtc/base/scoped_ref_ptr.h"
68
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000069#define NONAME
70
71namespace rtc {
72namespace detail {
73// This is needed because the template parameters in Bind can't be resolved
74// if they're used both as parameters of the function pointer type and as
75// parameters to Bind itself: the function pointer parameters are exact
76// matches to the function prototype, but the parameters to bind have
77// references stripped. This trick allows the compiler to dictate the Bind
78// parameter types rather than deduce them.
79template <class T> struct identity { typedef T type; };
Magnus Jedvertd3de9c52015-08-20 16:03:52 +020080
81// IsRefCounted<T>::value will be true for types that can be used in
82// rtc::scoped_refptr<T>, i.e. types that implements nullary functions AddRef()
83// and Release(), regardless of their return types. AddRef() and Release() can
84// be defined in T or any superclass of T.
85template <typename T>
86class IsRefCounted {
87 // This is a complex implementation detail done with SFINAE.
88
89 // Define types such that sizeof(Yes) != sizeof(No).
90 struct Yes { char dummy[1]; };
91 struct No { char dummy[2]; };
92 // Define two overloaded template functions with return types of different
93 // size. This way, we can use sizeof() on the return type to determine which
94 // function the compiler would have chosen. One function will be preferred
95 // over the other if it is possible to create it without compiler errors,
96 // otherwise the compiler will simply remove it, and default to the less
97 // preferred function.
98 template <typename R>
99 static Yes test(R* r, decltype(r->AddRef(), r->Release(), 42));
100 template <typename C> static No test(...);
101
102public:
103 // Trick the compiler to tell if it's possible to call AddRef() and Release().
104 static const bool value = sizeof(test<T>((T*)nullptr, 42)) == sizeof(Yes);
105};
106
107// TernaryTypeOperator is a helper class to select a type based on a static bool
108// value.
109template <bool condition, typename IfTrueT, typename IfFalseT>
110struct TernaryTypeOperator {};
111
112template <typename IfTrueT, typename IfFalseT>
113struct TernaryTypeOperator<true, IfTrueT, IfFalseT> {
114 typedef IfTrueT type;
115};
116
117template <typename IfTrueT, typename IfFalseT>
118struct TernaryTypeOperator<false, IfTrueT, IfFalseT> {
119 typedef IfFalseT type;
120};
121
122// PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T*
123// otherwise.
124template <class T>
125struct PointerType {
126 typedef typename TernaryTypeOperator<IsRefCounted<T>::value,
127 scoped_refptr<T>,
128 T*>::type type;
129};
130
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000131} // namespace detail
132
133template <class ObjectT, class MethodT, class R>
134class MethodFunctor0 {
135 public:
136 MethodFunctor0(MethodT method, ObjectT* object)
137 : method_(method), object_(object) {}
138 R operator()() const {
139 return (object_->*method_)(); }
140 private:
141 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200142 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000143};
144
145template <class FunctorT, class R>
146class Functor0 {
147 public:
148 explicit Functor0(const FunctorT& functor)
149 : functor_(functor) {}
150 R operator()() const {
151 return functor_(); }
152 private:
153 FunctorT functor_;
154};
155
156
157#define FP_T(x) R (ObjectT::*x)()
158
159template <class ObjectT, class R>
160MethodFunctor0<ObjectT, FP_T(NONAME), R>
161Bind(FP_T(method), ObjectT* object) {
162 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
163 method, object);
164}
165
166#undef FP_T
167#define FP_T(x) R (ObjectT::*x)() const
168
169template <class ObjectT, class R>
170MethodFunctor0<const ObjectT, FP_T(NONAME), R>
171Bind(FP_T(method), const ObjectT* object) {
172 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>(
173 method, object);
174}
175
176#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200177#define FP_T(x) R (ObjectT::*x)()
178
179template <class ObjectT, class R>
180MethodFunctor0<ObjectT, FP_T(NONAME), R>
181Bind(FP_T(method), const scoped_refptr<ObjectT>& object) {
182 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
183 method, object.get());
184}
185
186#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000187#define FP_T(x) R (*x)()
188
189template <class R>
190Functor0<FP_T(NONAME), R>
191Bind(FP_T(function)) {
192 return Functor0<FP_T(NONAME), R>(
193 function);
194}
195
196#undef FP_T
197
198template <class ObjectT, class MethodT, class R,
199 class P1>
200class MethodFunctor1 {
201 public:
202 MethodFunctor1(MethodT method, ObjectT* object,
203 P1 p1)
204 : method_(method), object_(object),
205 p1_(p1) {}
206 R operator()() const {
207 return (object_->*method_)(p1_); }
208 private:
209 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200210 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000211 P1 p1_;
212};
213
214template <class FunctorT, class R,
215 class P1>
216class Functor1 {
217 public:
218 Functor1(const FunctorT& functor, P1 p1)
219 : functor_(functor),
220 p1_(p1) {}
221 R operator()() const {
222 return functor_(p1_); }
223 private:
224 FunctorT functor_;
225 P1 p1_;
226};
227
228
229#define FP_T(x) R (ObjectT::*x)(P1)
230
231template <class ObjectT, class R,
232 class P1>
233MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
234Bind(FP_T(method), ObjectT* object,
235 typename detail::identity<P1>::type p1) {
236 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
237 method, object, p1);
238}
239
240#undef FP_T
241#define FP_T(x) R (ObjectT::*x)(P1) const
242
243template <class ObjectT, class R,
244 class P1>
245MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>
246Bind(FP_T(method), const ObjectT* object,
247 typename detail::identity<P1>::type p1) {
248 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>(
249 method, object, p1);
250}
251
252#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200253#define FP_T(x) R (ObjectT::*x)(P1)
254
255template <class ObjectT, class R,
256 class P1>
257MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
258Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
259 typename detail::identity<P1>::type p1) {
260 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
261 method, object.get(), p1);
262}
263
264#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000265#define FP_T(x) R (*x)(P1)
266
267template <class R,
268 class P1>
269Functor1<FP_T(NONAME), R, P1>
270Bind(FP_T(function),
271 typename detail::identity<P1>::type p1) {
272 return Functor1<FP_T(NONAME), R, P1>(
273 function, p1);
274}
275
276#undef FP_T
277
278template <class ObjectT, class MethodT, class R,
279 class P1,
280 class P2>
281class MethodFunctor2 {
282 public:
283 MethodFunctor2(MethodT method, ObjectT* object,
284 P1 p1,
285 P2 p2)
286 : method_(method), object_(object),
287 p1_(p1),
288 p2_(p2) {}
289 R operator()() const {
290 return (object_->*method_)(p1_, p2_); }
291 private:
292 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200293 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000294 P1 p1_;
295 P2 p2_;
296};
297
298template <class FunctorT, class R,
299 class P1,
300 class P2>
301class Functor2 {
302 public:
303 Functor2(const FunctorT& functor, P1 p1, P2 p2)
304 : functor_(functor),
305 p1_(p1),
306 p2_(p2) {}
307 R operator()() const {
308 return functor_(p1_, p2_); }
309 private:
310 FunctorT functor_;
311 P1 p1_;
312 P2 p2_;
313};
314
315
316#define FP_T(x) R (ObjectT::*x)(P1, P2)
317
318template <class ObjectT, class R,
319 class P1,
320 class P2>
321MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
322Bind(FP_T(method), ObjectT* object,
323 typename detail::identity<P1>::type p1,
324 typename detail::identity<P2>::type p2) {
325 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
326 method, object, p1, p2);
327}
328
329#undef FP_T
330#define FP_T(x) R (ObjectT::*x)(P1, P2) const
331
332template <class ObjectT, class R,
333 class P1,
334 class P2>
335MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>
336Bind(FP_T(method), const ObjectT* object,
337 typename detail::identity<P1>::type p1,
338 typename detail::identity<P2>::type p2) {
339 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>(
340 method, object, p1, p2);
341}
342
343#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200344#define FP_T(x) R (ObjectT::*x)(P1, P2)
345
346template <class ObjectT, class R,
347 class P1,
348 class P2>
349MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
350Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
351 typename detail::identity<P1>::type p1,
352 typename detail::identity<P2>::type p2) {
353 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
354 method, object.get(), p1, p2);
355}
356
357#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000358#define FP_T(x) R (*x)(P1, P2)
359
360template <class R,
361 class P1,
362 class P2>
363Functor2<FP_T(NONAME), R, P1, P2>
364Bind(FP_T(function),
365 typename detail::identity<P1>::type p1,
366 typename detail::identity<P2>::type p2) {
367 return Functor2<FP_T(NONAME), R, P1, P2>(
368 function, p1, p2);
369}
370
371#undef FP_T
372
373template <class ObjectT, class MethodT, class R,
374 class P1,
375 class P2,
376 class P3>
377class MethodFunctor3 {
378 public:
379 MethodFunctor3(MethodT method, ObjectT* object,
380 P1 p1,
381 P2 p2,
382 P3 p3)
383 : method_(method), object_(object),
384 p1_(p1),
385 p2_(p2),
386 p3_(p3) {}
387 R operator()() const {
388 return (object_->*method_)(p1_, p2_, p3_); }
389 private:
390 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200391 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000392 P1 p1_;
393 P2 p2_;
394 P3 p3_;
395};
396
397template <class FunctorT, class R,
398 class P1,
399 class P2,
400 class P3>
401class Functor3 {
402 public:
403 Functor3(const FunctorT& functor, P1 p1, P2 p2, P3 p3)
404 : functor_(functor),
405 p1_(p1),
406 p2_(p2),
407 p3_(p3) {}
408 R operator()() const {
409 return functor_(p1_, p2_, p3_); }
410 private:
411 FunctorT functor_;
412 P1 p1_;
413 P2 p2_;
414 P3 p3_;
415};
416
417
418#define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
419
420template <class ObjectT, class R,
421 class P1,
422 class P2,
423 class P3>
424MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
425Bind(FP_T(method), ObjectT* object,
426 typename detail::identity<P1>::type p1,
427 typename detail::identity<P2>::type p2,
428 typename detail::identity<P3>::type p3) {
429 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
430 method, object, p1, p2, p3);
431}
432
433#undef FP_T
434#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const
435
436template <class ObjectT, class R,
437 class P1,
438 class P2,
439 class P3>
440MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>
441Bind(FP_T(method), const ObjectT* object,
442 typename detail::identity<P1>::type p1,
443 typename detail::identity<P2>::type p2,
444 typename detail::identity<P3>::type p3) {
445 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>(
446 method, object, p1, p2, p3);
447}
448
449#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200450#define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
451
452template <class ObjectT, class R,
453 class P1,
454 class P2,
455 class P3>
456MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
457Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
458 typename detail::identity<P1>::type p1,
459 typename detail::identity<P2>::type p2,
460 typename detail::identity<P3>::type p3) {
461 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
462 method, object.get(), p1, p2, p3);
463}
464
465#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000466#define FP_T(x) R (*x)(P1, P2, P3)
467
468template <class R,
469 class P1,
470 class P2,
471 class P3>
472Functor3<FP_T(NONAME), R, P1, P2, P3>
473Bind(FP_T(function),
474 typename detail::identity<P1>::type p1,
475 typename detail::identity<P2>::type p2,
476 typename detail::identity<P3>::type p3) {
477 return Functor3<FP_T(NONAME), R, P1, P2, P3>(
478 function, p1, p2, p3);
479}
480
481#undef FP_T
482
483template <class ObjectT, class MethodT, class R,
484 class P1,
485 class P2,
486 class P3,
487 class P4>
488class MethodFunctor4 {
489 public:
490 MethodFunctor4(MethodT method, ObjectT* object,
491 P1 p1,
492 P2 p2,
493 P3 p3,
494 P4 p4)
495 : method_(method), object_(object),
496 p1_(p1),
497 p2_(p2),
498 p3_(p3),
499 p4_(p4) {}
500 R operator()() const {
501 return (object_->*method_)(p1_, p2_, p3_, p4_); }
502 private:
503 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200504 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000505 P1 p1_;
506 P2 p2_;
507 P3 p3_;
508 P4 p4_;
509};
510
511template <class FunctorT, class R,
512 class P1,
513 class P2,
514 class P3,
515 class P4>
516class Functor4 {
517 public:
518 Functor4(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4)
519 : functor_(functor),
520 p1_(p1),
521 p2_(p2),
522 p3_(p3),
523 p4_(p4) {}
524 R operator()() const {
525 return functor_(p1_, p2_, p3_, p4_); }
526 private:
527 FunctorT functor_;
528 P1 p1_;
529 P2 p2_;
530 P3 p3_;
531 P4 p4_;
532};
533
534
535#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
536
537template <class ObjectT, class R,
538 class P1,
539 class P2,
540 class P3,
541 class P4>
542MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
543Bind(FP_T(method), ObjectT* object,
544 typename detail::identity<P1>::type p1,
545 typename detail::identity<P2>::type p2,
546 typename detail::identity<P3>::type p3,
547 typename detail::identity<P4>::type p4) {
548 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
549 method, object, p1, p2, p3, p4);
550}
551
552#undef FP_T
553#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const
554
555template <class ObjectT, class R,
556 class P1,
557 class P2,
558 class P3,
559 class P4>
560MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
561Bind(FP_T(method), const ObjectT* object,
562 typename detail::identity<P1>::type p1,
563 typename detail::identity<P2>::type p2,
564 typename detail::identity<P3>::type p3,
565 typename detail::identity<P4>::type p4) {
566 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
567 method, object, p1, p2, p3, p4);
568}
569
570#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200571#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
572
573template <class ObjectT, class R,
574 class P1,
575 class P2,
576 class P3,
577 class P4>
578MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
579Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
580 typename detail::identity<P1>::type p1,
581 typename detail::identity<P2>::type p2,
582 typename detail::identity<P3>::type p3,
583 typename detail::identity<P4>::type p4) {
584 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
585 method, object.get(), p1, p2, p3, p4);
586}
587
588#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000589#define FP_T(x) R (*x)(P1, P2, P3, P4)
590
591template <class R,
592 class P1,
593 class P2,
594 class P3,
595 class P4>
596Functor4<FP_T(NONAME), R, P1, P2, P3, P4>
597Bind(FP_T(function),
598 typename detail::identity<P1>::type p1,
599 typename detail::identity<P2>::type p2,
600 typename detail::identity<P3>::type p3,
601 typename detail::identity<P4>::type p4) {
602 return Functor4<FP_T(NONAME), R, P1, P2, P3, P4>(
603 function, p1, p2, p3, p4);
604}
605
606#undef FP_T
607
608template <class ObjectT, class MethodT, class R,
609 class P1,
610 class P2,
611 class P3,
612 class P4,
613 class P5>
614class MethodFunctor5 {
615 public:
616 MethodFunctor5(MethodT method, ObjectT* object,
617 P1 p1,
618 P2 p2,
619 P3 p3,
620 P4 p4,
621 P5 p5)
622 : method_(method), object_(object),
623 p1_(p1),
624 p2_(p2),
625 p3_(p3),
626 p4_(p4),
627 p5_(p5) {}
628 R operator()() const {
629 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); }
630 private:
631 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200632 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000633 P1 p1_;
634 P2 p2_;
635 P3 p3_;
636 P4 p4_;
637 P5 p5_;
638};
639
640template <class FunctorT, class R,
641 class P1,
642 class P2,
643 class P3,
644 class P4,
645 class P5>
646class Functor5 {
647 public:
648 Functor5(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
649 : functor_(functor),
650 p1_(p1),
651 p2_(p2),
652 p3_(p3),
653 p4_(p4),
654 p5_(p5) {}
655 R operator()() const {
656 return functor_(p1_, p2_, p3_, p4_, p5_); }
657 private:
658 FunctorT functor_;
659 P1 p1_;
660 P2 p2_;
661 P3 p3_;
662 P4 p4_;
663 P5 p5_;
664};
665
666
667#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
668
669template <class ObjectT, class R,
670 class P1,
671 class P2,
672 class P3,
673 class P4,
674 class P5>
675MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
676Bind(FP_T(method), ObjectT* object,
677 typename detail::identity<P1>::type p1,
678 typename detail::identity<P2>::type p2,
679 typename detail::identity<P3>::type p3,
680 typename detail::identity<P4>::type p4,
681 typename detail::identity<P5>::type p5) {
682 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
683 method, object, p1, p2, p3, p4, p5);
684}
685
686#undef FP_T
687#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const
688
689template <class ObjectT, class R,
690 class P1,
691 class P2,
692 class P3,
693 class P4,
694 class P5>
695MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
696Bind(FP_T(method), const ObjectT* object,
697 typename detail::identity<P1>::type p1,
698 typename detail::identity<P2>::type p2,
699 typename detail::identity<P3>::type p3,
700 typename detail::identity<P4>::type p4,
701 typename detail::identity<P5>::type p5) {
702 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
703 method, object, p1, p2, p3, p4, p5);
704}
705
706#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200707#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
708
709template <class ObjectT, class R,
710 class P1,
711 class P2,
712 class P3,
713 class P4,
714 class P5>
715MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
716Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
717 typename detail::identity<P1>::type p1,
718 typename detail::identity<P2>::type p2,
719 typename detail::identity<P3>::type p3,
720 typename detail::identity<P4>::type p4,
721 typename detail::identity<P5>::type p5) {
722 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
723 method, object.get(), p1, p2, p3, p4, p5);
724}
725
726#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000727#define FP_T(x) R (*x)(P1, P2, P3, P4, P5)
728
729template <class R,
730 class P1,
731 class P2,
732 class P3,
733 class P4,
734 class P5>
735Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>
736Bind(FP_T(function),
737 typename detail::identity<P1>::type p1,
738 typename detail::identity<P2>::type p2,
739 typename detail::identity<P3>::type p3,
740 typename detail::identity<P4>::type p4,
741 typename detail::identity<P5>::type p5) {
742 return Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>(
743 function, p1, p2, p3, p4, p5);
744}
745
746#undef FP_T
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200747
748template <class ObjectT, class MethodT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200749 class P1,
750 class P2,
751 class P3,
752 class P4,
753 class P5,
754 class P6>
755class MethodFunctor6 {
756 public:
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200757 MethodFunctor6(MethodT method, ObjectT* object,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200758 P1 p1,
759 P2 p2,
760 P3 p3,
761 P4 p4,
762 P5 p5,
763 P6 p6)
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200764 : method_(method), object_(object),
765 p1_(p1),
766 p2_(p2),
767 p3_(p3),
768 p4_(p4),
769 p5_(p5),
770 p6_(p6) {}
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200771 R operator()() const {
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200772 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_); }
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200773 private:
774 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200775 typename detail::PointerType<ObjectT>::type object_;
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200776 P1 p1_;
777 P2 p2_;
778 P3 p3_;
779 P4 p4_;
780 P5 p5_;
781 P6 p6_;
782};
783
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200784template <class FunctorT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200785 class P1,
786 class P2,
787 class P3,
788 class P4,
789 class P5,
790 class P6>
791class Functor6 {
792 public:
793 Functor6(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
794 : functor_(functor),
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200795 p1_(p1),
796 p2_(p2),
797 p3_(p3),
798 p4_(p4),
799 p5_(p5),
800 p6_(p6) {}
801 R operator()() const {
802 return functor_(p1_, p2_, p3_, p4_, p5_, p6_); }
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200803 private:
804 FunctorT functor_;
805 P1 p1_;
806 P2 p2_;
807 P3 p3_;
808 P4 p4_;
809 P5 p5_;
810 P6 p6_;
811};
812
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200813
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200814#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6)
815
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200816template <class ObjectT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200817 class P1,
818 class P2,
819 class P3,
820 class P4,
821 class P5,
822 class P6>
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200823MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
824Bind(FP_T(method), ObjectT* object,
825 typename detail::identity<P1>::type p1,
826 typename detail::identity<P2>::type p2,
827 typename detail::identity<P3>::type p3,
828 typename detail::identity<P4>::type p4,
829 typename detail::identity<P5>::type p5,
830 typename detail::identity<P6>::type p6) {
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200831 return MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
832 method, object, p1, p2, p3, p4, p5, p6);
833}
834
835#undef FP_T
836#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) const
837
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200838template <class ObjectT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200839 class P1,
840 class P2,
841 class P3,
842 class P4,
843 class P5,
844 class P6>
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200845MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
846Bind(FP_T(method), const ObjectT* object,
847 typename detail::identity<P1>::type p1,
848 typename detail::identity<P2>::type p2,
849 typename detail::identity<P3>::type p3,
850 typename detail::identity<P4>::type p4,
851 typename detail::identity<P5>::type p5,
852 typename detail::identity<P6>::type p6) {
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200853 return MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
854 method, object, p1, p2, p3, p4, p5, p6);
855}
856
857#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200858#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6)
859
860template <class ObjectT, class R,
861 class P1,
862 class P2,
863 class P3,
864 class P4,
865 class P5,
866 class P6>
867MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
868Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
869 typename detail::identity<P1>::type p1,
870 typename detail::identity<P2>::type p2,
871 typename detail::identity<P3>::type p3,
872 typename detail::identity<P4>::type p4,
873 typename detail::identity<P5>::type p5,
874 typename detail::identity<P6>::type p6) {
875 return MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
876 method, object.get(), p1, p2, p3, p4, p5, p6);
877}
878
879#undef FP_T
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200880#define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6)
881
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200882template <class R,
883 class P1,
884 class P2,
885 class P3,
886 class P4,
887 class P5,
888 class P6>
889Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
890Bind(FP_T(function),
891 typename detail::identity<P1>::type p1,
892 typename detail::identity<P2>::type p2,
893 typename detail::identity<P3>::type p3,
894 typename detail::identity<P4>::type p4,
895 typename detail::identity<P5>::type p5,
896 typename detail::identity<P6>::type p6) {
897 return Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
898 function, p1, p2, p3, p4, p5, p6);
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200899}
900
901#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000902
903} // namespace rtc
904
905#undef NONAME
906
907#endif // WEBRTC_BASE_BIND_H_