Updating trunk VERSION from 935.0 to 936.0
[chromium-blink-merge.git] / base / bind_internal.h
blob7beba516f6f2407d42517dbecb06fbabf6afdff9
1 // This file was GENERATED by command:
2 // pump.py bind_internal.h.pump
3 // DO NOT EDIT BY HAND!!!
7 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
8 // Use of this source code is governed by a BSD-style license that can be
9 // found in the LICENSE file.
11 #ifndef BASE_BIND_INTERNAL_H_
12 #define BASE_BIND_INTERNAL_H_
13 #pragma once
15 #include "base/bind_helpers.h"
16 #include "base/callback_internal.h"
17 #include "base/memory/raw_scoped_refptr_mismatch_checker.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/template_util.h"
20 #include "build/build_config.h"
22 #if defined(OS_WIN)
23 #include "base/bind_internal_win.h"
24 #endif
26 namespace base {
27 namespace internal {
29 // The method by which a function is invoked is determined by 3 different
30 // dimensions:
32 // 1) The type of function (normal or method).
33 // 2) The arity of the function.
34 // 3) The number of bound parameters.
36 // The templates below handle the determination of each of these dimensions.
37 // In brief:
39 // FunctionTraits<> -- Provides a normalied signature, and other traits.
40 // InvokerN<> -- Provides a DoInvoke() function that actually executes
41 // a calback.
42 // InvokerStorageN<> -- Provides storage for the bound parameters, and
43 // typedefs to the above.
44 // IsWeakMethod<> -- Determines if we are binding a method to a WeakPtr<>.
46 // More details about the design of each class is included in a comment closer
47 // to their defition.
50 // IsWeakMethod determines if we are binding a method to a WeakPtr<> for an
51 // object. It is used to select an InvokerN that will no-op itself in the
52 // event the WeakPtr<> for the target object is invalidated.
53 template <bool IsMethod, typename T>
54 struct IsWeakMethod : public false_type {};
56 template <typename T>
57 struct IsWeakMethod<true, WeakPtr<T> > : public true_type {};
59 // FunctionTraits<>
61 // The FunctionTraits<> template determines the type of function, and also
62 // creates a NormalizedType used to select the InvokerN classes. It turns out
63 // that syntactically, you only really have 2 variations when invoking a
64 // funciton pointer: normal, and method. One is invoked func_ptr(arg1). The
65 // other is invoked (*obj_->method_ptr(arg1)).
67 // However, in the type system, there are many more distinctions. In standard
68 // C++, there's all variations of const, and volatile on the function pointer.
69 // In Windows, there are additional calling conventions (eg., __stdcall,
70 // __fastcall, etc.). FunctionTraits<> handles categorizing each of these into
71 // a normalized signature.
73 // Having a NormalizedSignature signature, reduces the combinatoric
74 // complexity of defintions for the InvokerN<> later. Even though there are
75 // only 2 syntactic variations on invoking a function, without normalizing the
76 // signature, there would need to be one specialization of InvokerN for each
77 // unique (function_type, bound_arg, unbound_args) tuple in order to match all
78 // function signatures.
80 // By normalizing the function signature, we reduce function_type to exactly 2.
82 template <typename Sig>
83 struct FunctionTraits;
85 // Function: Arity 0.
86 template <typename R>
87 struct FunctionTraits<R(*)()> {
88 typedef R (*NormalizedSig)();
89 typedef false_type IsMethod;
91 typedef R Return;
95 // Method: Arity 0.
96 template <typename R, typename T>
97 struct FunctionTraits<R(T::*)()> {
98 typedef R (T::*NormalizedSig)();
99 typedef true_type IsMethod;
101 typedef R Return;
103 // Target type for each bound parameter.
104 typedef T B1;
108 // Const Method: Arity 0.
109 template <typename R, typename T>
110 struct FunctionTraits<R(T::*)() const> {
111 typedef R (T::*NormalizedSig)();
112 typedef true_type IsMethod;
114 typedef R Return;
116 // Target type for each bound parameter.
117 typedef T B1;
121 // Function: Arity 1.
122 template <typename R, typename X1>
123 struct FunctionTraits<R(*)(X1)> {
124 typedef R (*NormalizedSig)(X1);
125 typedef false_type IsMethod;
127 typedef R Return;
129 // Target type for each bound parameter.
130 typedef X1 B1;
134 // Method: Arity 1.
135 template <typename R, typename T, typename X1>
136 struct FunctionTraits<R(T::*)(X1)> {
137 typedef R (T::*NormalizedSig)(X1);
138 typedef true_type IsMethod;
140 typedef R Return;
142 // Target type for each bound parameter.
143 typedef T B1;
144 typedef X1 B2;
148 // Const Method: Arity 1.
149 template <typename R, typename T, typename X1>
150 struct FunctionTraits<R(T::*)(X1) const> {
151 typedef R (T::*NormalizedSig)(X1);
152 typedef true_type IsMethod;
154 typedef R Return;
156 // Target type for each bound parameter.
157 typedef T B1;
158 typedef X1 B2;
162 // Function: Arity 2.
163 template <typename R, typename X1, typename X2>
164 struct FunctionTraits<R(*)(X1, X2)> {
165 typedef R (*NormalizedSig)(X1, X2);
166 typedef false_type IsMethod;
168 typedef R Return;
170 // Target type for each bound parameter.
171 typedef X1 B1;
172 typedef X2 B2;
176 // Method: Arity 2.
177 template <typename R, typename T, typename X1, typename X2>
178 struct FunctionTraits<R(T::*)(X1, X2)> {
179 typedef R (T::*NormalizedSig)(X1, X2);
180 typedef true_type IsMethod;
182 typedef R Return;
184 // Target type for each bound parameter.
185 typedef T B1;
186 typedef X1 B2;
187 typedef X2 B3;
191 // Const Method: Arity 2.
192 template <typename R, typename T, typename X1, typename X2>
193 struct FunctionTraits<R(T::*)(X1, X2) const> {
194 typedef R (T::*NormalizedSig)(X1, X2);
195 typedef true_type IsMethod;
197 typedef R Return;
199 // Target type for each bound parameter.
200 typedef T B1;
201 typedef X1 B2;
202 typedef X2 B3;
206 // Function: Arity 3.
207 template <typename R, typename X1, typename X2, typename X3>
208 struct FunctionTraits<R(*)(X1, X2, X3)> {
209 typedef R (*NormalizedSig)(X1, X2, X3);
210 typedef false_type IsMethod;
212 typedef R Return;
214 // Target type for each bound parameter.
215 typedef X1 B1;
216 typedef X2 B2;
217 typedef X3 B3;
221 // Method: Arity 3.
222 template <typename R, typename T, typename X1, typename X2, typename X3>
223 struct FunctionTraits<R(T::*)(X1, X2, X3)> {
224 typedef R (T::*NormalizedSig)(X1, X2, X3);
225 typedef true_type IsMethod;
227 typedef R Return;
229 // Target type for each bound parameter.
230 typedef T B1;
231 typedef X1 B2;
232 typedef X2 B3;
233 typedef X3 B4;
237 // Const Method: Arity 3.
238 template <typename R, typename T, typename X1, typename X2, typename X3>
239 struct FunctionTraits<R(T::*)(X1, X2, X3) const> {
240 typedef R (T::*NormalizedSig)(X1, X2, X3);
241 typedef true_type IsMethod;
243 typedef R Return;
245 // Target type for each bound parameter.
246 typedef T B1;
247 typedef X1 B2;
248 typedef X2 B3;
249 typedef X3 B4;
253 // Function: Arity 4.
254 template <typename R, typename X1, typename X2, typename X3, typename X4>
255 struct FunctionTraits<R(*)(X1, X2, X3, X4)> {
256 typedef R (*NormalizedSig)(X1, X2, X3, X4);
257 typedef false_type IsMethod;
259 typedef R Return;
261 // Target type for each bound parameter.
262 typedef X1 B1;
263 typedef X2 B2;
264 typedef X3 B3;
265 typedef X4 B4;
269 // Method: Arity 4.
270 template <typename R, typename T, typename X1, typename X2, typename X3,
271 typename X4>
272 struct FunctionTraits<R(T::*)(X1, X2, X3, X4)> {
273 typedef R (T::*NormalizedSig)(X1, X2, X3, X4);
274 typedef true_type IsMethod;
276 typedef R Return;
278 // Target type for each bound parameter.
279 typedef T B1;
280 typedef X1 B2;
281 typedef X2 B3;
282 typedef X3 B4;
283 typedef X4 B5;
287 // Const Method: Arity 4.
288 template <typename R, typename T, typename X1, typename X2, typename X3,
289 typename X4>
290 struct FunctionTraits<R(T::*)(X1, X2, X3, X4) const> {
291 typedef R (T::*NormalizedSig)(X1, X2, X3, X4);
292 typedef true_type IsMethod;
294 typedef R Return;
296 // Target type for each bound parameter.
297 typedef T B1;
298 typedef X1 B2;
299 typedef X2 B3;
300 typedef X3 B4;
301 typedef X4 B5;
305 // Function: Arity 5.
306 template <typename R, typename X1, typename X2, typename X3, typename X4,
307 typename X5>
308 struct FunctionTraits<R(*)(X1, X2, X3, X4, X5)> {
309 typedef R (*NormalizedSig)(X1, X2, X3, X4, X5);
310 typedef false_type IsMethod;
312 typedef R Return;
314 // Target type for each bound parameter.
315 typedef X1 B1;
316 typedef X2 B2;
317 typedef X3 B3;
318 typedef X4 B4;
319 typedef X5 B5;
323 // Method: Arity 5.
324 template <typename R, typename T, typename X1, typename X2, typename X3,
325 typename X4, typename X5>
326 struct FunctionTraits<R(T::*)(X1, X2, X3, X4, X5)> {
327 typedef R (T::*NormalizedSig)(X1, X2, X3, X4, X5);
328 typedef true_type IsMethod;
330 typedef R Return;
332 // Target type for each bound parameter.
333 typedef T B1;
334 typedef X1 B2;
335 typedef X2 B3;
336 typedef X3 B4;
337 typedef X4 B5;
338 typedef X5 B6;
342 // Const Method: Arity 5.
343 template <typename R, typename T, typename X1, typename X2, typename X3,
344 typename X4, typename X5>
345 struct FunctionTraits<R(T::*)(X1, X2, X3, X4, X5) const> {
346 typedef R (T::*NormalizedSig)(X1, X2, X3, X4, X5);
347 typedef true_type IsMethod;
349 typedef R Return;
351 // Target type for each bound parameter.
352 typedef T B1;
353 typedef X1 B2;
354 typedef X2 B3;
355 typedef X3 B4;
356 typedef X4 B5;
357 typedef X5 B6;
361 // Function: Arity 6.
362 template <typename R, typename X1, typename X2, typename X3, typename X4,
363 typename X5, typename X6>
364 struct FunctionTraits<R(*)(X1, X2, X3, X4, X5, X6)> {
365 typedef R (*NormalizedSig)(X1, X2, X3, X4, X5, X6);
366 typedef false_type IsMethod;
368 typedef R Return;
370 // Target type for each bound parameter.
371 typedef X1 B1;
372 typedef X2 B2;
373 typedef X3 B3;
374 typedef X4 B4;
375 typedef X5 B5;
376 typedef X6 B6;
380 // Method: Arity 6.
381 template <typename R, typename T, typename X1, typename X2, typename X3,
382 typename X4, typename X5, typename X6>
383 struct FunctionTraits<R(T::*)(X1, X2, X3, X4, X5, X6)> {
384 typedef R (T::*NormalizedSig)(X1, X2, X3, X4, X5, X6);
385 typedef true_type IsMethod;
387 typedef R Return;
389 // Target type for each bound parameter.
390 typedef T B1;
391 typedef X1 B2;
392 typedef X2 B3;
393 typedef X3 B4;
394 typedef X4 B5;
395 typedef X5 B6;
396 typedef X6 B7;
400 // Const Method: Arity 6.
401 template <typename R, typename T, typename X1, typename X2, typename X3,
402 typename X4, typename X5, typename X6>
403 struct FunctionTraits<R(T::*)(X1, X2, X3, X4, X5, X6) const> {
404 typedef R (T::*NormalizedSig)(X1, X2, X3, X4, X5, X6);
405 typedef true_type IsMethod;
407 typedef R Return;
409 // Target type for each bound parameter.
410 typedef T B1;
411 typedef X1 B2;
412 typedef X2 B3;
413 typedef X3 B4;
414 typedef X4 B5;
415 typedef X5 B6;
416 typedef X6 B7;
420 // InvokerN<>
422 // The InvokerN templates contain a static DoInvoke() function that is the key
423 // to implementing type erasure in the Callback() classes.
425 // DoInvoke() is a static function with a fixed signature that is independent
426 // of StorageType; its first argument is a pointer to the non-templated common
427 // baseclass of StorageType. This lets us store pointer to DoInvoke() in a
428 // function pointer that has knowledge of the specific StorageType, and thus
429 // no knowledge of the bound function and bound parameter types.
431 // As long as we ensure that DoInvoke() is only used with pointers there were
432 // upcasted from the correct StorageType, we can be sure that execution is
433 // safe.
435 // The InvokerN templates are the only point that knows the number of bound
436 // and unbound arguments. This is intentional because it allows the other
437 // templates classes in the system to only have as many specializations as
438 // the max arity of function we wish to support.
440 template <bool IsWeak, typename StorageType, typename NormalizedSig>
441 struct Invoker0;
443 // Function: Arity 0 -> 0.
444 template <typename StorageType, typename R>
445 struct Invoker0<false, StorageType, R(*)()> {
446 typedef R(*DoInvokeType)(
447 internal::InvokerStorageBase*);
449 static R DoInvoke(InvokerStorageBase* base) {
450 StorageType* invoker = static_cast<StorageType*>(base);
451 return invoker->f_();
455 // Function: Arity 1 -> 1.
456 template <typename StorageType, typename R,typename X1>
457 struct Invoker0<false, StorageType, R(*)(X1)> {
458 typedef R(*DoInvokeType)(
459 internal::InvokerStorageBase*,
460 typename internal::ParamTraits<X1>::ForwardType);
462 static R DoInvoke(InvokerStorageBase* base,
463 typename internal::ParamTraits<X1>::ForwardType x1) {
464 StorageType* invoker = static_cast<StorageType*>(base);
465 return invoker->f_(x1);
469 // Function: Arity 2 -> 2.
470 template <typename StorageType, typename R,typename X1, typename X2>
471 struct Invoker0<false, StorageType, R(*)(X1, X2)> {
472 typedef R(*DoInvokeType)(
473 internal::InvokerStorageBase*,
474 typename internal::ParamTraits<X1>::ForwardType,
475 typename internal::ParamTraits<X2>::ForwardType);
477 static R DoInvoke(InvokerStorageBase* base,
478 typename internal::ParamTraits<X1>::ForwardType x1,
479 typename internal::ParamTraits<X2>::ForwardType x2) {
480 StorageType* invoker = static_cast<StorageType*>(base);
481 return invoker->f_(x1, x2);
485 // Function: Arity 3 -> 3.
486 template <typename StorageType, typename R,typename X1, typename X2,
487 typename X3>
488 struct Invoker0<false, StorageType, R(*)(X1, X2, X3)> {
489 typedef R(*DoInvokeType)(
490 internal::InvokerStorageBase*,
491 typename internal::ParamTraits<X1>::ForwardType,
492 typename internal::ParamTraits<X2>::ForwardType,
493 typename internal::ParamTraits<X3>::ForwardType);
495 static R DoInvoke(InvokerStorageBase* base,
496 typename internal::ParamTraits<X1>::ForwardType x1,
497 typename internal::ParamTraits<X2>::ForwardType x2,
498 typename internal::ParamTraits<X3>::ForwardType x3) {
499 StorageType* invoker = static_cast<StorageType*>(base);
500 return invoker->f_(x1, x2, x3);
504 // Function: Arity 4 -> 4.
505 template <typename StorageType, typename R,typename X1, typename X2,
506 typename X3, typename X4>
507 struct Invoker0<false, StorageType, R(*)(X1, X2, X3, X4)> {
508 typedef R(*DoInvokeType)(
509 internal::InvokerStorageBase*,
510 typename internal::ParamTraits<X1>::ForwardType,
511 typename internal::ParamTraits<X2>::ForwardType,
512 typename internal::ParamTraits<X3>::ForwardType,
513 typename internal::ParamTraits<X4>::ForwardType);
515 static R DoInvoke(InvokerStorageBase* base,
516 typename internal::ParamTraits<X1>::ForwardType x1,
517 typename internal::ParamTraits<X2>::ForwardType x2,
518 typename internal::ParamTraits<X3>::ForwardType x3,
519 typename internal::ParamTraits<X4>::ForwardType x4) {
520 StorageType* invoker = static_cast<StorageType*>(base);
521 return invoker->f_(x1, x2, x3, x4);
525 // Function: Arity 5 -> 5.
526 template <typename StorageType, typename R,typename X1, typename X2,
527 typename X3, typename X4, typename X5>
528 struct Invoker0<false, StorageType, R(*)(X1, X2, X3, X4, X5)> {
529 typedef R(*DoInvokeType)(
530 internal::InvokerStorageBase*,
531 typename internal::ParamTraits<X1>::ForwardType,
532 typename internal::ParamTraits<X2>::ForwardType,
533 typename internal::ParamTraits<X3>::ForwardType,
534 typename internal::ParamTraits<X4>::ForwardType,
535 typename internal::ParamTraits<X5>::ForwardType);
537 static R DoInvoke(InvokerStorageBase* base,
538 typename internal::ParamTraits<X1>::ForwardType x1,
539 typename internal::ParamTraits<X2>::ForwardType x2,
540 typename internal::ParamTraits<X3>::ForwardType x3,
541 typename internal::ParamTraits<X4>::ForwardType x4,
542 typename internal::ParamTraits<X5>::ForwardType x5) {
543 StorageType* invoker = static_cast<StorageType*>(base);
544 return invoker->f_(x1, x2, x3, x4, x5);
548 // Function: Arity 6 -> 6.
549 template <typename StorageType, typename R,typename X1, typename X2,
550 typename X3, typename X4, typename X5, typename X6>
551 struct Invoker0<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
552 typedef R(*DoInvokeType)(
553 internal::InvokerStorageBase*,
554 typename internal::ParamTraits<X1>::ForwardType,
555 typename internal::ParamTraits<X2>::ForwardType,
556 typename internal::ParamTraits<X3>::ForwardType,
557 typename internal::ParamTraits<X4>::ForwardType,
558 typename internal::ParamTraits<X5>::ForwardType,
559 typename internal::ParamTraits<X6>::ForwardType);
561 static R DoInvoke(InvokerStorageBase* base,
562 typename internal::ParamTraits<X1>::ForwardType x1,
563 typename internal::ParamTraits<X2>::ForwardType x2,
564 typename internal::ParamTraits<X3>::ForwardType x3,
565 typename internal::ParamTraits<X4>::ForwardType x4,
566 typename internal::ParamTraits<X5>::ForwardType x5,
567 typename internal::ParamTraits<X6>::ForwardType x6) {
568 StorageType* invoker = static_cast<StorageType*>(base);
569 return invoker->f_(x1, x2, x3, x4, x5, x6);
573 template <bool IsWeak, typename StorageType, typename NormalizedSig>
574 struct Invoker1;
576 // Function: Arity 1 -> 0.
577 template <typename StorageType, typename R,typename X1>
578 struct Invoker1<false, StorageType, R(*)(X1)> {
579 typedef R(*DoInvokeType)(
580 internal::InvokerStorageBase*);
582 static R DoInvoke(InvokerStorageBase* base) {
583 StorageType* invoker = static_cast<StorageType*>(base);
584 return invoker->f_(Unwrap(invoker->p1_));
588 // Method: Arity 0 -> 0.
589 template <typename StorageType, typename R, typename T>
590 struct Invoker1<false, StorageType, R(T::*)()> {
591 typedef R(*DoInvokeType)(
592 internal::InvokerStorageBase*);
594 static R DoInvoke(InvokerStorageBase* base) {
595 StorageType* invoker = static_cast<StorageType*>(base);
596 return (Unwrap(invoker->p1_)->*invoker->f_)();
600 // WeakPtr Method: Arity 0 -> 0.
601 template <typename StorageType, typename T>
602 struct Invoker1<true, StorageType, void(T::*)()> {
603 typedef void(*DoInvokeType)(
604 internal::InvokerStorageBase*);
606 static void DoInvoke(InvokerStorageBase* base) {
607 StorageType* invoker = static_cast<StorageType*>(base);
608 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
609 if (!weak_ptr.get()) {
610 return;
612 (weak_ptr->*invoker->f_)();
616 // Function: Arity 2 -> 1.
617 template <typename StorageType, typename R,typename X1, typename X2>
618 struct Invoker1<false, StorageType, R(*)(X1, X2)> {
619 typedef R(*DoInvokeType)(
620 internal::InvokerStorageBase*,
621 typename internal::ParamTraits<X2>::ForwardType);
623 static R DoInvoke(InvokerStorageBase* base,
624 typename internal::ParamTraits<X2>::ForwardType x2) {
625 StorageType* invoker = static_cast<StorageType*>(base);
626 return invoker->f_(Unwrap(invoker->p1_), x2);
630 // Method: Arity 1 -> 1.
631 template <typename StorageType, typename R, typename T, typename X1>
632 struct Invoker1<false, StorageType, R(T::*)(X1)> {
633 typedef R(*DoInvokeType)(
634 internal::InvokerStorageBase*,
635 typename internal::ParamTraits<X1>::ForwardType);
637 static R DoInvoke(InvokerStorageBase* base,
638 typename internal::ParamTraits<X1>::ForwardType x1) {
639 StorageType* invoker = static_cast<StorageType*>(base);
640 return (Unwrap(invoker->p1_)->*invoker->f_)(x1);
644 // WeakPtr Method: Arity 1 -> 1.
645 template <typename StorageType, typename T, typename X1>
646 struct Invoker1<true, StorageType, void(T::*)(X1)> {
647 typedef void(*DoInvokeType)(
648 internal::InvokerStorageBase*,
649 typename internal::ParamTraits<X1>::ForwardType);
651 static void DoInvoke(InvokerStorageBase* base,
652 typename internal::ParamTraits<X1>::ForwardType x1) {
653 StorageType* invoker = static_cast<StorageType*>(base);
654 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
655 if (!weak_ptr.get()) {
656 return;
658 (weak_ptr->*invoker->f_)(x1);
662 // Function: Arity 3 -> 2.
663 template <typename StorageType, typename R,typename X1, typename X2,
664 typename X3>
665 struct Invoker1<false, StorageType, R(*)(X1, X2, X3)> {
666 typedef R(*DoInvokeType)(
667 internal::InvokerStorageBase*,
668 typename internal::ParamTraits<X2>::ForwardType,
669 typename internal::ParamTraits<X3>::ForwardType);
671 static R DoInvoke(InvokerStorageBase* base,
672 typename internal::ParamTraits<X2>::ForwardType x2,
673 typename internal::ParamTraits<X3>::ForwardType x3) {
674 StorageType* invoker = static_cast<StorageType*>(base);
675 return invoker->f_(Unwrap(invoker->p1_), x2, x3);
679 // Method: Arity 2 -> 2.
680 template <typename StorageType, typename R, typename T, typename X1,
681 typename X2>
682 struct Invoker1<false, StorageType, R(T::*)(X1, X2)> {
683 typedef R(*DoInvokeType)(
684 internal::InvokerStorageBase*,
685 typename internal::ParamTraits<X1>::ForwardType,
686 typename internal::ParamTraits<X2>::ForwardType);
688 static R DoInvoke(InvokerStorageBase* base,
689 typename internal::ParamTraits<X1>::ForwardType x1,
690 typename internal::ParamTraits<X2>::ForwardType x2) {
691 StorageType* invoker = static_cast<StorageType*>(base);
692 return (Unwrap(invoker->p1_)->*invoker->f_)(x1, x2);
696 // WeakPtr Method: Arity 2 -> 2.
697 template <typename StorageType, typename T, typename X1, typename X2>
698 struct Invoker1<true, StorageType, void(T::*)(X1, X2)> {
699 typedef void(*DoInvokeType)(
700 internal::InvokerStorageBase*,
701 typename internal::ParamTraits<X1>::ForwardType,
702 typename internal::ParamTraits<X2>::ForwardType);
704 static void DoInvoke(InvokerStorageBase* base,
705 typename internal::ParamTraits<X1>::ForwardType x1,
706 typename internal::ParamTraits<X2>::ForwardType x2) {
707 StorageType* invoker = static_cast<StorageType*>(base);
708 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
709 if (!weak_ptr.get()) {
710 return;
712 (weak_ptr->*invoker->f_)(x1, x2);
716 // Function: Arity 4 -> 3.
717 template <typename StorageType, typename R,typename X1, typename X2,
718 typename X3, typename X4>
719 struct Invoker1<false, StorageType, R(*)(X1, X2, X3, X4)> {
720 typedef R(*DoInvokeType)(
721 internal::InvokerStorageBase*,
722 typename internal::ParamTraits<X2>::ForwardType,
723 typename internal::ParamTraits<X3>::ForwardType,
724 typename internal::ParamTraits<X4>::ForwardType);
726 static R DoInvoke(InvokerStorageBase* base,
727 typename internal::ParamTraits<X2>::ForwardType x2,
728 typename internal::ParamTraits<X3>::ForwardType x3,
729 typename internal::ParamTraits<X4>::ForwardType x4) {
730 StorageType* invoker = static_cast<StorageType*>(base);
731 return invoker->f_(Unwrap(invoker->p1_), x2, x3, x4);
735 // Method: Arity 3 -> 3.
736 template <typename StorageType, typename R, typename T, typename X1,
737 typename X2, typename X3>
738 struct Invoker1<false, StorageType, R(T::*)(X1, X2, X3)> {
739 typedef R(*DoInvokeType)(
740 internal::InvokerStorageBase*,
741 typename internal::ParamTraits<X1>::ForwardType,
742 typename internal::ParamTraits<X2>::ForwardType,
743 typename internal::ParamTraits<X3>::ForwardType);
745 static R DoInvoke(InvokerStorageBase* base,
746 typename internal::ParamTraits<X1>::ForwardType x1,
747 typename internal::ParamTraits<X2>::ForwardType x2,
748 typename internal::ParamTraits<X3>::ForwardType x3) {
749 StorageType* invoker = static_cast<StorageType*>(base);
750 return (Unwrap(invoker->p1_)->*invoker->f_)(x1, x2, x3);
754 // WeakPtr Method: Arity 3 -> 3.
755 template <typename StorageType, typename T, typename X1, typename X2,
756 typename X3>
757 struct Invoker1<true, StorageType, void(T::*)(X1, X2, X3)> {
758 typedef void(*DoInvokeType)(
759 internal::InvokerStorageBase*,
760 typename internal::ParamTraits<X1>::ForwardType,
761 typename internal::ParamTraits<X2>::ForwardType,
762 typename internal::ParamTraits<X3>::ForwardType);
764 static void DoInvoke(InvokerStorageBase* base,
765 typename internal::ParamTraits<X1>::ForwardType x1,
766 typename internal::ParamTraits<X2>::ForwardType x2,
767 typename internal::ParamTraits<X3>::ForwardType x3) {
768 StorageType* invoker = static_cast<StorageType*>(base);
769 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
770 if (!weak_ptr.get()) {
771 return;
773 (weak_ptr->*invoker->f_)(x1, x2, x3);
777 // Function: Arity 5 -> 4.
778 template <typename StorageType, typename R,typename X1, typename X2,
779 typename X3, typename X4, typename X5>
780 struct Invoker1<false, StorageType, R(*)(X1, X2, X3, X4, X5)> {
781 typedef R(*DoInvokeType)(
782 internal::InvokerStorageBase*,
783 typename internal::ParamTraits<X2>::ForwardType,
784 typename internal::ParamTraits<X3>::ForwardType,
785 typename internal::ParamTraits<X4>::ForwardType,
786 typename internal::ParamTraits<X5>::ForwardType);
788 static R DoInvoke(InvokerStorageBase* base,
789 typename internal::ParamTraits<X2>::ForwardType x2,
790 typename internal::ParamTraits<X3>::ForwardType x3,
791 typename internal::ParamTraits<X4>::ForwardType x4,
792 typename internal::ParamTraits<X5>::ForwardType x5) {
793 StorageType* invoker = static_cast<StorageType*>(base);
794 return invoker->f_(Unwrap(invoker->p1_), x2, x3, x4, x5);
798 // Method: Arity 4 -> 4.
799 template <typename StorageType, typename R, typename T, typename X1,
800 typename X2, typename X3, typename X4>
801 struct Invoker1<false, StorageType, R(T::*)(X1, X2, X3, X4)> {
802 typedef R(*DoInvokeType)(
803 internal::InvokerStorageBase*,
804 typename internal::ParamTraits<X1>::ForwardType,
805 typename internal::ParamTraits<X2>::ForwardType,
806 typename internal::ParamTraits<X3>::ForwardType,
807 typename internal::ParamTraits<X4>::ForwardType);
809 static R DoInvoke(InvokerStorageBase* base,
810 typename internal::ParamTraits<X1>::ForwardType x1,
811 typename internal::ParamTraits<X2>::ForwardType x2,
812 typename internal::ParamTraits<X3>::ForwardType x3,
813 typename internal::ParamTraits<X4>::ForwardType x4) {
814 StorageType* invoker = static_cast<StorageType*>(base);
815 return (Unwrap(invoker->p1_)->*invoker->f_)(x1, x2, x3, x4);
819 // WeakPtr Method: Arity 4 -> 4.
820 template <typename StorageType, typename T, typename X1, typename X2,
821 typename X3, typename X4>
822 struct Invoker1<true, StorageType, void(T::*)(X1, X2, X3, X4)> {
823 typedef void(*DoInvokeType)(
824 internal::InvokerStorageBase*,
825 typename internal::ParamTraits<X1>::ForwardType,
826 typename internal::ParamTraits<X2>::ForwardType,
827 typename internal::ParamTraits<X3>::ForwardType,
828 typename internal::ParamTraits<X4>::ForwardType);
830 static void DoInvoke(InvokerStorageBase* base,
831 typename internal::ParamTraits<X1>::ForwardType x1,
832 typename internal::ParamTraits<X2>::ForwardType x2,
833 typename internal::ParamTraits<X3>::ForwardType x3,
834 typename internal::ParamTraits<X4>::ForwardType x4) {
835 StorageType* invoker = static_cast<StorageType*>(base);
836 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
837 if (!weak_ptr.get()) {
838 return;
840 (weak_ptr->*invoker->f_)(x1, x2, x3, x4);
844 // Function: Arity 6 -> 5.
845 template <typename StorageType, typename R,typename X1, typename X2,
846 typename X3, typename X4, typename X5, typename X6>
847 struct Invoker1<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
848 typedef R(*DoInvokeType)(
849 internal::InvokerStorageBase*,
850 typename internal::ParamTraits<X2>::ForwardType,
851 typename internal::ParamTraits<X3>::ForwardType,
852 typename internal::ParamTraits<X4>::ForwardType,
853 typename internal::ParamTraits<X5>::ForwardType,
854 typename internal::ParamTraits<X6>::ForwardType);
856 static R DoInvoke(InvokerStorageBase* base,
857 typename internal::ParamTraits<X2>::ForwardType x2,
858 typename internal::ParamTraits<X3>::ForwardType x3,
859 typename internal::ParamTraits<X4>::ForwardType x4,
860 typename internal::ParamTraits<X5>::ForwardType x5,
861 typename internal::ParamTraits<X6>::ForwardType x6) {
862 StorageType* invoker = static_cast<StorageType*>(base);
863 return invoker->f_(Unwrap(invoker->p1_), x2, x3, x4, x5, x6);
867 // Method: Arity 5 -> 5.
868 template <typename StorageType, typename R, typename T, typename X1,
869 typename X2, typename X3, typename X4, typename X5>
870 struct Invoker1<false, StorageType, R(T::*)(X1, X2, X3, X4, X5)> {
871 typedef R(*DoInvokeType)(
872 internal::InvokerStorageBase*,
873 typename internal::ParamTraits<X1>::ForwardType,
874 typename internal::ParamTraits<X2>::ForwardType,
875 typename internal::ParamTraits<X3>::ForwardType,
876 typename internal::ParamTraits<X4>::ForwardType,
877 typename internal::ParamTraits<X5>::ForwardType);
879 static R DoInvoke(InvokerStorageBase* base,
880 typename internal::ParamTraits<X1>::ForwardType x1,
881 typename internal::ParamTraits<X2>::ForwardType x2,
882 typename internal::ParamTraits<X3>::ForwardType x3,
883 typename internal::ParamTraits<X4>::ForwardType x4,
884 typename internal::ParamTraits<X5>::ForwardType x5) {
885 StorageType* invoker = static_cast<StorageType*>(base);
886 return (Unwrap(invoker->p1_)->*invoker->f_)(x1, x2, x3, x4, x5);
890 // WeakPtr Method: Arity 5 -> 5.
891 template <typename StorageType, typename T, typename X1, typename X2,
892 typename X3, typename X4, typename X5>
893 struct Invoker1<true, StorageType, void(T::*)(X1, X2, X3, X4, X5)> {
894 typedef void(*DoInvokeType)(
895 internal::InvokerStorageBase*,
896 typename internal::ParamTraits<X1>::ForwardType,
897 typename internal::ParamTraits<X2>::ForwardType,
898 typename internal::ParamTraits<X3>::ForwardType,
899 typename internal::ParamTraits<X4>::ForwardType,
900 typename internal::ParamTraits<X5>::ForwardType);
902 static void DoInvoke(InvokerStorageBase* base,
903 typename internal::ParamTraits<X1>::ForwardType x1,
904 typename internal::ParamTraits<X2>::ForwardType x2,
905 typename internal::ParamTraits<X3>::ForwardType x3,
906 typename internal::ParamTraits<X4>::ForwardType x4,
907 typename internal::ParamTraits<X5>::ForwardType x5) {
908 StorageType* invoker = static_cast<StorageType*>(base);
909 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
910 if (!weak_ptr.get()) {
911 return;
913 (weak_ptr->*invoker->f_)(x1, x2, x3, x4, x5);
917 template <bool IsWeak, typename StorageType, typename NormalizedSig>
918 struct Invoker2;
920 // Function: Arity 2 -> 0.
921 template <typename StorageType, typename R,typename X1, typename X2>
922 struct Invoker2<false, StorageType, R(*)(X1, X2)> {
923 typedef R(*DoInvokeType)(
924 internal::InvokerStorageBase*);
926 static R DoInvoke(InvokerStorageBase* base) {
927 StorageType* invoker = static_cast<StorageType*>(base);
928 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_));
932 // Method: Arity 1 -> 0.
933 template <typename StorageType, typename R, typename T, typename X1>
934 struct Invoker2<false, StorageType, R(T::*)(X1)> {
935 typedef R(*DoInvokeType)(
936 internal::InvokerStorageBase*);
938 static R DoInvoke(InvokerStorageBase* base) {
939 StorageType* invoker = static_cast<StorageType*>(base);
940 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_));
944 // WeakPtr Method: Arity 1 -> 0.
945 template <typename StorageType, typename T, typename X1>
946 struct Invoker2<true, StorageType, void(T::*)(X1)> {
947 typedef void(*DoInvokeType)(
948 internal::InvokerStorageBase*);
950 static void DoInvoke(InvokerStorageBase* base) {
951 StorageType* invoker = static_cast<StorageType*>(base);
952 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
953 if (!weak_ptr.get()) {
954 return;
956 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_));
960 // Function: Arity 3 -> 1.
961 template <typename StorageType, typename R,typename X1, typename X2,
962 typename X3>
963 struct Invoker2<false, StorageType, R(*)(X1, X2, X3)> {
964 typedef R(*DoInvokeType)(
965 internal::InvokerStorageBase*,
966 typename internal::ParamTraits<X3>::ForwardType);
968 static R DoInvoke(InvokerStorageBase* base,
969 typename internal::ParamTraits<X3>::ForwardType x3) {
970 StorageType* invoker = static_cast<StorageType*>(base);
971 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_), x3);
975 // Method: Arity 2 -> 1.
976 template <typename StorageType, typename R, typename T, typename X1,
977 typename X2>
978 struct Invoker2<false, StorageType, R(T::*)(X1, X2)> {
979 typedef R(*DoInvokeType)(
980 internal::InvokerStorageBase*,
981 typename internal::ParamTraits<X2>::ForwardType);
983 static R DoInvoke(InvokerStorageBase* base,
984 typename internal::ParamTraits<X2>::ForwardType x2) {
985 StorageType* invoker = static_cast<StorageType*>(base);
986 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_), x2);
990 // WeakPtr Method: Arity 2 -> 1.
991 template <typename StorageType, typename T, typename X1, typename X2>
992 struct Invoker2<true, StorageType, void(T::*)(X1, X2)> {
993 typedef void(*DoInvokeType)(
994 internal::InvokerStorageBase*,
995 typename internal::ParamTraits<X2>::ForwardType);
997 static void DoInvoke(InvokerStorageBase* base,
998 typename internal::ParamTraits<X2>::ForwardType x2) {
999 StorageType* invoker = static_cast<StorageType*>(base);
1000 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1001 if (!weak_ptr.get()) {
1002 return;
1004 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), x2);
1008 // Function: Arity 4 -> 2.
1009 template <typename StorageType, typename R,typename X1, typename X2,
1010 typename X3, typename X4>
1011 struct Invoker2<false, StorageType, R(*)(X1, X2, X3, X4)> {
1012 typedef R(*DoInvokeType)(
1013 internal::InvokerStorageBase*,
1014 typename internal::ParamTraits<X3>::ForwardType,
1015 typename internal::ParamTraits<X4>::ForwardType);
1017 static R DoInvoke(InvokerStorageBase* base,
1018 typename internal::ParamTraits<X3>::ForwardType x3,
1019 typename internal::ParamTraits<X4>::ForwardType x4) {
1020 StorageType* invoker = static_cast<StorageType*>(base);
1021 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_), x3, x4);
1025 // Method: Arity 3 -> 2.
1026 template <typename StorageType, typename R, typename T, typename X1,
1027 typename X2, typename X3>
1028 struct Invoker2<false, StorageType, R(T::*)(X1, X2, X3)> {
1029 typedef R(*DoInvokeType)(
1030 internal::InvokerStorageBase*,
1031 typename internal::ParamTraits<X2>::ForwardType,
1032 typename internal::ParamTraits<X3>::ForwardType);
1034 static R DoInvoke(InvokerStorageBase* base,
1035 typename internal::ParamTraits<X2>::ForwardType x2,
1036 typename internal::ParamTraits<X3>::ForwardType x3) {
1037 StorageType* invoker = static_cast<StorageType*>(base);
1038 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_), x2, x3);
1042 // WeakPtr Method: Arity 3 -> 2.
1043 template <typename StorageType, typename T, typename X1, typename X2,
1044 typename X3>
1045 struct Invoker2<true, StorageType, void(T::*)(X1, X2, X3)> {
1046 typedef void(*DoInvokeType)(
1047 internal::InvokerStorageBase*,
1048 typename internal::ParamTraits<X2>::ForwardType,
1049 typename internal::ParamTraits<X3>::ForwardType);
1051 static void DoInvoke(InvokerStorageBase* base,
1052 typename internal::ParamTraits<X2>::ForwardType x2,
1053 typename internal::ParamTraits<X3>::ForwardType x3) {
1054 StorageType* invoker = static_cast<StorageType*>(base);
1055 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1056 if (!weak_ptr.get()) {
1057 return;
1059 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), x2, x3);
1063 // Function: Arity 5 -> 3.
1064 template <typename StorageType, typename R,typename X1, typename X2,
1065 typename X3, typename X4, typename X5>
1066 struct Invoker2<false, StorageType, R(*)(X1, X2, X3, X4, X5)> {
1067 typedef R(*DoInvokeType)(
1068 internal::InvokerStorageBase*,
1069 typename internal::ParamTraits<X3>::ForwardType,
1070 typename internal::ParamTraits<X4>::ForwardType,
1071 typename internal::ParamTraits<X5>::ForwardType);
1073 static R DoInvoke(InvokerStorageBase* base,
1074 typename internal::ParamTraits<X3>::ForwardType x3,
1075 typename internal::ParamTraits<X4>::ForwardType x4,
1076 typename internal::ParamTraits<X5>::ForwardType x5) {
1077 StorageType* invoker = static_cast<StorageType*>(base);
1078 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_), x3, x4, x5);
1082 // Method: Arity 4 -> 3.
1083 template <typename StorageType, typename R, typename T, typename X1,
1084 typename X2, typename X3, typename X4>
1085 struct Invoker2<false, StorageType, R(T::*)(X1, X2, X3, X4)> {
1086 typedef R(*DoInvokeType)(
1087 internal::InvokerStorageBase*,
1088 typename internal::ParamTraits<X2>::ForwardType,
1089 typename internal::ParamTraits<X3>::ForwardType,
1090 typename internal::ParamTraits<X4>::ForwardType);
1092 static R DoInvoke(InvokerStorageBase* base,
1093 typename internal::ParamTraits<X2>::ForwardType x2,
1094 typename internal::ParamTraits<X3>::ForwardType x3,
1095 typename internal::ParamTraits<X4>::ForwardType x4) {
1096 StorageType* invoker = static_cast<StorageType*>(base);
1097 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_), x2, x3,
1098 x4);
1102 // WeakPtr Method: Arity 4 -> 3.
1103 template <typename StorageType, typename T, typename X1, typename X2,
1104 typename X3, typename X4>
1105 struct Invoker2<true, StorageType, void(T::*)(X1, X2, X3, X4)> {
1106 typedef void(*DoInvokeType)(
1107 internal::InvokerStorageBase*,
1108 typename internal::ParamTraits<X2>::ForwardType,
1109 typename internal::ParamTraits<X3>::ForwardType,
1110 typename internal::ParamTraits<X4>::ForwardType);
1112 static void DoInvoke(InvokerStorageBase* base,
1113 typename internal::ParamTraits<X2>::ForwardType x2,
1114 typename internal::ParamTraits<X3>::ForwardType x3,
1115 typename internal::ParamTraits<X4>::ForwardType x4) {
1116 StorageType* invoker = static_cast<StorageType*>(base);
1117 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1118 if (!weak_ptr.get()) {
1119 return;
1121 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), x2, x3, x4);
1125 // Function: Arity 6 -> 4.
1126 template <typename StorageType, typename R,typename X1, typename X2,
1127 typename X3, typename X4, typename X5, typename X6>
1128 struct Invoker2<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
1129 typedef R(*DoInvokeType)(
1130 internal::InvokerStorageBase*,
1131 typename internal::ParamTraits<X3>::ForwardType,
1132 typename internal::ParamTraits<X4>::ForwardType,
1133 typename internal::ParamTraits<X5>::ForwardType,
1134 typename internal::ParamTraits<X6>::ForwardType);
1136 static R DoInvoke(InvokerStorageBase* base,
1137 typename internal::ParamTraits<X3>::ForwardType x3,
1138 typename internal::ParamTraits<X4>::ForwardType x4,
1139 typename internal::ParamTraits<X5>::ForwardType x5,
1140 typename internal::ParamTraits<X6>::ForwardType x6) {
1141 StorageType* invoker = static_cast<StorageType*>(base);
1142 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_), x3, x4, x5,
1143 x6);
1147 // Method: Arity 5 -> 4.
1148 template <typename StorageType, typename R, typename T, typename X1,
1149 typename X2, typename X3, typename X4, typename X5>
1150 struct Invoker2<false, StorageType, R(T::*)(X1, X2, X3, X4, X5)> {
1151 typedef R(*DoInvokeType)(
1152 internal::InvokerStorageBase*,
1153 typename internal::ParamTraits<X2>::ForwardType,
1154 typename internal::ParamTraits<X3>::ForwardType,
1155 typename internal::ParamTraits<X4>::ForwardType,
1156 typename internal::ParamTraits<X5>::ForwardType);
1158 static R DoInvoke(InvokerStorageBase* base,
1159 typename internal::ParamTraits<X2>::ForwardType x2,
1160 typename internal::ParamTraits<X3>::ForwardType x3,
1161 typename internal::ParamTraits<X4>::ForwardType x4,
1162 typename internal::ParamTraits<X5>::ForwardType x5) {
1163 StorageType* invoker = static_cast<StorageType*>(base);
1164 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_), x2, x3,
1165 x4, x5);
1169 // WeakPtr Method: Arity 5 -> 4.
1170 template <typename StorageType, typename T, typename X1, typename X2,
1171 typename X3, typename X4, typename X5>
1172 struct Invoker2<true, StorageType, void(T::*)(X1, X2, X3, X4, X5)> {
1173 typedef void(*DoInvokeType)(
1174 internal::InvokerStorageBase*,
1175 typename internal::ParamTraits<X2>::ForwardType,
1176 typename internal::ParamTraits<X3>::ForwardType,
1177 typename internal::ParamTraits<X4>::ForwardType,
1178 typename internal::ParamTraits<X5>::ForwardType);
1180 static void DoInvoke(InvokerStorageBase* base,
1181 typename internal::ParamTraits<X2>::ForwardType x2,
1182 typename internal::ParamTraits<X3>::ForwardType x3,
1183 typename internal::ParamTraits<X4>::ForwardType x4,
1184 typename internal::ParamTraits<X5>::ForwardType x5) {
1185 StorageType* invoker = static_cast<StorageType*>(base);
1186 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1187 if (!weak_ptr.get()) {
1188 return;
1190 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), x2, x3, x4, x5);
1194 template <bool IsWeak, typename StorageType, typename NormalizedSig>
1195 struct Invoker3;
1197 // Function: Arity 3 -> 0.
1198 template <typename StorageType, typename R,typename X1, typename X2,
1199 typename X3>
1200 struct Invoker3<false, StorageType, R(*)(X1, X2, X3)> {
1201 typedef R(*DoInvokeType)(
1202 internal::InvokerStorageBase*);
1204 static R DoInvoke(InvokerStorageBase* base) {
1205 StorageType* invoker = static_cast<StorageType*>(base);
1206 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1207 Unwrap(invoker->p3_));
1211 // Method: Arity 2 -> 0.
1212 template <typename StorageType, typename R, typename T, typename X1,
1213 typename X2>
1214 struct Invoker3<false, StorageType, R(T::*)(X1, X2)> {
1215 typedef R(*DoInvokeType)(
1216 internal::InvokerStorageBase*);
1218 static R DoInvoke(InvokerStorageBase* base) {
1219 StorageType* invoker = static_cast<StorageType*>(base);
1220 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1221 Unwrap(invoker->p3_));
1225 // WeakPtr Method: Arity 2 -> 0.
1226 template <typename StorageType, typename T, typename X1, typename X2>
1227 struct Invoker3<true, StorageType, void(T::*)(X1, X2)> {
1228 typedef void(*DoInvokeType)(
1229 internal::InvokerStorageBase*);
1231 static void DoInvoke(InvokerStorageBase* base) {
1232 StorageType* invoker = static_cast<StorageType*>(base);
1233 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1234 if (!weak_ptr.get()) {
1235 return;
1237 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_));
1241 // Function: Arity 4 -> 1.
1242 template <typename StorageType, typename R,typename X1, typename X2,
1243 typename X3, typename X4>
1244 struct Invoker3<false, StorageType, R(*)(X1, X2, X3, X4)> {
1245 typedef R(*DoInvokeType)(
1246 internal::InvokerStorageBase*,
1247 typename internal::ParamTraits<X4>::ForwardType);
1249 static R DoInvoke(InvokerStorageBase* base,
1250 typename internal::ParamTraits<X4>::ForwardType x4) {
1251 StorageType* invoker = static_cast<StorageType*>(base);
1252 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1253 Unwrap(invoker->p3_), x4);
1257 // Method: Arity 3 -> 1.
1258 template <typename StorageType, typename R, typename T, typename X1,
1259 typename X2, typename X3>
1260 struct Invoker3<false, StorageType, R(T::*)(X1, X2, X3)> {
1261 typedef R(*DoInvokeType)(
1262 internal::InvokerStorageBase*,
1263 typename internal::ParamTraits<X3>::ForwardType);
1265 static R DoInvoke(InvokerStorageBase* base,
1266 typename internal::ParamTraits<X3>::ForwardType x3) {
1267 StorageType* invoker = static_cast<StorageType*>(base);
1268 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1269 Unwrap(invoker->p3_), x3);
1273 // WeakPtr Method: Arity 3 -> 1.
1274 template <typename StorageType, typename T, typename X1, typename X2,
1275 typename X3>
1276 struct Invoker3<true, StorageType, void(T::*)(X1, X2, X3)> {
1277 typedef void(*DoInvokeType)(
1278 internal::InvokerStorageBase*,
1279 typename internal::ParamTraits<X3>::ForwardType);
1281 static void DoInvoke(InvokerStorageBase* base,
1282 typename internal::ParamTraits<X3>::ForwardType x3) {
1283 StorageType* invoker = static_cast<StorageType*>(base);
1284 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1285 if (!weak_ptr.get()) {
1286 return;
1288 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_), x3);
1292 // Function: Arity 5 -> 2.
1293 template <typename StorageType, typename R,typename X1, typename X2,
1294 typename X3, typename X4, typename X5>
1295 struct Invoker3<false, StorageType, R(*)(X1, X2, X3, X4, X5)> {
1296 typedef R(*DoInvokeType)(
1297 internal::InvokerStorageBase*,
1298 typename internal::ParamTraits<X4>::ForwardType,
1299 typename internal::ParamTraits<X5>::ForwardType);
1301 static R DoInvoke(InvokerStorageBase* base,
1302 typename internal::ParamTraits<X4>::ForwardType x4,
1303 typename internal::ParamTraits<X5>::ForwardType x5) {
1304 StorageType* invoker = static_cast<StorageType*>(base);
1305 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1306 Unwrap(invoker->p3_), x4, x5);
1310 // Method: Arity 4 -> 2.
1311 template <typename StorageType, typename R, typename T, typename X1,
1312 typename X2, typename X3, typename X4>
1313 struct Invoker3<false, StorageType, R(T::*)(X1, X2, X3, X4)> {
1314 typedef R(*DoInvokeType)(
1315 internal::InvokerStorageBase*,
1316 typename internal::ParamTraits<X3>::ForwardType,
1317 typename internal::ParamTraits<X4>::ForwardType);
1319 static R DoInvoke(InvokerStorageBase* base,
1320 typename internal::ParamTraits<X3>::ForwardType x3,
1321 typename internal::ParamTraits<X4>::ForwardType x4) {
1322 StorageType* invoker = static_cast<StorageType*>(base);
1323 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1324 Unwrap(invoker->p3_), x3, x4);
1328 // WeakPtr Method: Arity 4 -> 2.
1329 template <typename StorageType, typename T, typename X1, typename X2,
1330 typename X3, typename X4>
1331 struct Invoker3<true, StorageType, void(T::*)(X1, X2, X3, X4)> {
1332 typedef void(*DoInvokeType)(
1333 internal::InvokerStorageBase*,
1334 typename internal::ParamTraits<X3>::ForwardType,
1335 typename internal::ParamTraits<X4>::ForwardType);
1337 static void DoInvoke(InvokerStorageBase* base,
1338 typename internal::ParamTraits<X3>::ForwardType x3,
1339 typename internal::ParamTraits<X4>::ForwardType x4) {
1340 StorageType* invoker = static_cast<StorageType*>(base);
1341 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1342 if (!weak_ptr.get()) {
1343 return;
1345 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_), x3,
1346 x4);
1350 // Function: Arity 6 -> 3.
1351 template <typename StorageType, typename R,typename X1, typename X2,
1352 typename X3, typename X4, typename X5, typename X6>
1353 struct Invoker3<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
1354 typedef R(*DoInvokeType)(
1355 internal::InvokerStorageBase*,
1356 typename internal::ParamTraits<X4>::ForwardType,
1357 typename internal::ParamTraits<X5>::ForwardType,
1358 typename internal::ParamTraits<X6>::ForwardType);
1360 static R DoInvoke(InvokerStorageBase* base,
1361 typename internal::ParamTraits<X4>::ForwardType x4,
1362 typename internal::ParamTraits<X5>::ForwardType x5,
1363 typename internal::ParamTraits<X6>::ForwardType x6) {
1364 StorageType* invoker = static_cast<StorageType*>(base);
1365 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1366 Unwrap(invoker->p3_), x4, x5, x6);
1370 // Method: Arity 5 -> 3.
1371 template <typename StorageType, typename R, typename T, typename X1,
1372 typename X2, typename X3, typename X4, typename X5>
1373 struct Invoker3<false, StorageType, R(T::*)(X1, X2, X3, X4, X5)> {
1374 typedef R(*DoInvokeType)(
1375 internal::InvokerStorageBase*,
1376 typename internal::ParamTraits<X3>::ForwardType,
1377 typename internal::ParamTraits<X4>::ForwardType,
1378 typename internal::ParamTraits<X5>::ForwardType);
1380 static R DoInvoke(InvokerStorageBase* base,
1381 typename internal::ParamTraits<X3>::ForwardType x3,
1382 typename internal::ParamTraits<X4>::ForwardType x4,
1383 typename internal::ParamTraits<X5>::ForwardType x5) {
1384 StorageType* invoker = static_cast<StorageType*>(base);
1385 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1386 Unwrap(invoker->p3_), x3, x4, x5);
1390 // WeakPtr Method: Arity 5 -> 3.
1391 template <typename StorageType, typename T, typename X1, typename X2,
1392 typename X3, typename X4, typename X5>
1393 struct Invoker3<true, StorageType, void(T::*)(X1, X2, X3, X4, X5)> {
1394 typedef void(*DoInvokeType)(
1395 internal::InvokerStorageBase*,
1396 typename internal::ParamTraits<X3>::ForwardType,
1397 typename internal::ParamTraits<X4>::ForwardType,
1398 typename internal::ParamTraits<X5>::ForwardType);
1400 static void DoInvoke(InvokerStorageBase* base,
1401 typename internal::ParamTraits<X3>::ForwardType x3,
1402 typename internal::ParamTraits<X4>::ForwardType x4,
1403 typename internal::ParamTraits<X5>::ForwardType x5) {
1404 StorageType* invoker = static_cast<StorageType*>(base);
1405 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1406 if (!weak_ptr.get()) {
1407 return;
1409 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_), x3,
1410 x4, x5);
1414 template <bool IsWeak, typename StorageType, typename NormalizedSig>
1415 struct Invoker4;
1417 // Function: Arity 4 -> 0.
1418 template <typename StorageType, typename R,typename X1, typename X2,
1419 typename X3, typename X4>
1420 struct Invoker4<false, StorageType, R(*)(X1, X2, X3, X4)> {
1421 typedef R(*DoInvokeType)(
1422 internal::InvokerStorageBase*);
1424 static R DoInvoke(InvokerStorageBase* base) {
1425 StorageType* invoker = static_cast<StorageType*>(base);
1426 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1427 Unwrap(invoker->p3_), Unwrap(invoker->p4_));
1431 // Method: Arity 3 -> 0.
1432 template <typename StorageType, typename R, typename T, typename X1,
1433 typename X2, typename X3>
1434 struct Invoker4<false, StorageType, R(T::*)(X1, X2, X3)> {
1435 typedef R(*DoInvokeType)(
1436 internal::InvokerStorageBase*);
1438 static R DoInvoke(InvokerStorageBase* base) {
1439 StorageType* invoker = static_cast<StorageType*>(base);
1440 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1441 Unwrap(invoker->p3_), Unwrap(invoker->p4_));
1445 // WeakPtr Method: Arity 3 -> 0.
1446 template <typename StorageType, typename T, typename X1, typename X2,
1447 typename X3>
1448 struct Invoker4<true, StorageType, void(T::*)(X1, X2, X3)> {
1449 typedef void(*DoInvokeType)(
1450 internal::InvokerStorageBase*);
1452 static void DoInvoke(InvokerStorageBase* base) {
1453 StorageType* invoker = static_cast<StorageType*>(base);
1454 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1455 if (!weak_ptr.get()) {
1456 return;
1458 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_),
1459 Unwrap(invoker->p4_));
1463 // Function: Arity 5 -> 1.
1464 template <typename StorageType, typename R,typename X1, typename X2,
1465 typename X3, typename X4, typename X5>
1466 struct Invoker4<false, StorageType, R(*)(X1, X2, X3, X4, X5)> {
1467 typedef R(*DoInvokeType)(
1468 internal::InvokerStorageBase*,
1469 typename internal::ParamTraits<X5>::ForwardType);
1471 static R DoInvoke(InvokerStorageBase* base,
1472 typename internal::ParamTraits<X5>::ForwardType x5) {
1473 StorageType* invoker = static_cast<StorageType*>(base);
1474 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1475 Unwrap(invoker->p3_), Unwrap(invoker->p4_), x5);
1479 // Method: Arity 4 -> 1.
1480 template <typename StorageType, typename R, typename T, typename X1,
1481 typename X2, typename X3, typename X4>
1482 struct Invoker4<false, StorageType, R(T::*)(X1, X2, X3, X4)> {
1483 typedef R(*DoInvokeType)(
1484 internal::InvokerStorageBase*,
1485 typename internal::ParamTraits<X4>::ForwardType);
1487 static R DoInvoke(InvokerStorageBase* base,
1488 typename internal::ParamTraits<X4>::ForwardType x4) {
1489 StorageType* invoker = static_cast<StorageType*>(base);
1490 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1491 Unwrap(invoker->p3_), Unwrap(invoker->p4_), x4);
1495 // WeakPtr Method: Arity 4 -> 1.
1496 template <typename StorageType, typename T, typename X1, typename X2,
1497 typename X3, typename X4>
1498 struct Invoker4<true, StorageType, void(T::*)(X1, X2, X3, X4)> {
1499 typedef void(*DoInvokeType)(
1500 internal::InvokerStorageBase*,
1501 typename internal::ParamTraits<X4>::ForwardType);
1503 static void DoInvoke(InvokerStorageBase* base,
1504 typename internal::ParamTraits<X4>::ForwardType x4) {
1505 StorageType* invoker = static_cast<StorageType*>(base);
1506 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1507 if (!weak_ptr.get()) {
1508 return;
1510 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_),
1511 Unwrap(invoker->p4_), x4);
1515 // Function: Arity 6 -> 2.
1516 template <typename StorageType, typename R,typename X1, typename X2,
1517 typename X3, typename X4, typename X5, typename X6>
1518 struct Invoker4<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
1519 typedef R(*DoInvokeType)(
1520 internal::InvokerStorageBase*,
1521 typename internal::ParamTraits<X5>::ForwardType,
1522 typename internal::ParamTraits<X6>::ForwardType);
1524 static R DoInvoke(InvokerStorageBase* base,
1525 typename internal::ParamTraits<X5>::ForwardType x5,
1526 typename internal::ParamTraits<X6>::ForwardType x6) {
1527 StorageType* invoker = static_cast<StorageType*>(base);
1528 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1529 Unwrap(invoker->p3_), Unwrap(invoker->p4_), x5, x6);
1533 // Method: Arity 5 -> 2.
1534 template <typename StorageType, typename R, typename T, typename X1,
1535 typename X2, typename X3, typename X4, typename X5>
1536 struct Invoker4<false, StorageType, R(T::*)(X1, X2, X3, X4, X5)> {
1537 typedef R(*DoInvokeType)(
1538 internal::InvokerStorageBase*,
1539 typename internal::ParamTraits<X4>::ForwardType,
1540 typename internal::ParamTraits<X5>::ForwardType);
1542 static R DoInvoke(InvokerStorageBase* base,
1543 typename internal::ParamTraits<X4>::ForwardType x4,
1544 typename internal::ParamTraits<X5>::ForwardType x5) {
1545 StorageType* invoker = static_cast<StorageType*>(base);
1546 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1547 Unwrap(invoker->p3_), Unwrap(invoker->p4_), x4, x5);
1551 // WeakPtr Method: Arity 5 -> 2.
1552 template <typename StorageType, typename T, typename X1, typename X2,
1553 typename X3, typename X4, typename X5>
1554 struct Invoker4<true, StorageType, void(T::*)(X1, X2, X3, X4, X5)> {
1555 typedef void(*DoInvokeType)(
1556 internal::InvokerStorageBase*,
1557 typename internal::ParamTraits<X4>::ForwardType,
1558 typename internal::ParamTraits<X5>::ForwardType);
1560 static void DoInvoke(InvokerStorageBase* base,
1561 typename internal::ParamTraits<X4>::ForwardType x4,
1562 typename internal::ParamTraits<X5>::ForwardType x5) {
1563 StorageType* invoker = static_cast<StorageType*>(base);
1564 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1565 if (!weak_ptr.get()) {
1566 return;
1568 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_),
1569 Unwrap(invoker->p4_), x4, x5);
1573 template <bool IsWeak, typename StorageType, typename NormalizedSig>
1574 struct Invoker5;
1576 // Function: Arity 5 -> 0.
1577 template <typename StorageType, typename R,typename X1, typename X2,
1578 typename X3, typename X4, typename X5>
1579 struct Invoker5<false, StorageType, R(*)(X1, X2, X3, X4, X5)> {
1580 typedef R(*DoInvokeType)(
1581 internal::InvokerStorageBase*);
1583 static R DoInvoke(InvokerStorageBase* base) {
1584 StorageType* invoker = static_cast<StorageType*>(base);
1585 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1586 Unwrap(invoker->p3_), Unwrap(invoker->p4_), Unwrap(invoker->p5_));
1590 // Method: Arity 4 -> 0.
1591 template <typename StorageType, typename R, typename T, typename X1,
1592 typename X2, typename X3, typename X4>
1593 struct Invoker5<false, StorageType, R(T::*)(X1, X2, X3, X4)> {
1594 typedef R(*DoInvokeType)(
1595 internal::InvokerStorageBase*);
1597 static R DoInvoke(InvokerStorageBase* base) {
1598 StorageType* invoker = static_cast<StorageType*>(base);
1599 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1600 Unwrap(invoker->p3_), Unwrap(invoker->p4_), Unwrap(invoker->p5_));
1604 // WeakPtr Method: Arity 4 -> 0.
1605 template <typename StorageType, typename T, typename X1, typename X2,
1606 typename X3, typename X4>
1607 struct Invoker5<true, StorageType, void(T::*)(X1, X2, X3, X4)> {
1608 typedef void(*DoInvokeType)(
1609 internal::InvokerStorageBase*);
1611 static void DoInvoke(InvokerStorageBase* base) {
1612 StorageType* invoker = static_cast<StorageType*>(base);
1613 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1614 if (!weak_ptr.get()) {
1615 return;
1617 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_),
1618 Unwrap(invoker->p4_), Unwrap(invoker->p5_));
1622 // Function: Arity 6 -> 1.
1623 template <typename StorageType, typename R,typename X1, typename X2,
1624 typename X3, typename X4, typename X5, typename X6>
1625 struct Invoker5<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
1626 typedef R(*DoInvokeType)(
1627 internal::InvokerStorageBase*,
1628 typename internal::ParamTraits<X6>::ForwardType);
1630 static R DoInvoke(InvokerStorageBase* base,
1631 typename internal::ParamTraits<X6>::ForwardType x6) {
1632 StorageType* invoker = static_cast<StorageType*>(base);
1633 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1634 Unwrap(invoker->p3_), Unwrap(invoker->p4_), Unwrap(invoker->p5_), x6);
1638 // Method: Arity 5 -> 1.
1639 template <typename StorageType, typename R, typename T, typename X1,
1640 typename X2, typename X3, typename X4, typename X5>
1641 struct Invoker5<false, StorageType, R(T::*)(X1, X2, X3, X4, X5)> {
1642 typedef R(*DoInvokeType)(
1643 internal::InvokerStorageBase*,
1644 typename internal::ParamTraits<X5>::ForwardType);
1646 static R DoInvoke(InvokerStorageBase* base,
1647 typename internal::ParamTraits<X5>::ForwardType x5) {
1648 StorageType* invoker = static_cast<StorageType*>(base);
1649 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1650 Unwrap(invoker->p3_), Unwrap(invoker->p4_), Unwrap(invoker->p5_), x5);
1654 // WeakPtr Method: Arity 5 -> 1.
1655 template <typename StorageType, typename T, typename X1, typename X2,
1656 typename X3, typename X4, typename X5>
1657 struct Invoker5<true, StorageType, void(T::*)(X1, X2, X3, X4, X5)> {
1658 typedef void(*DoInvokeType)(
1659 internal::InvokerStorageBase*,
1660 typename internal::ParamTraits<X5>::ForwardType);
1662 static void DoInvoke(InvokerStorageBase* base,
1663 typename internal::ParamTraits<X5>::ForwardType x5) {
1664 StorageType* invoker = static_cast<StorageType*>(base);
1665 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1666 if (!weak_ptr.get()) {
1667 return;
1669 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_),
1670 Unwrap(invoker->p4_), Unwrap(invoker->p5_), x5);
1674 template <bool IsWeak, typename StorageType, typename NormalizedSig>
1675 struct Invoker6;
1677 // Function: Arity 6 -> 0.
1678 template <typename StorageType, typename R,typename X1, typename X2,
1679 typename X3, typename X4, typename X5, typename X6>
1680 struct Invoker6<false, StorageType, R(*)(X1, X2, X3, X4, X5, X6)> {
1681 typedef R(*DoInvokeType)(
1682 internal::InvokerStorageBase*);
1684 static R DoInvoke(InvokerStorageBase* base) {
1685 StorageType* invoker = static_cast<StorageType*>(base);
1686 return invoker->f_(Unwrap(invoker->p1_), Unwrap(invoker->p2_),
1687 Unwrap(invoker->p3_), Unwrap(invoker->p4_), Unwrap(invoker->p5_),
1688 Unwrap(invoker->p6_));
1692 // Method: Arity 5 -> 0.
1693 template <typename StorageType, typename R, typename T, typename X1,
1694 typename X2, typename X3, typename X4, typename X5>
1695 struct Invoker6<false, StorageType, R(T::*)(X1, X2, X3, X4, X5)> {
1696 typedef R(*DoInvokeType)(
1697 internal::InvokerStorageBase*);
1699 static R DoInvoke(InvokerStorageBase* base) {
1700 StorageType* invoker = static_cast<StorageType*>(base);
1701 return (Unwrap(invoker->p1_)->*invoker->f_)(Unwrap(invoker->p2_),
1702 Unwrap(invoker->p3_), Unwrap(invoker->p4_), Unwrap(invoker->p5_),
1703 Unwrap(invoker->p6_));
1707 // WeakPtr Method: Arity 5 -> 0.
1708 template <typename StorageType, typename T, typename X1, typename X2,
1709 typename X3, typename X4, typename X5>
1710 struct Invoker6<true, StorageType, void(T::*)(X1, X2, X3, X4, X5)> {
1711 typedef void(*DoInvokeType)(
1712 internal::InvokerStorageBase*);
1714 static void DoInvoke(InvokerStorageBase* base) {
1715 StorageType* invoker = static_cast<StorageType*>(base);
1716 typename StorageType::P1Traits::StorageType& weak_ptr = invoker->p1_;
1717 if (!weak_ptr.get()) {
1718 return;
1720 (weak_ptr->*invoker->f_)(Unwrap(invoker->p2_), Unwrap(invoker->p3_),
1721 Unwrap(invoker->p4_), Unwrap(invoker->p5_), Unwrap(invoker->p6_));
1725 // BindMoreFuncN<>
1727 // This set of functions help in fully binding the free parameters in a
1728 // Callback<>.
1729 template <typename Sig, typename P1>
1730 void BindMoreFunc1(const base::Callback<Sig>& callback, const P1& p1) {
1731 callback.Run(p1);
1734 template <typename Sig, typename P1, typename P2>
1735 void BindMoreFunc2(const base::Callback<Sig>& callback, const P1& p1,
1736 const P2& p2) {
1737 callback.Run(p1, p2);
1740 template <typename Sig, typename P1, typename P2, typename P3>
1741 void BindMoreFunc3(const base::Callback<Sig>& callback, const P1& p1,
1742 const P2& p2, const P3& p3) {
1743 callback.Run(p1, p2, p3);
1746 template <typename Sig, typename P1, typename P2, typename P3, typename P4>
1747 void BindMoreFunc4(const base::Callback<Sig>& callback, const P1& p1,
1748 const P2& p2, const P3& p3, const P4& p4) {
1749 callback.Run(p1, p2, p3, p4);
1752 template <typename Sig, typename P1, typename P2, typename P3, typename P4,
1753 typename P5>
1754 void BindMoreFunc5(const base::Callback<Sig>& callback, const P1& p1,
1755 const P2& p2, const P3& p3, const P4& p4, const P5& p5) {
1756 callback.Run(p1, p2, p3, p4, p5);
1759 template <typename Sig, typename P1, typename P2, typename P3, typename P4,
1760 typename P5, typename P6>
1761 void BindMoreFunc6(const base::Callback<Sig>& callback, const P1& p1,
1762 const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) {
1763 callback.Run(p1, p2, p3, p4, p5, p6);
1766 // InvokerStorageN<>
1768 // These are the actual storage classes for the Invokers.
1770 // Though these types are "classes", they are being used as structs with
1771 // all member variable public. We cannot make it a struct because it inherits
1772 // from a class which causes a compiler warning. We cannot add a "Run()" method
1773 // that forwards the unbound arguments because that would require we unwrap the
1774 // Sig type like in InvokerN above to know the return type, and the arity
1775 // of Run().
1777 // An alternate solution would be to merge InvokerN and InvokerStorageN,
1778 // but the generated code seemed harder to read.
1780 template <typename Sig>
1781 class InvokerStorage0 : public InvokerStorageBase {
1782 public:
1783 typedef InvokerStorage0 StorageType;
1784 typedef FunctionTraits<Sig> TargetTraits;
1785 typedef typename TargetTraits::IsMethod IsMethod;
1786 typedef Sig Signature;
1787 typedef Invoker0<false, StorageType,
1788 typename TargetTraits::NormalizedSig> Invoker;
1792 InvokerStorage0(Sig f)
1793 : f_(f) {
1796 virtual ~InvokerStorage0() { }
1798 Sig f_;
1801 template <typename Sig, typename P1>
1802 class InvokerStorage1 : public InvokerStorageBase {
1803 public:
1804 typedef InvokerStorage1 StorageType;
1805 typedef FunctionTraits<Sig> TargetTraits;
1806 typedef typename TargetTraits::IsMethod IsMethod;
1807 typedef Sig Signature;
1808 typedef ParamTraits<P1> P1Traits;
1809 typedef Invoker1<IsWeakMethod<IsMethod::value, P1>::value, StorageType,
1810 typename TargetTraits::NormalizedSig> Invoker;
1811 COMPILE_ASSERT(!(IsWeakMethod<IsMethod::value, P1>::value) ||
1812 is_void<typename TargetTraits::Return>::value,
1813 weak_ptrs_can_only_bind_to_methods_without_return_values);
1815 // For methods, we need to be careful for parameter 1. We skip the
1816 // scoped_refptr check because the binder itself takes care of this. We also
1817 // disallow binding of an array as the method's target object.
1818 COMPILE_ASSERT(IsMethod::value ||
1819 internal::NeedsScopedRefptrButGetsRawPtr<
1820 typename ParamTraits<P1>::StorageType>::value == 0,
1821 p1_is_refcounted_type_and_needs_scoped_refptr);
1822 COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
1823 first_bound_argument_to_method_cannot_be_array);
1825 // Do not allow binding a non-const reference parameter. Non-const reference
1826 // parameters are disallowed by the Google style guide. Also, binding a
1827 // non-const reference parameter can make for subtle bugs because the
1828 // invoked function will receive a reference to the stored copy of the
1829 // argument and not the original.
1830 COMPILE_ASSERT(
1831 !( is_non_const_reference<typename TargetTraits::B1>::value ),
1832 do_not_bind_functions_with_nonconst_ref);
1835 InvokerStorage1(Sig f, const P1& p1)
1836 : f_(f), p1_(static_cast<typename ParamTraits<P1>::StorageType>(p1)) {
1837 MaybeRefcount<IsMethod, P1>::AddRef(p1_);
1840 virtual ~InvokerStorage1() {
1841 MaybeRefcount<IsMethod, P1>::Release(p1_);
1844 Sig f_;
1845 typename ParamTraits<P1>::StorageType p1_;
1848 template <typename Sig, typename P1, typename P2>
1849 class InvokerStorage2 : public InvokerStorageBase {
1850 public:
1851 typedef InvokerStorage2 StorageType;
1852 typedef FunctionTraits<Sig> TargetTraits;
1853 typedef typename TargetTraits::IsMethod IsMethod;
1854 typedef Sig Signature;
1855 typedef ParamTraits<P1> P1Traits;
1856 typedef ParamTraits<P2> P2Traits;
1857 typedef Invoker2<IsWeakMethod<IsMethod::value, P1>::value, StorageType,
1858 typename TargetTraits::NormalizedSig> Invoker;
1859 COMPILE_ASSERT(!(IsWeakMethod<IsMethod::value, P1>::value) ||
1860 is_void<typename TargetTraits::Return>::value,
1861 weak_ptrs_can_only_bind_to_methods_without_return_values);
1863 // For methods, we need to be careful for parameter 1. We skip the
1864 // scoped_refptr check because the binder itself takes care of this. We also
1865 // disallow binding of an array as the method's target object.
1866 COMPILE_ASSERT(IsMethod::value ||
1867 internal::NeedsScopedRefptrButGetsRawPtr<
1868 typename ParamTraits<P1>::StorageType>::value == 0,
1869 p1_is_refcounted_type_and_needs_scoped_refptr);
1870 COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
1871 first_bound_argument_to_method_cannot_be_array);
1872 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
1873 typename ParamTraits<P2>::StorageType>::value == 0,
1874 p2_is_refcounted_type_and_needs_scoped_refptr);
1876 // Do not allow binding a non-const reference parameter. Non-const reference
1877 // parameters are disallowed by the Google style guide. Also, binding a
1878 // non-const reference parameter can make for subtle bugs because the
1879 // invoked function will receive a reference to the stored copy of the
1880 // argument and not the original.
1881 COMPILE_ASSERT(
1882 !( is_non_const_reference<typename TargetTraits::B1>::value ||
1883 is_non_const_reference<typename TargetTraits::B2>::value ),
1884 do_not_bind_functions_with_nonconst_ref);
1887 InvokerStorage2(Sig f, const P1& p1, const P2& p2)
1888 : f_(f), p1_(static_cast<typename ParamTraits<P1>::StorageType>(p1)),
1889 p2_(static_cast<typename ParamTraits<P2>::StorageType>(p2)) {
1890 MaybeRefcount<IsMethod, P1>::AddRef(p1_);
1893 virtual ~InvokerStorage2() {
1894 MaybeRefcount<IsMethod, P1>::Release(p1_);
1897 Sig f_;
1898 typename ParamTraits<P1>::StorageType p1_;
1899 typename ParamTraits<P2>::StorageType p2_;
1902 template <typename Sig, typename P1, typename P2, typename P3>
1903 class InvokerStorage3 : public InvokerStorageBase {
1904 public:
1905 typedef InvokerStorage3 StorageType;
1906 typedef FunctionTraits<Sig> TargetTraits;
1907 typedef typename TargetTraits::IsMethod IsMethod;
1908 typedef Sig Signature;
1909 typedef ParamTraits<P1> P1Traits;
1910 typedef ParamTraits<P2> P2Traits;
1911 typedef ParamTraits<P3> P3Traits;
1912 typedef Invoker3<IsWeakMethod<IsMethod::value, P1>::value, StorageType,
1913 typename TargetTraits::NormalizedSig> Invoker;
1914 COMPILE_ASSERT(!(IsWeakMethod<IsMethod::value, P1>::value) ||
1915 is_void<typename TargetTraits::Return>::value,
1916 weak_ptrs_can_only_bind_to_methods_without_return_values);
1918 // For methods, we need to be careful for parameter 1. We skip the
1919 // scoped_refptr check because the binder itself takes care of this. We also
1920 // disallow binding of an array as the method's target object.
1921 COMPILE_ASSERT(IsMethod::value ||
1922 internal::NeedsScopedRefptrButGetsRawPtr<
1923 typename ParamTraits<P1>::StorageType>::value == 0,
1924 p1_is_refcounted_type_and_needs_scoped_refptr);
1925 COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
1926 first_bound_argument_to_method_cannot_be_array);
1927 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
1928 typename ParamTraits<P2>::StorageType>::value == 0,
1929 p2_is_refcounted_type_and_needs_scoped_refptr);
1930 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
1931 typename ParamTraits<P3>::StorageType>::value == 0,
1932 p3_is_refcounted_type_and_needs_scoped_refptr);
1934 // Do not allow binding a non-const reference parameter. Non-const reference
1935 // parameters are disallowed by the Google style guide. Also, binding a
1936 // non-const reference parameter can make for subtle bugs because the
1937 // invoked function will receive a reference to the stored copy of the
1938 // argument and not the original.
1939 COMPILE_ASSERT(
1940 !( is_non_const_reference<typename TargetTraits::B1>::value ||
1941 is_non_const_reference<typename TargetTraits::B2>::value ||
1942 is_non_const_reference<typename TargetTraits::B3>::value ),
1943 do_not_bind_functions_with_nonconst_ref);
1946 InvokerStorage3(Sig f, const P1& p1, const P2& p2, const P3& p3)
1947 : f_(f), p1_(static_cast<typename ParamTraits<P1>::StorageType>(p1)),
1948 p2_(static_cast<typename ParamTraits<P2>::StorageType>(p2)),
1949 p3_(static_cast<typename ParamTraits<P3>::StorageType>(p3)) {
1950 MaybeRefcount<IsMethod, P1>::AddRef(p1_);
1953 virtual ~InvokerStorage3() {
1954 MaybeRefcount<IsMethod, P1>::Release(p1_);
1957 Sig f_;
1958 typename ParamTraits<P1>::StorageType p1_;
1959 typename ParamTraits<P2>::StorageType p2_;
1960 typename ParamTraits<P3>::StorageType p3_;
1963 template <typename Sig, typename P1, typename P2, typename P3, typename P4>
1964 class InvokerStorage4 : public InvokerStorageBase {
1965 public:
1966 typedef InvokerStorage4 StorageType;
1967 typedef FunctionTraits<Sig> TargetTraits;
1968 typedef typename TargetTraits::IsMethod IsMethod;
1969 typedef Sig Signature;
1970 typedef ParamTraits<P1> P1Traits;
1971 typedef ParamTraits<P2> P2Traits;
1972 typedef ParamTraits<P3> P3Traits;
1973 typedef ParamTraits<P4> P4Traits;
1974 typedef Invoker4<IsWeakMethod<IsMethod::value, P1>::value, StorageType,
1975 typename TargetTraits::NormalizedSig> Invoker;
1976 COMPILE_ASSERT(!(IsWeakMethod<IsMethod::value, P1>::value) ||
1977 is_void<typename TargetTraits::Return>::value,
1978 weak_ptrs_can_only_bind_to_methods_without_return_values);
1980 // For methods, we need to be careful for parameter 1. We skip the
1981 // scoped_refptr check because the binder itself takes care of this. We also
1982 // disallow binding of an array as the method's target object.
1983 COMPILE_ASSERT(IsMethod::value ||
1984 internal::NeedsScopedRefptrButGetsRawPtr<
1985 typename ParamTraits<P1>::StorageType>::value == 0,
1986 p1_is_refcounted_type_and_needs_scoped_refptr);
1987 COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
1988 first_bound_argument_to_method_cannot_be_array);
1989 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
1990 typename ParamTraits<P2>::StorageType>::value == 0,
1991 p2_is_refcounted_type_and_needs_scoped_refptr);
1992 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
1993 typename ParamTraits<P3>::StorageType>::value == 0,
1994 p3_is_refcounted_type_and_needs_scoped_refptr);
1995 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
1996 typename ParamTraits<P4>::StorageType>::value == 0,
1997 p4_is_refcounted_type_and_needs_scoped_refptr);
1999 // Do not allow binding a non-const reference parameter. Non-const reference
2000 // parameters are disallowed by the Google style guide. Also, binding a
2001 // non-const reference parameter can make for subtle bugs because the
2002 // invoked function will receive a reference to the stored copy of the
2003 // argument and not the original.
2004 COMPILE_ASSERT(
2005 !( is_non_const_reference<typename TargetTraits::B1>::value ||
2006 is_non_const_reference<typename TargetTraits::B2>::value ||
2007 is_non_const_reference<typename TargetTraits::B3>::value ||
2008 is_non_const_reference<typename TargetTraits::B4>::value ),
2009 do_not_bind_functions_with_nonconst_ref);
2012 InvokerStorage4(Sig f, const P1& p1, const P2& p2, const P3& p3, const P4& p4)
2013 : f_(f), p1_(static_cast<typename ParamTraits<P1>::StorageType>(p1)),
2014 p2_(static_cast<typename ParamTraits<P2>::StorageType>(p2)),
2015 p3_(static_cast<typename ParamTraits<P3>::StorageType>(p3)),
2016 p4_(static_cast<typename ParamTraits<P4>::StorageType>(p4)) {
2017 MaybeRefcount<IsMethod, P1>::AddRef(p1_);
2020 virtual ~InvokerStorage4() {
2021 MaybeRefcount<IsMethod, P1>::Release(p1_);
2024 Sig f_;
2025 typename ParamTraits<P1>::StorageType p1_;
2026 typename ParamTraits<P2>::StorageType p2_;
2027 typename ParamTraits<P3>::StorageType p3_;
2028 typename ParamTraits<P4>::StorageType p4_;
2031 template <typename Sig, typename P1, typename P2, typename P3, typename P4,
2032 typename P5>
2033 class InvokerStorage5 : public InvokerStorageBase {
2034 public:
2035 typedef InvokerStorage5 StorageType;
2036 typedef FunctionTraits<Sig> TargetTraits;
2037 typedef typename TargetTraits::IsMethod IsMethod;
2038 typedef Sig Signature;
2039 typedef ParamTraits<P1> P1Traits;
2040 typedef ParamTraits<P2> P2Traits;
2041 typedef ParamTraits<P3> P3Traits;
2042 typedef ParamTraits<P4> P4Traits;
2043 typedef ParamTraits<P5> P5Traits;
2044 typedef Invoker5<IsWeakMethod<IsMethod::value, P1>::value, StorageType,
2045 typename TargetTraits::NormalizedSig> Invoker;
2046 COMPILE_ASSERT(!(IsWeakMethod<IsMethod::value, P1>::value) ||
2047 is_void<typename TargetTraits::Return>::value,
2048 weak_ptrs_can_only_bind_to_methods_without_return_values);
2050 // For methods, we need to be careful for parameter 1. We skip the
2051 // scoped_refptr check because the binder itself takes care of this. We also
2052 // disallow binding of an array as the method's target object.
2053 COMPILE_ASSERT(IsMethod::value ||
2054 internal::NeedsScopedRefptrButGetsRawPtr<
2055 typename ParamTraits<P1>::StorageType>::value == 0,
2056 p1_is_refcounted_type_and_needs_scoped_refptr);
2057 COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
2058 first_bound_argument_to_method_cannot_be_array);
2059 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2060 typename ParamTraits<P2>::StorageType>::value == 0,
2061 p2_is_refcounted_type_and_needs_scoped_refptr);
2062 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2063 typename ParamTraits<P3>::StorageType>::value == 0,
2064 p3_is_refcounted_type_and_needs_scoped_refptr);
2065 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2066 typename ParamTraits<P4>::StorageType>::value == 0,
2067 p4_is_refcounted_type_and_needs_scoped_refptr);
2068 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2069 typename ParamTraits<P5>::StorageType>::value == 0,
2070 p5_is_refcounted_type_and_needs_scoped_refptr);
2072 // Do not allow binding a non-const reference parameter. Non-const reference
2073 // parameters are disallowed by the Google style guide. Also, binding a
2074 // non-const reference parameter can make for subtle bugs because the
2075 // invoked function will receive a reference to the stored copy of the
2076 // argument and not the original.
2077 COMPILE_ASSERT(
2078 !( is_non_const_reference<typename TargetTraits::B1>::value ||
2079 is_non_const_reference<typename TargetTraits::B2>::value ||
2080 is_non_const_reference<typename TargetTraits::B3>::value ||
2081 is_non_const_reference<typename TargetTraits::B4>::value ||
2082 is_non_const_reference<typename TargetTraits::B5>::value ),
2083 do_not_bind_functions_with_nonconst_ref);
2086 InvokerStorage5(Sig f, const P1& p1, const P2& p2, const P3& p3,
2087 const P4& p4, const P5& p5)
2088 : f_(f), p1_(static_cast<typename ParamTraits<P1>::StorageType>(p1)),
2089 p2_(static_cast<typename ParamTraits<P2>::StorageType>(p2)),
2090 p3_(static_cast<typename ParamTraits<P3>::StorageType>(p3)),
2091 p4_(static_cast<typename ParamTraits<P4>::StorageType>(p4)),
2092 p5_(static_cast<typename ParamTraits<P5>::StorageType>(p5)) {
2093 MaybeRefcount<IsMethod, P1>::AddRef(p1_);
2096 virtual ~InvokerStorage5() {
2097 MaybeRefcount<IsMethod, P1>::Release(p1_);
2100 Sig f_;
2101 typename ParamTraits<P1>::StorageType p1_;
2102 typename ParamTraits<P2>::StorageType p2_;
2103 typename ParamTraits<P3>::StorageType p3_;
2104 typename ParamTraits<P4>::StorageType p4_;
2105 typename ParamTraits<P5>::StorageType p5_;
2108 template <typename Sig, typename P1, typename P2, typename P3, typename P4,
2109 typename P5, typename P6>
2110 class InvokerStorage6 : public InvokerStorageBase {
2111 public:
2112 typedef InvokerStorage6 StorageType;
2113 typedef FunctionTraits<Sig> TargetTraits;
2114 typedef typename TargetTraits::IsMethod IsMethod;
2115 typedef Sig Signature;
2116 typedef ParamTraits<P1> P1Traits;
2117 typedef ParamTraits<P2> P2Traits;
2118 typedef ParamTraits<P3> P3Traits;
2119 typedef ParamTraits<P4> P4Traits;
2120 typedef ParamTraits<P5> P5Traits;
2121 typedef ParamTraits<P6> P6Traits;
2122 typedef Invoker6<IsWeakMethod<IsMethod::value, P1>::value, StorageType,
2123 typename TargetTraits::NormalizedSig> Invoker;
2124 COMPILE_ASSERT(!(IsWeakMethod<IsMethod::value, P1>::value) ||
2125 is_void<typename TargetTraits::Return>::value,
2126 weak_ptrs_can_only_bind_to_methods_without_return_values);
2128 // For methods, we need to be careful for parameter 1. We skip the
2129 // scoped_refptr check because the binder itself takes care of this. We also
2130 // disallow binding of an array as the method's target object.
2131 COMPILE_ASSERT(IsMethod::value ||
2132 internal::NeedsScopedRefptrButGetsRawPtr<
2133 typename ParamTraits<P1>::StorageType>::value == 0,
2134 p1_is_refcounted_type_and_needs_scoped_refptr);
2135 COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
2136 first_bound_argument_to_method_cannot_be_array);
2137 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2138 typename ParamTraits<P2>::StorageType>::value == 0,
2139 p2_is_refcounted_type_and_needs_scoped_refptr);
2140 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2141 typename ParamTraits<P3>::StorageType>::value == 0,
2142 p3_is_refcounted_type_and_needs_scoped_refptr);
2143 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2144 typename ParamTraits<P4>::StorageType>::value == 0,
2145 p4_is_refcounted_type_and_needs_scoped_refptr);
2146 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2147 typename ParamTraits<P5>::StorageType>::value == 0,
2148 p5_is_refcounted_type_and_needs_scoped_refptr);
2149 COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
2150 typename ParamTraits<P6>::StorageType>::value == 0,
2151 p6_is_refcounted_type_and_needs_scoped_refptr);
2153 // Do not allow binding a non-const reference parameter. Non-const reference
2154 // parameters are disallowed by the Google style guide. Also, binding a
2155 // non-const reference parameter can make for subtle bugs because the
2156 // invoked function will receive a reference to the stored copy of the
2157 // argument and not the original.
2158 COMPILE_ASSERT(
2159 !( is_non_const_reference<typename TargetTraits::B1>::value ||
2160 is_non_const_reference<typename TargetTraits::B2>::value ||
2161 is_non_const_reference<typename TargetTraits::B3>::value ||
2162 is_non_const_reference<typename TargetTraits::B4>::value ||
2163 is_non_const_reference<typename TargetTraits::B5>::value ||
2164 is_non_const_reference<typename TargetTraits::B6>::value ),
2165 do_not_bind_functions_with_nonconst_ref);
2168 InvokerStorage6(Sig f, const P1& p1, const P2& p2, const P3& p3,
2169 const P4& p4, const P5& p5, const P6& p6)
2170 : f_(f), p1_(static_cast<typename ParamTraits<P1>::StorageType>(p1)),
2171 p2_(static_cast<typename ParamTraits<P2>::StorageType>(p2)),
2172 p3_(static_cast<typename ParamTraits<P3>::StorageType>(p3)),
2173 p4_(static_cast<typename ParamTraits<P4>::StorageType>(p4)),
2174 p5_(static_cast<typename ParamTraits<P5>::StorageType>(p5)),
2175 p6_(static_cast<typename ParamTraits<P6>::StorageType>(p6)) {
2176 MaybeRefcount<IsMethod, P1>::AddRef(p1_);
2179 virtual ~InvokerStorage6() {
2180 MaybeRefcount<IsMethod, P1>::Release(p1_);
2183 Sig f_;
2184 typename ParamTraits<P1>::StorageType p1_;
2185 typename ParamTraits<P2>::StorageType p2_;
2186 typename ParamTraits<P3>::StorageType p3_;
2187 typename ParamTraits<P4>::StorageType p4_;
2188 typename ParamTraits<P5>::StorageType p5_;
2189 typename ParamTraits<P6>::StorageType p6_;
2192 } // namespace internal
2193 } // namespace base
2195 #endif // BASE_BIND_INTERNAL_H_