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