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 #include "base/callback_internal.h" | 9 #include "base/callback_internal.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // feels a little nicer to have the asserts here so people do not need to crack | 45 // feels a little nicer to have the asserts here so people do not need to crack |
46 // open bind_internal.h. On the other hand, it makes Bind() harder to read. | 46 // open bind_internal.h. On the other hand, it makes Bind() harder to read. |
47 | 47 |
48 namespace base { | 48 namespace base { |
49 | 49 |
50 template <typename Functor> | 50 template <typename Functor> |
51 base::Callback< | 51 base::Callback< |
52 typename internal::BindState< | 52 typename internal::BindState< |
53 typename internal::FunctorTraits<Functor>::RunnableType, | 53 typename internal::FunctorTraits<Functor>::RunnableType, |
54 typename internal::FunctorTraits<Functor>::RunType, | 54 typename internal::FunctorTraits<Functor>::RunType, |
55 void()>::UnboundRunType> | 55 internal::TypeList<>>::UnboundRunType> |
56 Bind(Functor functor) { | 56 Bind(Functor functor) { |
57 // Typedefs for how to store and run the functor. | 57 // Typedefs for how to store and run the functor. |
58 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; | 58 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
59 typedef typename internal::FunctorTraits<Functor>::RunType RunType; | 59 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
60 | 60 |
61 typedef internal::BindState<RunnableType, RunType, void()> BindState; | 61 typedef internal::BindState<RunnableType, RunType, |
| 62 internal::TypeList<>> BindState; |
62 | 63 |
63 return Callback<typename BindState::UnboundRunType>( | 64 return Callback<typename BindState::UnboundRunType>( |
64 new BindState(internal::MakeRunnable(functor))); | 65 new BindState(internal::MakeRunnable(functor))); |
65 } | 66 } |
66 | 67 |
67 template <typename Functor, typename... Args> | 68 template <typename Functor, typename... Args> |
68 base::Callback< | 69 base::Callback< |
69 typename internal::BindState< | 70 typename internal::BindState< |
70 typename internal::FunctorTraits<Functor>::RunnableType, | 71 typename internal::FunctorTraits<Functor>::RunnableType, |
71 typename internal::FunctorTraits<Functor>::RunType, | 72 typename internal::FunctorTraits<Functor>::RunType, |
72 void(typename internal::CallbackParamTraits<Args>::StorageType...)> | 73 internal::TypeList< |
| 74 typename internal::CallbackParamTraits<Args>::StorageType...>> |
73 ::UnboundRunType> | 75 ::UnboundRunType> |
74 Bind(Functor functor, const Args&... args) { | 76 Bind(Functor functor, const Args&... args) { |
75 // Typedefs for how to store and run the functor. | 77 // Typedefs for how to store and run the functor. |
76 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; | 78 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
77 typedef typename internal::FunctorTraits<Functor>::RunType RunType; | 79 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
78 | 80 |
79 // Use RunnableType::RunType instead of RunType above because our | 81 // Use RunnableType::RunType instead of RunType above because our |
80 // checks should below for bound references need to know what the actual | 82 // checks should below for bound references need to know what the actual |
81 // functor is going to interpret the argument as. | 83 // functor is going to interpret the argument as. |
82 typedef typename RunnableType::RunType BoundRunType; | 84 typedef typename RunnableType::RunType BoundRunType; |
(...skipping 11 matching lines...) Expand all Loading... |
94 // For methods, we need to be careful for parameter 1. We do not require | 96 // For methods, we need to be careful for parameter 1. We do not require |
95 // a scoped_refptr because BindState<> itself takes care of AddRef() for | 97 // a scoped_refptr because BindState<> itself takes care of AddRef() for |
96 // methods. We also disallow binding of an array as the method's target | 98 // methods. We also disallow binding of an array as the method's target |
97 // object. | 99 // object. |
98 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, | 100 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, |
99 "first_bound_argument_to_method_cannot_be_array"); | 101 "first_bound_argument_to_method_cannot_be_array"); |
100 static_assert( | 102 static_assert( |
101 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, | 103 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, |
102 "a_parameter_is_refcounted_type_and_needs_scoped_refptr"); | 104 "a_parameter_is_refcounted_type_and_needs_scoped_refptr"); |
103 | 105 |
104 typedef internal::BindState<RunnableType, RunType, | 106 typedef internal::BindState< |
105 void(typename internal::CallbackParamTraits<Args>::StorageType...)> | 107 RunnableType, RunType, |
| 108 internal::TypeList< |
| 109 typename internal::CallbackParamTraits<Args>::StorageType...>> |
106 BindState; | 110 BindState; |
107 | 111 |
108 return Callback<typename BindState::UnboundRunType>( | 112 return Callback<typename BindState::UnboundRunType>( |
109 new BindState(internal::MakeRunnable(functor), args...)); | 113 new BindState(internal::MakeRunnable(functor), args...)); |
110 } | 114 } |
111 | 115 |
112 } // namespace base | 116 } // namespace base |
113 | 117 |
114 #endif // BASE_BIND_H_ | 118 #endif // BASE_BIND_H_ |
OLD | NEW |