Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: webrtc/base/bind.h

Issue 1300523004: rtc::Bind: Capture method objects as scoped_refptr if they are ref counted (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove silly comment + address tommi@s comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/base/bind.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file was GENERATED by command: 1 // This file was GENERATED by command:
2 // pump.py bind.h.pump 2 // pump.py bind.h.pump
3 // DO NOT EDIT BY HAND!!! 3 // DO NOT EDIT BY HAND!!!
4 4
5 /* 5 /*
6 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 6 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
7 * 7 *
8 * Use of this source code is governed by a BSD-style license 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 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 10 * tree. An additional intellectual property rights grant can be found
11 * in the file PATENTS. All contributing project authors may 11 * in the file PATENTS. All contributing project authors may
12 * be found in the AUTHORS file in the root of the source tree. 12 * be found in the AUTHORS file in the root of the source tree.
13 */ 13 */
14 14
15 // To generate bind.h from bind.h.pump, execute: 15 // To generate bind.h from bind.h.pump, execute:
16 // /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump 16 // /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump
17 17
18 // Bind() is an overloaded function that converts method calls into function 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 19 // objects (aka functors). The method object is captured as a scoped_refptr<> if
20 // when Bind is called, producing a stateful, nullary function object. Care 20 // possible, and as a raw pointer otherwise. Any arguments to the method are
21 // should be taken about the lifetime of objects captured by Bind(); the 21 // captured by value. The return value of Bind is a stateful, nullary function
22 // returned functor knows nothing about the lifetime of the method's object or 22 // object. Care should be taken about the lifetime of objects captured by
23 // any arguments passed by pointer, and calling the functor with a destroyed 23 // Bind(); the returned functor knows nothing about the lifetime of a non
24 // object will surely do bad things. 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.
25 // 26 //
26 // Example usage: 27 // Example usage:
27 // struct Foo { 28 // struct Foo {
28 // int Test1() { return 42; } 29 // int Test1() { return 42; }
29 // int Test2() const { return 52; } 30 // int Test2() const { return 52; }
30 // int Test3(int x) { return x*x; } 31 // int Test3(int x) { return x*x; }
31 // float Test4(int x, float y) { return x + y; } 32 // float Test4(int x, float y) { return x + y; }
32 // }; 33 // };
33 // 34 //
34 // int main() { 35 // int main() {
35 // Foo foo; 36 // Foo foo;
36 // cout << rtc::Bind(&Foo::Test1, &foo)() << endl; 37 // cout << rtc::Bind(&Foo::Test1, &foo)() << endl;
37 // cout << rtc::Bind(&Foo::Test2, &foo)() << endl; 38 // cout << rtc::Bind(&Foo::Test2, &foo)() << endl;
38 // cout << rtc::Bind(&Foo::Test3, &foo, 3)() << endl; 39 // cout << rtc::Bind(&Foo::Test3, &foo, 3)() << endl;
39 // cout << rtc::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl; 40 // cout << rtc::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl;
40 // } 41 // }
42 //
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 //
41 63
42 #ifndef WEBRTC_BASE_BIND_H_ 64 #ifndef WEBRTC_BASE_BIND_H_
43 #define WEBRTC_BASE_BIND_H_ 65 #define WEBRTC_BASE_BIND_H_
44 66
67 #include "webrtc/base/scoped_ref_ptr.h"
68
45 #define NONAME 69 #define NONAME
46 70
47 namespace rtc { 71 namespace rtc {
48 namespace detail { 72 namespace detail {
49 // This is needed because the template parameters in Bind can't be resolved 73 // 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 74 // 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 75 // parameters to Bind itself: the function pointer parameters are exact
52 // matches to the function prototype, but the parameters to bind have 76 // matches to the function prototype, but the parameters to bind have
53 // references stripped. This trick allows the compiler to dictate the Bind 77 // references stripped. This trick allows the compiler to dictate the Bind
54 // parameter types rather than deduce them. 78 // parameter types rather than deduce them.
55 template <class T> struct identity { typedef T type; }; 79 template <class T> struct identity { typedef T type; };
80
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.
85 template <typename T>
86 class 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
102 public:
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.
109 template <bool condition, typename IfTrueT, typename IfFalseT>
110 struct TernaryTypeOperator {};
111
112 template <typename IfTrueT, typename IfFalseT>
113 struct TernaryTypeOperator<true, IfTrueT, IfFalseT> {
114 typedef IfTrueT type;
115 };
116
117 template <typename IfTrueT, typename IfFalseT>
118 struct 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.
124 template <class T>
125 struct PointerType {
126 typedef typename TernaryTypeOperator<IsRefCounted<T>::value,
127 scoped_refptr<T>,
128 T*>::type type;
129 };
130
56 } // namespace detail 131 } // namespace detail
57 132
58 template <class ObjectT, class MethodT, class R> 133 template <class ObjectT, class MethodT, class R>
59 class MethodFunctor0 { 134 class MethodFunctor0 {
60 public: 135 public:
61 MethodFunctor0(MethodT method, ObjectT* object) 136 MethodFunctor0(MethodT method, ObjectT* object)
62 : method_(method), object_(object) {} 137 : method_(method), object_(object) {}
63 R operator()() const { 138 R operator()() const {
64 return (object_->*method_)(); } 139 return (object_->*method_)(); }
65 private: 140 private:
66 MethodT method_; 141 MethodT method_;
67 ObjectT* object_; 142 typename detail::PointerType<ObjectT>::type object_;
68 }; 143 };
69 144
70 template <class FunctorT, class R> 145 template <class FunctorT, class R>
71 class Functor0 { 146 class Functor0 {
72 public: 147 public:
73 explicit Functor0(const FunctorT& functor) 148 explicit Functor0(const FunctorT& functor)
74 : functor_(functor) {} 149 : functor_(functor) {}
75 R operator()() const { 150 R operator()() const {
76 return functor_(); } 151 return functor_(); }
77 private: 152 private:
(...skipping 14 matching lines...) Expand all
92 #define FP_T(x) R (ObjectT::*x)() const 167 #define FP_T(x) R (ObjectT::*x)() const
93 168
94 template <class ObjectT, class R> 169 template <class ObjectT, class R>
95 MethodFunctor0<const ObjectT, FP_T(NONAME), R> 170 MethodFunctor0<const ObjectT, FP_T(NONAME), R>
96 Bind(FP_T(method), const ObjectT* object) { 171 Bind(FP_T(method), const ObjectT* object) {
97 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>( 172 return MethodFunctor0<const ObjectT, FP_T(NONAME), R>(
98 method, object); 173 method, object);
99 } 174 }
100 175
101 #undef FP_T 176 #undef FP_T
177 #define FP_T(x) R (ObjectT::*x)()
178
179 template <class ObjectT, class R>
180 MethodFunctor0<ObjectT, FP_T(NONAME), R>
181 Bind(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
102 #define FP_T(x) R (*x)() 187 #define FP_T(x) R (*x)()
103 188
104 template <class R> 189 template <class R>
105 Functor0<FP_T(NONAME), R> 190 Functor0<FP_T(NONAME), R>
106 Bind(FP_T(function)) { 191 Bind(FP_T(function)) {
107 return Functor0<FP_T(NONAME), R>( 192 return Functor0<FP_T(NONAME), R>(
108 function); 193 function);
109 } 194 }
110 195
111 #undef FP_T 196 #undef FP_T
112 197
113 template <class ObjectT, class MethodT, class R, 198 template <class ObjectT, class MethodT, class R,
114 class P1> 199 class P1>
115 class MethodFunctor1 { 200 class MethodFunctor1 {
116 public: 201 public:
117 MethodFunctor1(MethodT method, ObjectT* object, 202 MethodFunctor1(MethodT method, ObjectT* object,
118 P1 p1) 203 P1 p1)
119 : method_(method), object_(object), 204 : method_(method), object_(object),
120 p1_(p1) {} 205 p1_(p1) {}
121 R operator()() const { 206 R operator()() const {
122 return (object_->*method_)(p1_); } 207 return (object_->*method_)(p1_); }
123 private: 208 private:
124 MethodT method_; 209 MethodT method_;
125 ObjectT* object_; 210 typename detail::PointerType<ObjectT>::type object_;
126 P1 p1_; 211 P1 p1_;
127 }; 212 };
128 213
129 template <class FunctorT, class R, 214 template <class FunctorT, class R,
130 class P1> 215 class P1>
131 class Functor1 { 216 class Functor1 {
132 public: 217 public:
133 Functor1(const FunctorT& functor, P1 p1) 218 Functor1(const FunctorT& functor, P1 p1)
134 : functor_(functor), 219 : functor_(functor),
135 p1_(p1) {} 220 p1_(p1) {}
(...skipping 22 matching lines...) Expand all
158 template <class ObjectT, class R, 243 template <class ObjectT, class R,
159 class P1> 244 class P1>
160 MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1> 245 MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>
161 Bind(FP_T(method), const ObjectT* object, 246 Bind(FP_T(method), const ObjectT* object,
162 typename detail::identity<P1>::type p1) { 247 typename detail::identity<P1>::type p1) {
163 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>( 248 return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>(
164 method, object, p1); 249 method, object, p1);
165 } 250 }
166 251
167 #undef FP_T 252 #undef FP_T
253 #define FP_T(x) R (ObjectT::*x)(P1)
254
255 template <class ObjectT, class R,
256 class P1>
257 MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>
258 Bind(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
168 #define FP_T(x) R (*x)(P1) 265 #define FP_T(x) R (*x)(P1)
169 266
170 template <class R, 267 template <class R,
171 class P1> 268 class P1>
172 Functor1<FP_T(NONAME), R, P1> 269 Functor1<FP_T(NONAME), R, P1>
173 Bind(FP_T(function), 270 Bind(FP_T(function),
174 typename detail::identity<P1>::type p1) { 271 typename detail::identity<P1>::type p1) {
175 return Functor1<FP_T(NONAME), R, P1>( 272 return Functor1<FP_T(NONAME), R, P1>(
176 function, p1); 273 function, p1);
177 } 274 }
178 275
179 #undef FP_T 276 #undef FP_T
180 277
181 template <class ObjectT, class MethodT, class R, 278 template <class ObjectT, class MethodT, class R,
182 class P1, 279 class P1,
183 class P2> 280 class P2>
184 class MethodFunctor2 { 281 class MethodFunctor2 {
185 public: 282 public:
186 MethodFunctor2(MethodT method, ObjectT* object, 283 MethodFunctor2(MethodT method, ObjectT* object,
187 P1 p1, 284 P1 p1,
188 P2 p2) 285 P2 p2)
189 : method_(method), object_(object), 286 : method_(method), object_(object),
190 p1_(p1), 287 p1_(p1),
191 p2_(p2) {} 288 p2_(p2) {}
192 R operator()() const { 289 R operator()() const {
193 return (object_->*method_)(p1_, p2_); } 290 return (object_->*method_)(p1_, p2_); }
194 private: 291 private:
195 MethodT method_; 292 MethodT method_;
196 ObjectT* object_; 293 typename detail::PointerType<ObjectT>::type object_;
197 P1 p1_; 294 P1 p1_;
198 P2 p2_; 295 P2 p2_;
199 }; 296 };
200 297
201 template <class FunctorT, class R, 298 template <class FunctorT, class R,
202 class P1, 299 class P1,
203 class P2> 300 class P2>
204 class Functor2 { 301 class Functor2 {
205 public: 302 public:
206 Functor2(const FunctorT& functor, P1 p1, P2 p2) 303 Functor2(const FunctorT& functor, P1 p1, P2 p2)
(...skipping 30 matching lines...) Expand all
237 class P2> 334 class P2>
238 MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2> 335 MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>
239 Bind(FP_T(method), const ObjectT* object, 336 Bind(FP_T(method), const ObjectT* object,
240 typename detail::identity<P1>::type p1, 337 typename detail::identity<P1>::type p1,
241 typename detail::identity<P2>::type p2) { 338 typename detail::identity<P2>::type p2) {
242 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>( 339 return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>(
243 method, object, p1, p2); 340 method, object, p1, p2);
244 } 341 }
245 342
246 #undef FP_T 343 #undef FP_T
344 #define FP_T(x) R (ObjectT::*x)(P1, P2)
345
346 template <class ObjectT, class R,
347 class P1,
348 class P2>
349 MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>
350 Bind(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
247 #define FP_T(x) R (*x)(P1, P2) 358 #define FP_T(x) R (*x)(P1, P2)
248 359
249 template <class R, 360 template <class R,
250 class P1, 361 class P1,
251 class P2> 362 class P2>
252 Functor2<FP_T(NONAME), R, P1, P2> 363 Functor2<FP_T(NONAME), R, P1, P2>
253 Bind(FP_T(function), 364 Bind(FP_T(function),
254 typename detail::identity<P1>::type p1, 365 typename detail::identity<P1>::type p1,
255 typename detail::identity<P2>::type p2) { 366 typename detail::identity<P2>::type p2) {
256 return Functor2<FP_T(NONAME), R, P1, P2>( 367 return Functor2<FP_T(NONAME), R, P1, P2>(
(...skipping 13 matching lines...) Expand all
270 P2 p2, 381 P2 p2,
271 P3 p3) 382 P3 p3)
272 : method_(method), object_(object), 383 : method_(method), object_(object),
273 p1_(p1), 384 p1_(p1),
274 p2_(p2), 385 p2_(p2),
275 p3_(p3) {} 386 p3_(p3) {}
276 R operator()() const { 387 R operator()() const {
277 return (object_->*method_)(p1_, p2_, p3_); } 388 return (object_->*method_)(p1_, p2_, p3_); }
278 private: 389 private:
279 MethodT method_; 390 MethodT method_;
280 ObjectT* object_; 391 typename detail::PointerType<ObjectT>::type object_;
281 P1 p1_; 392 P1 p1_;
282 P2 p2_; 393 P2 p2_;
283 P3 p3_; 394 P3 p3_;
284 }; 395 };
285 396
286 template <class FunctorT, class R, 397 template <class FunctorT, class R,
287 class P1, 398 class P1,
288 class P2, 399 class P2,
289 class P3> 400 class P3>
290 class Functor3 { 401 class Functor3 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3> 440 MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>
330 Bind(FP_T(method), const ObjectT* object, 441 Bind(FP_T(method), const ObjectT* object,
331 typename detail::identity<P1>::type p1, 442 typename detail::identity<P1>::type p1,
332 typename detail::identity<P2>::type p2, 443 typename detail::identity<P2>::type p2,
333 typename detail::identity<P3>::type p3) { 444 typename detail::identity<P3>::type p3) {
334 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>( 445 return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>(
335 method, object, p1, p2, p3); 446 method, object, p1, p2, p3);
336 } 447 }
337 448
338 #undef FP_T 449 #undef FP_T
450 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3)
451
452 template <class ObjectT, class R,
453 class P1,
454 class P2,
455 class P3>
456 MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>
457 Bind(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
339 #define FP_T(x) R (*x)(P1, P2, P3) 466 #define FP_T(x) R (*x)(P1, P2, P3)
340 467
341 template <class R, 468 template <class R,
342 class P1, 469 class P1,
343 class P2, 470 class P2,
344 class P3> 471 class P3>
345 Functor3<FP_T(NONAME), R, P1, P2, P3> 472 Functor3<FP_T(NONAME), R, P1, P2, P3>
346 Bind(FP_T(function), 473 Bind(FP_T(function),
347 typename detail::identity<P1>::type p1, 474 typename detail::identity<P1>::type p1,
348 typename detail::identity<P2>::type p2, 475 typename detail::identity<P2>::type p2,
(...skipping 18 matching lines...) Expand all
367 P4 p4) 494 P4 p4)
368 : method_(method), object_(object), 495 : method_(method), object_(object),
369 p1_(p1), 496 p1_(p1),
370 p2_(p2), 497 p2_(p2),
371 p3_(p3), 498 p3_(p3),
372 p4_(p4) {} 499 p4_(p4) {}
373 R operator()() const { 500 R operator()() const {
374 return (object_->*method_)(p1_, p2_, p3_, p4_); } 501 return (object_->*method_)(p1_, p2_, p3_, p4_); }
375 private: 502 private:
376 MethodT method_; 503 MethodT method_;
377 ObjectT* object_; 504 typename detail::PointerType<ObjectT>::type object_;
378 P1 p1_; 505 P1 p1_;
379 P2 p2_; 506 P2 p2_;
380 P3 p3_; 507 P3 p3_;
381 P4 p4_; 508 P4 p4_;
382 }; 509 };
383 510
384 template <class FunctorT, class R, 511 template <class FunctorT, class R,
385 class P1, 512 class P1,
386 class P2, 513 class P2,
387 class P3, 514 class P3,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 Bind(FP_T(method), const ObjectT* object, 561 Bind(FP_T(method), const ObjectT* object,
435 typename detail::identity<P1>::type p1, 562 typename detail::identity<P1>::type p1,
436 typename detail::identity<P2>::type p2, 563 typename detail::identity<P2>::type p2,
437 typename detail::identity<P3>::type p3, 564 typename detail::identity<P3>::type p3,
438 typename detail::identity<P4>::type p4) { 565 typename detail::identity<P4>::type p4) {
439 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>( 566 return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>(
440 method, object, p1, p2, p3, p4); 567 method, object, p1, p2, p3, p4);
441 } 568 }
442 569
443 #undef FP_T 570 #undef FP_T
571 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4)
572
573 template <class ObjectT, class R,
574 class P1,
575 class P2,
576 class P3,
577 class P4>
578 MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>
579 Bind(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
444 #define FP_T(x) R (*x)(P1, P2, P3, P4) 589 #define FP_T(x) R (*x)(P1, P2, P3, P4)
445 590
446 template <class R, 591 template <class R,
447 class P1, 592 class P1,
448 class P2, 593 class P2,
449 class P3, 594 class P3,
450 class P4> 595 class P4>
451 Functor4<FP_T(NONAME), R, P1, P2, P3, P4> 596 Functor4<FP_T(NONAME), R, P1, P2, P3, P4>
452 Bind(FP_T(function), 597 Bind(FP_T(function),
453 typename detail::identity<P1>::type p1, 598 typename detail::identity<P1>::type p1,
(...skipping 23 matching lines...) Expand all
477 : method_(method), object_(object), 622 : method_(method), object_(object),
478 p1_(p1), 623 p1_(p1),
479 p2_(p2), 624 p2_(p2),
480 p3_(p3), 625 p3_(p3),
481 p4_(p4), 626 p4_(p4),
482 p5_(p5) {} 627 p5_(p5) {}
483 R operator()() const { 628 R operator()() const {
484 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); } 629 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); }
485 private: 630 private:
486 MethodT method_; 631 MethodT method_;
487 ObjectT* object_; 632 typename detail::PointerType<ObjectT>::type object_;
488 P1 p1_; 633 P1 p1_;
489 P2 p2_; 634 P2 p2_;
490 P3 p3_; 635 P3 p3_;
491 P4 p4_; 636 P4 p4_;
492 P5 p5_; 637 P5 p5_;
493 }; 638 };
494 639
495 template <class FunctorT, class R, 640 template <class FunctorT, class R,
496 class P1, 641 class P1,
497 class P2, 642 class P2,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 typename detail::identity<P1>::type p1, 697 typename detail::identity<P1>::type p1,
553 typename detail::identity<P2>::type p2, 698 typename detail::identity<P2>::type p2,
554 typename detail::identity<P3>::type p3, 699 typename detail::identity<P3>::type p3,
555 typename detail::identity<P4>::type p4, 700 typename detail::identity<P4>::type p4,
556 typename detail::identity<P5>::type p5) { 701 typename detail::identity<P5>::type p5) {
557 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>( 702 return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>(
558 method, object, p1, p2, p3, p4, p5); 703 method, object, p1, p2, p3, p4, p5);
559 } 704 }
560 705
561 #undef FP_T 706 #undef FP_T
707 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5)
708
709 template <class ObjectT, class R,
710 class P1,
711 class P2,
712 class P3,
713 class P4,
714 class P5>
715 MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>
716 Bind(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
562 #define FP_T(x) R (*x)(P1, P2, P3, P4, P5) 727 #define FP_T(x) R (*x)(P1, P2, P3, P4, P5)
563 728
564 template <class R, 729 template <class R,
565 class P1, 730 class P1,
566 class P2, 731 class P2,
567 class P3, 732 class P3,
568 class P4, 733 class P4,
569 class P5> 734 class P5>
570 Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5> 735 Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>
571 Bind(FP_T(function), 736 Bind(FP_T(function),
(...skipping 28 matching lines...) Expand all
600 p1_(p1), 765 p1_(p1),
601 p2_(p2), 766 p2_(p2),
602 p3_(p3), 767 p3_(p3),
603 p4_(p4), 768 p4_(p4),
604 p5_(p5), 769 p5_(p5),
605 p6_(p6) {} 770 p6_(p6) {}
606 R operator()() const { 771 R operator()() const {
607 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_); } 772 return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_); }
608 private: 773 private:
609 MethodT method_; 774 MethodT method_;
610 ObjectT* object_; 775 typename detail::PointerType<ObjectT>::type object_;
611 P1 p1_; 776 P1 p1_;
612 P2 p2_; 777 P2 p2_;
613 P3 p3_; 778 P3 p3_;
614 P4 p4_; 779 P4 p4_;
615 P5 p5_; 780 P5 p5_;
616 P6 p6_; 781 P6 p6_;
617 }; 782 };
618 783
619 template <class FunctorT, class R, 784 template <class FunctorT, class R,
620 class P1, 785 class P1,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 typename detail::identity<P2>::type p2, 848 typename detail::identity<P2>::type p2,
684 typename detail::identity<P3>::type p3, 849 typename detail::identity<P3>::type p3,
685 typename detail::identity<P4>::type p4, 850 typename detail::identity<P4>::type p4,
686 typename detail::identity<P5>::type p5, 851 typename detail::identity<P5>::type p5,
687 typename detail::identity<P6>::type p6) { 852 typename detail::identity<P6>::type p6) {
688 return MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>( 853 return MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
689 method, object, p1, p2, p3, p4, p5, p6); 854 method, object, p1, p2, p3, p4, p5, p6);
690 } 855 }
691 856
692 #undef FP_T 857 #undef FP_T
858 #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6)
859
860 template <class ObjectT, class R,
861 class P1,
862 class P2,
863 class P3,
864 class P4,
865 class P5,
866 class P6>
867 MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
868 Bind(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
693 #define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6) 880 #define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6)
694 881
695 template <class R, 882 template <class R,
696 class P1, 883 class P1,
697 class P2, 884 class P2,
698 class P3, 885 class P3,
699 class P4, 886 class P4,
700 class P5, 887 class P5,
701 class P6> 888 class P6>
702 Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6> 889 Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>
703 Bind(FP_T(function), 890 Bind(FP_T(function),
704 typename detail::identity<P1>::type p1, 891 typename detail::identity<P1>::type p1,
705 typename detail::identity<P2>::type p2, 892 typename detail::identity<P2>::type p2,
706 typename detail::identity<P3>::type p3, 893 typename detail::identity<P3>::type p3,
707 typename detail::identity<P4>::type p4, 894 typename detail::identity<P4>::type p4,
708 typename detail::identity<P5>::type p5, 895 typename detail::identity<P5>::type p5,
709 typename detail::identity<P6>::type p6) { 896 typename detail::identity<P6>::type p6) {
710 return Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>( 897 return Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>(
711 function, p1, p2, p3, p4, p5, p6); 898 function, p1, p2, p3, p4, p5, p6);
712 } 899 }
713 900
714 #undef FP_T 901 #undef FP_T
715 902
716 } // namespace rtc 903 } // namespace rtc
717 904
718 #undef NONAME 905 #undef NONAME
719 906
720 #endif // WEBRTC_BASE_BIND_H_ 907 #endif // WEBRTC_BASE_BIND_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/bind.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698