blob: 923fda21b559f276a90a3504f7045de38f08289d [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
Magnus Jedvertb2745472015-08-25 17:56:22 +0200131// RemoveScopedPtrRef will capture scoped_refptr by-value instead of
132// by-reference.
133template <class T> struct RemoveScopedPtrRef { typedef T type; };
134template <class T>
135struct RemoveScopedPtrRef<const scoped_refptr<T>&> {
136 typedef scoped_refptr<T> type;
137};
138template <class T>
139struct RemoveScopedPtrRef<scoped_refptr<T>&> {
140 typedef scoped_refptr<T> type;
141};
142
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000143} // namespace detail
144
145template <class ObjectT, class MethodT, class R>
146class MethodFunctor0 {
147 public:
148 MethodFunctor0(MethodT method, ObjectT* object)
149 : method_(method), object_(object) {}
150 R operator()() const {
151 return (object_->*method_)(); }
152 private:
153 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200154 typename detail::PointerType<ObjectT>::type object_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000155};
156
157template <class FunctorT, class R>
158class Functor0 {
159 public:
160 explicit Functor0(const FunctorT& functor)
161 : functor_(functor) {}
162 R operator()() const {
163 return functor_(); }
164 private:
165 FunctorT functor_;
166};
167
168
169#define FP_T(x) R (ObjectT::*x)()
170
171template <class ObjectT, class R>
172MethodFunctor0<ObjectT, FP_T(NONAME), R>
173Bind(FP_T(method), ObjectT* object) {
174 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
175 method, object);
176}
177
178#undef FP_T
179#define FP_T(x) R (ObjectT::*x)() const
180
181template <class ObjectT, class R>
182MethodFunctor0<const ObjectT, FP_T(NONAME), R>
183Bind(FP_T(method), const ObjectT* object) {
184 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>(
185 method, object);
186}
187
188#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200189#define FP_T(x) R (ObjectT::*x)()
190
191template <class ObjectT, class R>
192MethodFunctor0<ObjectT, FP_T(NONAME), R>
193Bind(FP_T(method), const scoped_refptr<ObjectT>& object) {
194 return MethodFunctor0<ObjectT, FP_T(NONAME), R>(
195 method, object.get());
196}
197
198#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000199#define FP_T(x) R (*x)()
200
201template <class R>
202Functor0<FP_T(NONAME), R>
203Bind(FP_T(function)) {
204 return Functor0<FP_T(NONAME), R>(
205 function);
206}
207
208#undef FP_T
209
210template <class ObjectT, class MethodT, class R,
211 class P1>
212class MethodFunctor1 {
213 public:
214 MethodFunctor1(MethodT method, ObjectT* object,
215 P1 p1)
216 : method_(method), object_(object),
217 p1_(p1) {}
218 R operator()() const {
219 return (object_->*method_)(p1_); }
220 private:
221 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200222 typename detail::PointerType<ObjectT>::type object_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200223 typename detail::RemoveScopedPtrRef<P1>::type p1_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000224};
225
226template <class FunctorT, class R,
227 class P1>
228class Functor1 {
229 public:
230 Functor1(const FunctorT& functor, P1 p1)
231 : functor_(functor),
232 p1_(p1) {}
233 R operator()() const {
234 return functor_(p1_); }
235 private:
236 FunctorT functor_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200237 typename detail::RemoveScopedPtrRef<P1>::type p1_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000238};
239
240
241#define FP_T(x) R (ObjectT::*x)(P1)
242
243template <class ObjectT, class R,
244 class P1>
245MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
246Bind(FP_T(method), ObjectT* object,
247 typename detail::identity<P1>::type p1) {
248 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
249 method, object, p1);
250}
251
252#undef FP_T
253#define FP_T(x) R (ObjectT::*x)(P1) const
254
255template <class ObjectT, class R,
256 class P1>
257MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>
258Bind(FP_T(method), const ObjectT* object,
259 typename detail::identity<P1>::type p1) {
260 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>(
261 method, object, p1);
262}
263
264#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200265#define FP_T(x) R (ObjectT::*x)(P1)
266
267template <class ObjectT, class R,
268 class P1>
269MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
270Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
271 typename detail::identity<P1>::type p1) {
272 return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>(
273 method, object.get(), p1);
274}
275
276#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000277#define FP_T(x) R (*x)(P1)
278
279template <class R,
280 class P1>
281Functor1<FP_T(NONAME), R, P1>
282Bind(FP_T(function),
283 typename detail::identity<P1>::type p1) {
284 return Functor1<FP_T(NONAME), R, P1>(
285 function, p1);
286}
287
288#undef FP_T
289
290template <class ObjectT, class MethodT, class R,
291 class P1,
292 class P2>
293class MethodFunctor2 {
294 public:
295 MethodFunctor2(MethodT method, ObjectT* object,
296 P1 p1,
297 P2 p2)
298 : method_(method), object_(object),
299 p1_(p1),
300 p2_(p2) {}
301 R operator()() const {
302 return (object_->*method_)(p1_, p2_); }
303 private:
304 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200305 typename detail::PointerType<ObjectT>::type object_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200306 typename detail::RemoveScopedPtrRef<P1>::type p1_;
307 typename detail::RemoveScopedPtrRef<P2>::type p2_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000308};
309
310template <class FunctorT, class R,
311 class P1,
312 class P2>
313class Functor2 {
314 public:
315 Functor2(const FunctorT& functor, P1 p1, P2 p2)
316 : functor_(functor),
317 p1_(p1),
318 p2_(p2) {}
319 R operator()() const {
320 return functor_(p1_, p2_); }
321 private:
322 FunctorT functor_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200323 typename detail::RemoveScopedPtrRef<P1>::type p1_;
324 typename detail::RemoveScopedPtrRef<P2>::type p2_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000325};
326
327
328#define FP_T(x) R (ObjectT::*x)(P1, P2)
329
330template <class ObjectT, class R,
331 class P1,
332 class P2>
333MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
334Bind(FP_T(method), ObjectT* object,
335 typename detail::identity<P1>::type p1,
336 typename detail::identity<P2>::type p2) {
337 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
338 method, object, p1, p2);
339}
340
341#undef FP_T
342#define FP_T(x) R (ObjectT::*x)(P1, P2) const
343
344template <class ObjectT, class R,
345 class P1,
346 class P2>
347MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>
348Bind(FP_T(method), const ObjectT* object,
349 typename detail::identity<P1>::type p1,
350 typename detail::identity<P2>::type p2) {
351 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>(
352 method, object, p1, p2);
353}
354
355#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200356#define FP_T(x) R (ObjectT::*x)(P1, P2)
357
358template <class ObjectT, class R,
359 class P1,
360 class P2>
361MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
362Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
363 typename detail::identity<P1>::type p1,
364 typename detail::identity<P2>::type p2) {
365 return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>(
366 method, object.get(), p1, p2);
367}
368
369#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000370#define FP_T(x) R (*x)(P1, P2)
371
372template <class R,
373 class P1,
374 class P2>
375Functor2<FP_T(NONAME), R, P1, P2>
376Bind(FP_T(function),
377 typename detail::identity<P1>::type p1,
378 typename detail::identity<P2>::type p2) {
379 return Functor2<FP_T(NONAME), R, P1, P2>(
380 function, p1, p2);
381}
382
383#undef FP_T
384
385template <class ObjectT, class MethodT, class R,
386 class P1,
387 class P2,
388 class P3>
389class MethodFunctor3 {
390 public:
391 MethodFunctor3(MethodT method, ObjectT* object,
392 P1 p1,
393 P2 p2,
394 P3 p3)
395 : method_(method), object_(object),
396 p1_(p1),
397 p2_(p2),
398 p3_(p3) {}
399 R operator()() const {
400 return (object_->*method_)(p1_, p2_, p3_); }
401 private:
402 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200403 typename detail::PointerType<ObjectT>::type object_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200404 typename detail::RemoveScopedPtrRef<P1>::type p1_;
405 typename detail::RemoveScopedPtrRef<P2>::type p2_;
406 typename detail::RemoveScopedPtrRef<P3>::type p3_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000407};
408
409template <class FunctorT, class R,
410 class P1,
411 class P2,
412 class P3>
413class Functor3 {
414 public:
415 Functor3(const FunctorT& functor, P1 p1, P2 p2, P3 p3)
416 : functor_(functor),
417 p1_(p1),
418 p2_(p2),
419 p3_(p3) {}
420 R operator()() const {
421 return functor_(p1_, p2_, p3_); }
422 private:
423 FunctorT functor_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200424 typename detail::RemoveScopedPtrRef<P1>::type p1_;
425 typename detail::RemoveScopedPtrRef<P2>::type p2_;
426 typename detail::RemoveScopedPtrRef<P3>::type p3_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000427};
428
429
430#define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
431
432template <class ObjectT, class R,
433 class P1,
434 class P2,
435 class P3>
436MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
437Bind(FP_T(method), ObjectT* object,
438 typename detail::identity<P1>::type p1,
439 typename detail::identity<P2>::type p2,
440 typename detail::identity<P3>::type p3) {
441 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
442 method, object, p1, p2, p3);
443}
444
445#undef FP_T
446#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const
447
448template <class ObjectT, class R,
449 class P1,
450 class P2,
451 class P3>
452MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>
453Bind(FP_T(method), const ObjectT* object,
454 typename detail::identity<P1>::type p1,
455 typename detail::identity<P2>::type p2,
456 typename detail::identity<P3>::type p3) {
457 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>(
458 method, object, p1, p2, p3);
459}
460
461#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200462#define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
463
464template <class ObjectT, class R,
465 class P1,
466 class P2,
467 class P3>
468MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
469Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
470 typename detail::identity<P1>::type p1,
471 typename detail::identity<P2>::type p2,
472 typename detail::identity<P3>::type p3) {
473 return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>(
474 method, object.get(), p1, p2, p3);
475}
476
477#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000478#define FP_T(x) R (*x)(P1, P2, P3)
479
480template <class R,
481 class P1,
482 class P2,
483 class P3>
484Functor3<FP_T(NONAME), R, P1, P2, P3>
485Bind(FP_T(function),
486 typename detail::identity<P1>::type p1,
487 typename detail::identity<P2>::type p2,
488 typename detail::identity<P3>::type p3) {
489 return Functor3<FP_T(NONAME), R, P1, P2, P3>(
490 function, p1, p2, p3);
491}
492
493#undef FP_T
494
495template <class ObjectT, class MethodT, class R,
496 class P1,
497 class P2,
498 class P3,
499 class P4>
500class MethodFunctor4 {
501 public:
502 MethodFunctor4(MethodT method, ObjectT* object,
503 P1 p1,
504 P2 p2,
505 P3 p3,
506 P4 p4)
507 : method_(method), object_(object),
508 p1_(p1),
509 p2_(p2),
510 p3_(p3),
511 p4_(p4) {}
512 R operator()() const {
513 return (object_->*method_)(p1_, p2_, p3_, p4_); }
514 private:
515 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200516 typename detail::PointerType<ObjectT>::type object_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200517 typename detail::RemoveScopedPtrRef<P1>::type p1_;
518 typename detail::RemoveScopedPtrRef<P2>::type p2_;
519 typename detail::RemoveScopedPtrRef<P3>::type p3_;
520 typename detail::RemoveScopedPtrRef<P4>::type p4_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000521};
522
523template <class FunctorT, class R,
524 class P1,
525 class P2,
526 class P3,
527 class P4>
528class Functor4 {
529 public:
530 Functor4(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4)
531 : functor_(functor),
532 p1_(p1),
533 p2_(p2),
534 p3_(p3),
535 p4_(p4) {}
536 R operator()() const {
537 return functor_(p1_, p2_, p3_, p4_); }
538 private:
539 FunctorT functor_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200540 typename detail::RemoveScopedPtrRef<P1>::type p1_;
541 typename detail::RemoveScopedPtrRef<P2>::type p2_;
542 typename detail::RemoveScopedPtrRef<P3>::type p3_;
543 typename detail::RemoveScopedPtrRef<P4>::type p4_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000544};
545
546
547#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
548
549template <class ObjectT, class R,
550 class P1,
551 class P2,
552 class P3,
553 class P4>
554MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
555Bind(FP_T(method), ObjectT* object,
556 typename detail::identity<P1>::type p1,
557 typename detail::identity<P2>::type p2,
558 typename detail::identity<P3>::type p3,
559 typename detail::identity<P4>::type p4) {
560 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
561 method, object, p1, p2, p3, p4);
562}
563
564#undef FP_T
565#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const
566
567template <class ObjectT, class R,
568 class P1,
569 class P2,
570 class P3,
571 class P4>
572MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
573Bind(FP_T(method), const ObjectT* object,
574 typename detail::identity<P1>::type p1,
575 typename detail::identity<P2>::type p2,
576 typename detail::identity<P3>::type p3,
577 typename detail::identity<P4>::type p4) {
578 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
579 method, object, p1, p2, p3, p4);
580}
581
582#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200583#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
584
585template <class ObjectT, class R,
586 class P1,
587 class P2,
588 class P3,
589 class P4>
590MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
591Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
592 typename detail::identity<P1>::type p1,
593 typename detail::identity<P2>::type p2,
594 typename detail::identity<P3>::type p3,
595 typename detail::identity<P4>::type p4) {
596 return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
597 method, object.get(), p1, p2, p3, p4);
598}
599
600#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000601#define FP_T(x) R (*x)(P1, P2, P3, P4)
602
603template <class R,
604 class P1,
605 class P2,
606 class P3,
607 class P4>
608Functor4<FP_T(NONAME), R, P1, P2, P3, P4>
609Bind(FP_T(function),
610 typename detail::identity<P1>::type p1,
611 typename detail::identity<P2>::type p2,
612 typename detail::identity<P3>::type p3,
613 typename detail::identity<P4>::type p4) {
614 return Functor4<FP_T(NONAME), R, P1, P2, P3, P4>(
615 function, p1, p2, p3, p4);
616}
617
618#undef FP_T
619
620template <class ObjectT, class MethodT, class R,
621 class P1,
622 class P2,
623 class P3,
624 class P4,
625 class P5>
626class MethodFunctor5 {
627 public:
628 MethodFunctor5(MethodT method, ObjectT* object,
629 P1 p1,
630 P2 p2,
631 P3 p3,
632 P4 p4,
633 P5 p5)
634 : method_(method), object_(object),
635 p1_(p1),
636 p2_(p2),
637 p3_(p3),
638 p4_(p4),
639 p5_(p5) {}
640 R operator()() const {
641 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); }
642 private:
643 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200644 typename detail::PointerType<ObjectT>::type object_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200645 typename detail::RemoveScopedPtrRef<P1>::type p1_;
646 typename detail::RemoveScopedPtrRef<P2>::type p2_;
647 typename detail::RemoveScopedPtrRef<P3>::type p3_;
648 typename detail::RemoveScopedPtrRef<P4>::type p4_;
649 typename detail::RemoveScopedPtrRef<P5>::type p5_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000650};
651
652template <class FunctorT, class R,
653 class P1,
654 class P2,
655 class P3,
656 class P4,
657 class P5>
658class Functor5 {
659 public:
660 Functor5(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
661 : functor_(functor),
662 p1_(p1),
663 p2_(p2),
664 p3_(p3),
665 p4_(p4),
666 p5_(p5) {}
667 R operator()() const {
668 return functor_(p1_, p2_, p3_, p4_, p5_); }
669 private:
670 FunctorT functor_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200671 typename detail::RemoveScopedPtrRef<P1>::type p1_;
672 typename detail::RemoveScopedPtrRef<P2>::type p2_;
673 typename detail::RemoveScopedPtrRef<P3>::type p3_;
674 typename detail::RemoveScopedPtrRef<P4>::type p4_;
675 typename detail::RemoveScopedPtrRef<P5>::type p5_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000676};
677
678
679#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
680
681template <class ObjectT, class R,
682 class P1,
683 class P2,
684 class P3,
685 class P4,
686 class P5>
687MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
688Bind(FP_T(method), ObjectT* object,
689 typename detail::identity<P1>::type p1,
690 typename detail::identity<P2>::type p2,
691 typename detail::identity<P3>::type p3,
692 typename detail::identity<P4>::type p4,
693 typename detail::identity<P5>::type p5) {
694 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
695 method, object, p1, p2, p3, p4, p5);
696}
697
698#undef FP_T
699#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const
700
701template <class ObjectT, class R,
702 class P1,
703 class P2,
704 class P3,
705 class P4,
706 class P5>
707MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
708Bind(FP_T(method), const ObjectT* object,
709 typename detail::identity<P1>::type p1,
710 typename detail::identity<P2>::type p2,
711 typename detail::identity<P3>::type p3,
712 typename detail::identity<P4>::type p4,
713 typename detail::identity<P5>::type p5) {
714 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
715 method, object, p1, p2, p3, p4, p5);
716}
717
718#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200719#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
720
721template <class ObjectT, class R,
722 class P1,
723 class P2,
724 class P3,
725 class P4,
726 class P5>
727MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
728Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
729 typename detail::identity<P1>::type p1,
730 typename detail::identity<P2>::type p2,
731 typename detail::identity<P3>::type p3,
732 typename detail::identity<P4>::type p4,
733 typename detail::identity<P5>::type p5) {
734 return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
735 method, object.get(), p1, p2, p3, p4, p5);
736}
737
738#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000739#define FP_T(x) R (*x)(P1, P2, P3, P4, P5)
740
741template <class R,
742 class P1,
743 class P2,
744 class P3,
745 class P4,
746 class P5>
747Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>
748Bind(FP_T(function),
749 typename detail::identity<P1>::type p1,
750 typename detail::identity<P2>::type p2,
751 typename detail::identity<P3>::type p3,
752 typename detail::identity<P4>::type p4,
753 typename detail::identity<P5>::type p5) {
754 return Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>(
755 function, p1, p2, p3, p4, p5);
756}
757
758#undef FP_T
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200759
760template <class ObjectT, class MethodT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200761 class P1,
762 class P2,
763 class P3,
764 class P4,
765 class P5,
766 class P6>
767class MethodFunctor6 {
768 public:
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200769 MethodFunctor6(MethodT method, ObjectT* object,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200770 P1 p1,
771 P2 p2,
772 P3 p3,
773 P4 p4,
774 P5 p5,
775 P6 p6)
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200776 : method_(method), object_(object),
777 p1_(p1),
778 p2_(p2),
779 p3_(p3),
780 p4_(p4),
781 p5_(p5),
782 p6_(p6) {}
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200783 R operator()() const {
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200784 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_); }
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200785 private:
786 MethodT method_;
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200787 typename detail::PointerType<ObjectT>::type object_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200788 typename detail::RemoveScopedPtrRef<P1>::type p1_;
789 typename detail::RemoveScopedPtrRef<P2>::type p2_;
790 typename detail::RemoveScopedPtrRef<P3>::type p3_;
791 typename detail::RemoveScopedPtrRef<P4>::type p4_;
792 typename detail::RemoveScopedPtrRef<P5>::type p5_;
793 typename detail::RemoveScopedPtrRef<P6>::type p6_;
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200794};
795
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200796template <class FunctorT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200797 class P1,
798 class P2,
799 class P3,
800 class P4,
801 class P5,
802 class P6>
803class Functor6 {
804 public:
805 Functor6(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
806 : functor_(functor),
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200807 p1_(p1),
808 p2_(p2),
809 p3_(p3),
810 p4_(p4),
811 p5_(p5),
812 p6_(p6) {}
813 R operator()() const {
814 return functor_(p1_, p2_, p3_, p4_, p5_, p6_); }
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200815 private:
816 FunctorT functor_;
Magnus Jedvertb2745472015-08-25 17:56:22 +0200817 typename detail::RemoveScopedPtrRef<P1>::type p1_;
818 typename detail::RemoveScopedPtrRef<P2>::type p2_;
819 typename detail::RemoveScopedPtrRef<P3>::type p3_;
820 typename detail::RemoveScopedPtrRef<P4>::type p4_;
821 typename detail::RemoveScopedPtrRef<P5>::type p5_;
822 typename detail::RemoveScopedPtrRef<P6>::type p6_;
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200823};
824
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200825
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200826#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6)
827
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200828template <class ObjectT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200829 class P1,
830 class P2,
831 class P3,
832 class P4,
833 class P5,
834 class P6>
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200835MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
836Bind(FP_T(method), ObjectT* object,
837 typename detail::identity<P1>::type p1,
838 typename detail::identity<P2>::type p2,
839 typename detail::identity<P3>::type p3,
840 typename detail::identity<P4>::type p4,
841 typename detail::identity<P5>::type p5,
842 typename detail::identity<P6>::type p6) {
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200843 return MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
844 method, object, p1, p2, p3, p4, p5, p6);
845}
846
847#undef FP_T
848#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) const
849
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200850template <class ObjectT, class R,
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200851 class P1,
852 class P2,
853 class P3,
854 class P4,
855 class P5,
856 class P6>
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200857MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
858Bind(FP_T(method), const ObjectT* object,
859 typename detail::identity<P1>::type p1,
860 typename detail::identity<P2>::type p2,
861 typename detail::identity<P3>::type p3,
862 typename detail::identity<P4>::type p4,
863 typename detail::identity<P5>::type p5,
864 typename detail::identity<P6>::type p6) {
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200865 return MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
866 method, object, p1, p2, p3, p4, p5, p6);
867}
868
869#undef FP_T
Magnus Jedvertd3de9c52015-08-20 16:03:52 +0200870#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6)
871
872template <class ObjectT, class R,
873 class P1,
874 class P2,
875 class P3,
876 class P4,
877 class P5,
878 class P6>
879MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
880Bind(FP_T(method), const scoped_refptr<ObjectT>& object,
881 typename detail::identity<P1>::type p1,
882 typename detail::identity<P2>::type p2,
883 typename detail::identity<P3>::type p3,
884 typename detail::identity<P4>::type p4,
885 typename detail::identity<P5>::type p5,
886 typename detail::identity<P6>::type p6) {
887 return MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
888 method, object.get(), p1, p2, p3, p4, p5, p6);
889}
890
891#undef FP_T
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200892#define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6)
893
Fredrik Solenbergc9371392015-08-06 12:40:53 +0200894template <class R,
895 class P1,
896 class P2,
897 class P3,
898 class P4,
899 class P5,
900 class P6>
901Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
902Bind(FP_T(function),
903 typename detail::identity<P1>::type p1,
904 typename detail::identity<P2>::type p2,
905 typename detail::identity<P3>::type p3,
906 typename detail::identity<P4>::type p4,
907 typename detail::identity<P5>::type p5,
908 typename detail::identity<P6>::type p6) {
909 return Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
910 function, p1, p2, p3, p4, p5, p6);
Jelena Marusic5d6e58e2015-07-13 11:16:39 +0200911}
912
913#undef FP_T
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000914
915} // namespace rtc
916
917#undef NONAME
918
919#endif // WEBRTC_BASE_BIND_H_