OLD | NEW |
1 // This file was GENERATED by command: | 1 // This file was GENERATED by command: |
2 // pump.py callback.h.pump | 2 // pump.py callback.h.pump |
3 // DO NOT EDIT BY HAND!!! | 3 // DO NOT EDIT BY HAND!!! |
4 | 4 |
5 | 5 |
6 | 6 |
7 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 8 // Use of this source code is governed by a BSD-style license that can be |
9 // found in the LICENSE file. | 9 // found in the LICENSE file. |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // void Bar(char* ptr); | 220 // void Bar(char* ptr); |
221 // Bind(&Foo, "test"); | 221 // Bind(&Foo, "test"); |
222 // Bind(&Bar, "test"); // This fails because ptr is not const. | 222 // Bind(&Bar, "test"); // This fails because ptr is not const. |
223 | 223 |
224 namespace base { | 224 namespace base { |
225 | 225 |
226 // First, we forward declare the Callback class template. This informs the | 226 // First, we forward declare the Callback class template. This informs the |
227 // compiler that the template only has 1 type parameter which is the function | 227 // compiler that the template only has 1 type parameter which is the function |
228 // signature that the Callback is representing. | 228 // signature that the Callback is representing. |
229 // | 229 // |
230 // After this, create template specializations for 0-6 parameters. Note that | 230 // After this, create template specializations for 0-7 parameters. Note that |
231 // even though the template typelist grows, the specialization still | 231 // even though the template typelist grows, the specialization still |
232 // only has one type: the function signature. | 232 // only has one type: the function signature. |
233 template <typename Sig> | 233 template <typename Sig> |
234 class Callback; | 234 class Callback; |
235 | 235 |
236 template <typename R> | 236 template <typename R> |
237 class Callback<R(void)> : public internal::CallbackBase { | 237 class Callback<R(void)> : public internal::CallbackBase { |
238 public: | 238 public: |
239 typedef R(RunType)(); | 239 typedef R(RunType)(); |
240 | 240 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 internal::BindStateBase*, | 566 internal::BindStateBase*, |
567 typename internal::CallbackParamTraits<A1>::ForwardType, | 567 typename internal::CallbackParamTraits<A1>::ForwardType, |
568 typename internal::CallbackParamTraits<A2>::ForwardType, | 568 typename internal::CallbackParamTraits<A2>::ForwardType, |
569 typename internal::CallbackParamTraits<A3>::ForwardType, | 569 typename internal::CallbackParamTraits<A3>::ForwardType, |
570 typename internal::CallbackParamTraits<A4>::ForwardType, | 570 typename internal::CallbackParamTraits<A4>::ForwardType, |
571 typename internal::CallbackParamTraits<A5>::ForwardType, | 571 typename internal::CallbackParamTraits<A5>::ForwardType, |
572 typename internal::CallbackParamTraits<A6>::ForwardType); | 572 typename internal::CallbackParamTraits<A6>::ForwardType); |
573 | 573 |
574 }; | 574 }; |
575 | 575 |
| 576 template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 577 typename A5, typename A6, typename A7> |
| 578 class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase { |
| 579 public: |
| 580 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); |
| 581 |
| 582 Callback() : CallbackBase(NULL, NULL) { } |
| 583 |
| 584 // We pass BindStateHolder by const ref to avoid incurring an |
| 585 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 586 // We cannot use a normal reference because the compiler will warn |
| 587 // since this is often used on a return value, which is a temporary. |
| 588 // |
| 589 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 590 // return the exact Callback<> type. See base/bind.h for details. |
| 591 template <typename T> |
| 592 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 593 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 594 // Force the assignment to a location variable of PolymorphicInvoke |
| 595 // so the compiler will typecheck that the passed in Run() method has |
| 596 // the correct type. |
| 597 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 598 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 599 } |
| 600 |
| 601 bool Equals(const Callback& other) const { |
| 602 return CallbackBase::Equals(other); |
| 603 } |
| 604 |
| 605 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 606 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
| 607 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
| 608 typename internal::CallbackParamTraits<A4>::ForwardType a4, |
| 609 typename internal::CallbackParamTraits<A5>::ForwardType a5, |
| 610 typename internal::CallbackParamTraits<A6>::ForwardType a6, |
| 611 typename internal::CallbackParamTraits<A7>::ForwardType a7) const { |
| 612 PolymorphicInvoke f = |
| 613 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
| 614 |
| 615 return f(bind_state_.get(), a1, |
| 616 a2, |
| 617 a3, |
| 618 a4, |
| 619 a5, |
| 620 a6, |
| 621 a7); |
| 622 } |
| 623 |
| 624 private: |
| 625 typedef R(*PolymorphicInvoke)( |
| 626 internal::BindStateBase*, |
| 627 typename internal::CallbackParamTraits<A1>::ForwardType, |
| 628 typename internal::CallbackParamTraits<A2>::ForwardType, |
| 629 typename internal::CallbackParamTraits<A3>::ForwardType, |
| 630 typename internal::CallbackParamTraits<A4>::ForwardType, |
| 631 typename internal::CallbackParamTraits<A5>::ForwardType, |
| 632 typename internal::CallbackParamTraits<A6>::ForwardType, |
| 633 typename internal::CallbackParamTraits<A7>::ForwardType); |
| 634 |
| 635 }; |
| 636 |
576 | 637 |
577 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 638 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
578 // will be used in a lot of APIs with delayed execution. | 639 // will be used in a lot of APIs with delayed execution. |
579 typedef Callback<void(void)> Closure; | 640 typedef Callback<void(void)> Closure; |
580 | 641 |
581 } // namespace base | 642 } // namespace base |
582 | 643 |
583 #endif // BASE_CALLBACK_H | 644 #endif // BASE_CALLBACK_H |
OLD | NEW |