| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_BIND_H_ | 5 #ifndef BASE_BIND_H_ |
| 6 #define BASE_BIND_H_ | 6 #define BASE_BIND_H_ |
| 7 | 7 |
| 8 #include "base/bind_internal.h" | 8 #include "base/bind_internal.h" |
| 9 | 9 |
| 10 // ----------------------------------------------------------------------------- | 10 // ----------------------------------------------------------------------------- |
| 11 // Usage documentation | 11 // Usage documentation |
| 12 // ----------------------------------------------------------------------------- | 12 // ----------------------------------------------------------------------------- |
| 13 // | 13 // |
| 14 // See //docs/callback.md for documentation. | 14 // See //docs/callback.md for documentation. |
| 15 // | 15 // |
| 16 // | 16 // |
| 17 // ----------------------------------------------------------------------------- | 17 // ----------------------------------------------------------------------------- |
| 18 // Implementation notes | 18 // Implementation notes |
| 19 // ----------------------------------------------------------------------------- | 19 // ----------------------------------------------------------------------------- |
| 20 // | 20 // |
| 21 // If you're reading the implementation, before proceeding further, you should | 21 // If you're reading the implementation, before proceeding further, you should |
| 22 // read the top comment of base/bind_internal.h for a definition of common | 22 // read the top comment of base/bind_internal.h for a definition of common |
| 23 // terms and concepts. | 23 // terms and concepts. |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 namespace internal { | |
| 27 | 26 |
| 28 // Bind as OnceCallback. | 27 // Bind as OnceCallback. |
| 29 template <typename Functor, typename... Args> | 28 template <typename Functor, typename... Args> |
| 30 inline OnceCallback<MakeUnboundRunType<Functor, Args...>> | 29 inline OnceCallback<MakeUnboundRunType<Functor, Args...>> |
| 31 BindOnce(Functor&& functor, Args&&... args) { | 30 BindOnce(Functor&& functor, Args&&... args) { |
| 32 using BindState = internal::MakeBindStateType<Functor, Args...>; | 31 using BindState = internal::MakeBindStateType<Functor, Args...>; |
| 33 using UnboundRunType = MakeUnboundRunType<Functor, Args...>; | 32 using UnboundRunType = MakeUnboundRunType<Functor, Args...>; |
| 34 using Invoker = internal::Invoker<BindState, UnboundRunType>; | 33 using Invoker = internal::Invoker<BindState, UnboundRunType>; |
| 35 using CallbackType = OnceCallback<UnboundRunType>; | 34 using CallbackType = OnceCallback<UnboundRunType>; |
| 36 | 35 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 using PolymorphicInvoke = typename CallbackType::PolymorphicInvoke; | 61 using PolymorphicInvoke = typename CallbackType::PolymorphicInvoke; |
| 63 PolymorphicInvoke invoke_func = &Invoker::Run; | 62 PolymorphicInvoke invoke_func = &Invoker::Run; |
| 64 | 63 |
| 65 using InvokeFuncStorage = internal::BindStateBase::InvokeFuncStorage; | 64 using InvokeFuncStorage = internal::BindStateBase::InvokeFuncStorage; |
| 66 return CallbackType(new BindState( | 65 return CallbackType(new BindState( |
| 67 reinterpret_cast<InvokeFuncStorage>(invoke_func), | 66 reinterpret_cast<InvokeFuncStorage>(invoke_func), |
| 68 std::forward<Functor>(functor), | 67 std::forward<Functor>(functor), |
| 69 std::forward<Args>(args)...)); | 68 std::forward<Args>(args)...)); |
| 70 } | 69 } |
| 71 | 70 |
| 72 } // namespace internal | |
| 73 | |
| 74 // Unannotated Bind. | 71 // Unannotated Bind. |
| 75 // TODO(tzik): Deprecate this and migrate to OnceCallback and | 72 // TODO(tzik): Deprecate this and migrate to OnceCallback and |
| 76 // RepeatingCallback, once they get ready. | 73 // RepeatingCallback, once they get ready. |
| 77 template <typename Functor, typename... Args> | 74 template <typename Functor, typename... Args> |
| 78 inline Callback<MakeUnboundRunType<Functor, Args...>> | 75 inline Callback<MakeUnboundRunType<Functor, Args...>> |
| 79 Bind(Functor&& functor, Args&&... args) { | 76 Bind(Functor&& functor, Args&&... args) { |
| 80 return internal::BindRepeating(std::forward<Functor>(functor), | 77 return BindRepeating(std::forward<Functor>(functor), |
| 81 std::forward<Args>(args)...); | 78 std::forward<Args>(args)...); |
| 82 } | 79 } |
| 83 | 80 |
| 84 } // namespace base | 81 } // namespace base |
| 85 | 82 |
| 86 #endif // BASE_BIND_H_ | 83 #endif // BASE_BIND_H_ |
| OLD | NEW |