OLD | NEW |
1 // This file was GENERATED by command: | 1 // This file was GENERATED by command: |
2 // pump.py bind.h.pump | 2 // pump.py bind.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 10 matching lines...) Expand all Loading... |
21 // Though Bind()'s result is meant to be stored in a Callback<> type, it | 21 // Though Bind()'s result is meant to be stored in a Callback<> type, it |
22 // cannot actually return the exact type without requiring a large amount | 22 // cannot actually return the exact type without requiring a large amount |
23 // of extra template specializations. The problem is that in order to | 23 // of extra template specializations. The problem is that in order to |
24 // discern the correct specialization of Callback<>, Bind would need to | 24 // discern the correct specialization of Callback<>, Bind would need to |
25 // unwrap the function signature to determine the signature's arity, and | 25 // unwrap the function signature to determine the signature's arity, and |
26 // whether or not it is a method. | 26 // whether or not it is a method. |
27 // | 27 // |
28 // Each unique combination of (arity, function_type, num_prebound) where | 28 // Each unique combination of (arity, function_type, num_prebound) where |
29 // function_type is one of {function, method, const_method} would require | 29 // function_type is one of {function, method, const_method} would require |
30 // one specialization. We eventually have to do a similar number of | 30 // one specialization. We eventually have to do a similar number of |
31 // specializations anyways in the implementation (see the FunctionTraitsN, | 31 // specializations anyways in the implementation (see the Invoker<>, |
32 // classes). However, it is avoidable in Bind if we return the result | 32 // classes). However, it is avoidable in Bind if we return the result |
33 // via an indirection like we do below. | 33 // via an indirection like we do below. |
| 34 // |
| 35 // TODO(ajwong): We might be able to avoid this now, but need to test. |
| 36 // |
| 37 // It is possible to move most of the COMPILE_ASSERT asserts into BindState<>, |
| 38 // bit it feels a little nicer to have the asserts here so people do not |
| 39 // need to crack open bind_internal.h. On the otherhand, it makes BindState |
| 40 // harder to read. |
34 | 41 |
35 namespace base { | 42 namespace base { |
36 | 43 |
37 template <typename Sig> | 44 template <typename Functor> |
38 internal::InvokerStorageHolder<internal::InvokerStorage0<Sig> > | 45 internal::BindStateHolder< |
39 Bind(Sig f) { | 46 internal::BindState< |
40 return internal::MakeInvokerStorageHolder( | 47 typename internal::FunctorTraits<Functor>::RunnableType, |
41 new internal::InvokerStorage0<Sig>(f)); | 48 typename internal::FunctorTraits<Functor>::RunType, |
42 } | 49 void()> > |
43 | 50 Bind(Functor functor) { |
44 template <typename Sig, typename P1> | 51 // Typedefs for how to store and run the functor. |
45 internal::InvokerStorageHolder<internal::InvokerStorage1<Sig,P1> > | 52 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
46 Bind(Sig f, const P1& p1) { | 53 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
47 return internal::MakeInvokerStorageHolder( | 54 |
48 new internal::InvokerStorage1<Sig, P1>( | 55 // Use RunnableType::RunType instead of RunType above because our |
49 f, p1)); | 56 // checks should below for bound references need to know what the actual |
50 } | 57 // functor is going to interpret the argument as. |
51 | 58 typedef internal::FunctionTraits<typename RunnableType::RunType> |
52 template <typename Sig, typename P1, typename P2> | 59 BoundFunctorTraits; |
53 internal::InvokerStorageHolder<internal::InvokerStorage2<Sig,P1, P2> > | 60 |
54 Bind(Sig f, const P1& p1, const P2& p2) { | 61 |
55 return internal::MakeInvokerStorageHolder( | 62 return internal::MakeBindStateHolder( |
56 new internal::InvokerStorage2<Sig, P1, P2>( | 63 new internal::BindState<RunnableType, RunType, void()>( |
57 f, p1, p2)); | 64 internal::MakeRunnable(functor))); |
58 } | 65 } |
59 | 66 |
60 template <typename Sig, typename P1, typename P2, typename P3> | 67 template <typename Functor, typename P1> |
61 internal::InvokerStorageHolder<internal::InvokerStorage3<Sig,P1, P2, P3> > | 68 internal::BindStateHolder< |
62 Bind(Sig f, const P1& p1, const P2& p2, const P3& p3) { | 69 internal::BindState< |
63 return internal::MakeInvokerStorageHolder( | 70 typename internal::FunctorTraits<Functor>::RunnableType, |
64 new internal::InvokerStorage3<Sig, P1, P2, P3>( | 71 typename internal::FunctorTraits<Functor>::RunType, |
65 f, p1, p2, p3)); | 72 void(typename internal::CallbackParamTraits<P1>::StorageType)> > |
66 } | 73 Bind(Functor functor, const P1& p1) { |
67 | 74 // Typedefs for how to store and run the functor. |
68 template <typename Sig, typename P1, typename P2, typename P3, typename P4> | 75 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
69 internal::InvokerStorageHolder<internal::InvokerStorage4<Sig,P1, P2, P3, P4> > | 76 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
70 Bind(Sig f, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { | 77 |
71 return internal::MakeInvokerStorageHolder( | 78 // Use RunnableType::RunType instead of RunType above because our |
72 new internal::InvokerStorage4<Sig, P1, P2, P3, P4>( | 79 // checks should below for bound references need to know what the actual |
73 f, p1, p2, p3, p4)); | 80 // functor is going to interpret the argument as. |
74 } | 81 typedef internal::FunctionTraits<typename RunnableType::RunType> |
75 | 82 BoundFunctorTraits; |
76 template <typename Sig, typename P1, typename P2, typename P3, typename P4, | 83 |
| 84 // Do not allow binding a non-const reference parameter. Non-const reference |
| 85 // parameters are disallowed by the Google style guide. Also, binding a |
| 86 // non-const reference parameter can make for subtle bugs because the |
| 87 // invoked function will receive a reference to the stored copy of the |
| 88 // argument and not the original. |
| 89 COMPILE_ASSERT( |
| 90 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ), |
| 91 do_not_bind_functions_with_nonconst_ref); |
| 92 |
| 93 // For methods, we need to be careful for parameter 1. We skip the |
| 94 // scoped_refptr check because the binder itself takes care of this. We also |
| 95 // disallow binding of an array as the method's target object. |
| 96 COMPILE_ASSERT( |
| 97 internal::HasIsMethodTag<RunnableType>::value || |
| 98 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
| 99 p1_is_refcounted_type_and_needs_scoped_refptr); |
| 100 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || |
| 101 !is_array<P1>::value, |
| 102 first_bound_argument_to_method_cannot_be_array); |
| 103 |
| 104 return internal::MakeBindStateHolder( |
| 105 new internal::BindState<RunnableType, RunType, |
| 106 void(typename internal::CallbackParamTraits<P1>::StorageType)>( |
| 107 internal::MakeRunnable(functor), p1)); |
| 108 } |
| 109 |
| 110 template <typename Functor, typename P1, typename P2> |
| 111 internal::BindStateHolder< |
| 112 internal::BindState< |
| 113 typename internal::FunctorTraits<Functor>::RunnableType, |
| 114 typename internal::FunctorTraits<Functor>::RunType, |
| 115 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 116 typename internal::CallbackParamTraits<P2>::StorageType)> > |
| 117 Bind(Functor functor, const P1& p1, const P2& p2) { |
| 118 // Typedefs for how to store and run the functor. |
| 119 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
| 120 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
| 121 |
| 122 // Use RunnableType::RunType instead of RunType above because our |
| 123 // checks should below for bound references need to know what the actual |
| 124 // functor is going to interpret the argument as. |
| 125 typedef internal::FunctionTraits<typename RunnableType::RunType> |
| 126 BoundFunctorTraits; |
| 127 |
| 128 // Do not allow binding a non-const reference parameter. Non-const reference |
| 129 // parameters are disallowed by the Google style guide. Also, binding a |
| 130 // non-const reference parameter can make for subtle bugs because the |
| 131 // invoked function will receive a reference to the stored copy of the |
| 132 // argument and not the original. |
| 133 COMPILE_ASSERT( |
| 134 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || |
| 135 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ), |
| 136 do_not_bind_functions_with_nonconst_ref); |
| 137 |
| 138 // For methods, we need to be careful for parameter 1. We skip the |
| 139 // scoped_refptr check because the binder itself takes care of this. We also |
| 140 // disallow binding of an array as the method's target object. |
| 141 COMPILE_ASSERT( |
| 142 internal::HasIsMethodTag<RunnableType>::value || |
| 143 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
| 144 p1_is_refcounted_type_and_needs_scoped_refptr); |
| 145 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || |
| 146 !is_array<P1>::value, |
| 147 first_bound_argument_to_method_cannot_be_array); |
| 148 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value, |
| 149 p2_is_refcounted_type_and_needs_scoped_refptr); |
| 150 |
| 151 return internal::MakeBindStateHolder( |
| 152 new internal::BindState<RunnableType, RunType, |
| 153 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 154 typename internal::CallbackParamTraits<P2>::StorageType)>( |
| 155 internal::MakeRunnable(functor), p1, p2)); |
| 156 } |
| 157 |
| 158 template <typename Functor, typename P1, typename P2, typename P3> |
| 159 internal::BindStateHolder< |
| 160 internal::BindState< |
| 161 typename internal::FunctorTraits<Functor>::RunnableType, |
| 162 typename internal::FunctorTraits<Functor>::RunType, |
| 163 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 164 typename internal::CallbackParamTraits<P2>::StorageType, |
| 165 typename internal::CallbackParamTraits<P3>::StorageType)> > |
| 166 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3) { |
| 167 // Typedefs for how to store and run the functor. |
| 168 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
| 169 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
| 170 |
| 171 // Use RunnableType::RunType instead of RunType above because our |
| 172 // checks should below for bound references need to know what the actual |
| 173 // functor is going to interpret the argument as. |
| 174 typedef internal::FunctionTraits<typename RunnableType::RunType> |
| 175 BoundFunctorTraits; |
| 176 |
| 177 // Do not allow binding a non-const reference parameter. Non-const reference |
| 178 // parameters are disallowed by the Google style guide. Also, binding a |
| 179 // non-const reference parameter can make for subtle bugs because the |
| 180 // invoked function will receive a reference to the stored copy of the |
| 181 // argument and not the original. |
| 182 COMPILE_ASSERT( |
| 183 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || |
| 184 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value || |
| 185 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ), |
| 186 do_not_bind_functions_with_nonconst_ref); |
| 187 |
| 188 // For methods, we need to be careful for parameter 1. We skip the |
| 189 // scoped_refptr check because the binder itself takes care of this. We also |
| 190 // disallow binding of an array as the method's target object. |
| 191 COMPILE_ASSERT( |
| 192 internal::HasIsMethodTag<RunnableType>::value || |
| 193 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
| 194 p1_is_refcounted_type_and_needs_scoped_refptr); |
| 195 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || |
| 196 !is_array<P1>::value, |
| 197 first_bound_argument_to_method_cannot_be_array); |
| 198 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value, |
| 199 p2_is_refcounted_type_and_needs_scoped_refptr); |
| 200 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value, |
| 201 p3_is_refcounted_type_and_needs_scoped_refptr); |
| 202 |
| 203 return internal::MakeBindStateHolder( |
| 204 new internal::BindState<RunnableType, RunType, |
| 205 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 206 typename internal::CallbackParamTraits<P2>::StorageType, |
| 207 typename internal::CallbackParamTraits<P3>::StorageType)>( |
| 208 internal::MakeRunnable(functor), p1, p2, p3)); |
| 209 } |
| 210 |
| 211 template <typename Functor, typename P1, typename P2, typename P3, typename P4> |
| 212 internal::BindStateHolder< |
| 213 internal::BindState< |
| 214 typename internal::FunctorTraits<Functor>::RunnableType, |
| 215 typename internal::FunctorTraits<Functor>::RunType, |
| 216 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 217 typename internal::CallbackParamTraits<P2>::StorageType, |
| 218 typename internal::CallbackParamTraits<P3>::StorageType, |
| 219 typename internal::CallbackParamTraits<P4>::StorageType)> > |
| 220 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { |
| 221 // Typedefs for how to store and run the functor. |
| 222 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
| 223 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
| 224 |
| 225 // Use RunnableType::RunType instead of RunType above because our |
| 226 // checks should below for bound references need to know what the actual |
| 227 // functor is going to interpret the argument as. |
| 228 typedef internal::FunctionTraits<typename RunnableType::RunType> |
| 229 BoundFunctorTraits; |
| 230 |
| 231 // Do not allow binding a non-const reference parameter. Non-const reference |
| 232 // parameters are disallowed by the Google style guide. Also, binding a |
| 233 // non-const reference parameter can make for subtle bugs because the |
| 234 // invoked function will receive a reference to the stored copy of the |
| 235 // argument and not the original. |
| 236 COMPILE_ASSERT( |
| 237 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || |
| 238 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value || |
| 239 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value || |
| 240 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ), |
| 241 do_not_bind_functions_with_nonconst_ref); |
| 242 |
| 243 // For methods, we need to be careful for parameter 1. We skip the |
| 244 // scoped_refptr check because the binder itself takes care of this. We also |
| 245 // disallow binding of an array as the method's target object. |
| 246 COMPILE_ASSERT( |
| 247 internal::HasIsMethodTag<RunnableType>::value || |
| 248 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
| 249 p1_is_refcounted_type_and_needs_scoped_refptr); |
| 250 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || |
| 251 !is_array<P1>::value, |
| 252 first_bound_argument_to_method_cannot_be_array); |
| 253 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value, |
| 254 p2_is_refcounted_type_and_needs_scoped_refptr); |
| 255 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value, |
| 256 p3_is_refcounted_type_and_needs_scoped_refptr); |
| 257 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value, |
| 258 p4_is_refcounted_type_and_needs_scoped_refptr); |
| 259 |
| 260 return internal::MakeBindStateHolder( |
| 261 new internal::BindState<RunnableType, RunType, |
| 262 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 263 typename internal::CallbackParamTraits<P2>::StorageType, |
| 264 typename internal::CallbackParamTraits<P3>::StorageType, |
| 265 typename internal::CallbackParamTraits<P4>::StorageType)>( |
| 266 internal::MakeRunnable(functor), p1, p2, p3, p4)); |
| 267 } |
| 268 |
| 269 template <typename Functor, typename P1, typename P2, typename P3, typename P4, |
77 typename P5> | 270 typename P5> |
78 internal::InvokerStorageHolder<internal::InvokerStorage5<Sig,P1, P2, P3, P4, | 271 internal::BindStateHolder< |
79 P5> > | 272 internal::BindState< |
80 Bind(Sig f, const P1& p1, const P2& p2, const P3& p3, const P4& p4, | 273 typename internal::FunctorTraits<Functor>::RunnableType, |
| 274 typename internal::FunctorTraits<Functor>::RunType, |
| 275 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 276 typename internal::CallbackParamTraits<P2>::StorageType, |
| 277 typename internal::CallbackParamTraits<P3>::StorageType, |
| 278 typename internal::CallbackParamTraits<P4>::StorageType, |
| 279 typename internal::CallbackParamTraits<P5>::StorageType)> > |
| 280 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4, |
81 const P5& p5) { | 281 const P5& p5) { |
82 return internal::MakeInvokerStorageHolder( | 282 // Typedefs for how to store and run the functor. |
83 new internal::InvokerStorage5<Sig, P1, P2, P3, P4, P5>( | 283 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
84 f, p1, p2, p3, p4, p5)); | 284 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
85 } | 285 |
86 | 286 // Use RunnableType::RunType instead of RunType above because our |
87 template <typename Sig, typename P1, typename P2, typename P3, typename P4, | 287 // checks should below for bound references need to know what the actual |
| 288 // functor is going to interpret the argument as. |
| 289 typedef internal::FunctionTraits<typename RunnableType::RunType> |
| 290 BoundFunctorTraits; |
| 291 |
| 292 // Do not allow binding a non-const reference parameter. Non-const reference |
| 293 // parameters are disallowed by the Google style guide. Also, binding a |
| 294 // non-const reference parameter can make for subtle bugs because the |
| 295 // invoked function will receive a reference to the stored copy of the |
| 296 // argument and not the original. |
| 297 COMPILE_ASSERT( |
| 298 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || |
| 299 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value || |
| 300 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value || |
| 301 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value || |
| 302 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ), |
| 303 do_not_bind_functions_with_nonconst_ref); |
| 304 |
| 305 // For methods, we need to be careful for parameter 1. We skip the |
| 306 // scoped_refptr check because the binder itself takes care of this. We also |
| 307 // disallow binding of an array as the method's target object. |
| 308 COMPILE_ASSERT( |
| 309 internal::HasIsMethodTag<RunnableType>::value || |
| 310 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
| 311 p1_is_refcounted_type_and_needs_scoped_refptr); |
| 312 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || |
| 313 !is_array<P1>::value, |
| 314 first_bound_argument_to_method_cannot_be_array); |
| 315 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value, |
| 316 p2_is_refcounted_type_and_needs_scoped_refptr); |
| 317 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value, |
| 318 p3_is_refcounted_type_and_needs_scoped_refptr); |
| 319 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value, |
| 320 p4_is_refcounted_type_and_needs_scoped_refptr); |
| 321 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value, |
| 322 p5_is_refcounted_type_and_needs_scoped_refptr); |
| 323 |
| 324 return internal::MakeBindStateHolder( |
| 325 new internal::BindState<RunnableType, RunType, |
| 326 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 327 typename internal::CallbackParamTraits<P2>::StorageType, |
| 328 typename internal::CallbackParamTraits<P3>::StorageType, |
| 329 typename internal::CallbackParamTraits<P4>::StorageType, |
| 330 typename internal::CallbackParamTraits<P5>::StorageType)>( |
| 331 internal::MakeRunnable(functor), p1, p2, p3, p4, p5)); |
| 332 } |
| 333 |
| 334 template <typename Functor, typename P1, typename P2, typename P3, typename P4, |
88 typename P5, typename P6> | 335 typename P5, typename P6> |
89 internal::InvokerStorageHolder<internal::InvokerStorage6<Sig,P1, P2, P3, P4, | 336 internal::BindStateHolder< |
90 P5, P6> > | 337 internal::BindState< |
91 Bind(Sig f, const P1& p1, const P2& p2, const P3& p3, const P4& p4, | 338 typename internal::FunctorTraits<Functor>::RunnableType, |
| 339 typename internal::FunctorTraits<Functor>::RunType, |
| 340 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 341 typename internal::CallbackParamTraits<P2>::StorageType, |
| 342 typename internal::CallbackParamTraits<P3>::StorageType, |
| 343 typename internal::CallbackParamTraits<P4>::StorageType, |
| 344 typename internal::CallbackParamTraits<P5>::StorageType, |
| 345 typename internal::CallbackParamTraits<P6>::StorageType)> > |
| 346 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4, |
92 const P5& p5, const P6& p6) { | 347 const P5& p5, const P6& p6) { |
93 return internal::MakeInvokerStorageHolder( | 348 // Typedefs for how to store and run the functor. |
94 new internal::InvokerStorage6<Sig, P1, P2, P3, P4, P5, P6>( | 349 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; |
95 f, p1, p2, p3, p4, p5, p6)); | 350 typedef typename internal::FunctorTraits<Functor>::RunType RunType; |
96 } | 351 |
97 | 352 // Use RunnableType::RunType instead of RunType above because our |
98 // Specializations to allow binding all the free arguments in a | 353 // checks should below for bound references need to know what the actual |
99 // pre-existing base::Callback<>. This does not give full support for | 354 // functor is going to interpret the argument as. |
100 // currying, but is significantly simpler and addresses the use case | 355 typedef internal::FunctionTraits<typename RunnableType::RunType> |
101 // where a base::Callback<> needs to be invoked on another context/thread. | 356 BoundFunctorTraits; |
102 template <typename Sig, typename P1> | 357 |
103 base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1) { | 358 // Do not allow binding a non-const reference parameter. Non-const reference |
104 return base::Bind(&internal::BindMoreFunc1<Sig, P1>, callback, p1); | 359 // parameters are disallowed by the Google style guide. Also, binding a |
105 } | 360 // non-const reference parameter can make for subtle bugs because the |
106 | 361 // invoked function will receive a reference to the stored copy of the |
107 template <typename Sig, typename P1, typename P2> | 362 // argument and not the original. |
108 base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1, | 363 COMPILE_ASSERT( |
109 const P2& p2) { | 364 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value || |
110 return base::Bind(&internal::BindMoreFunc2<Sig, P1, P2>, callback, p1, p2); | 365 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value || |
111 } | 366 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value || |
112 | 367 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value || |
113 template <typename Sig, typename P1, typename P2, typename P3> | 368 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value || |
114 base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1, | 369 is_non_const_reference<typename BoundFunctorTraits::A6Type>::value ), |
115 const P2& p2, const P3& p3) { | 370 do_not_bind_functions_with_nonconst_ref); |
116 return base::Bind(&internal::BindMoreFunc3<Sig, P1, P2, P3>, callback, p1, | 371 |
117 p2, p3); | 372 // For methods, we need to be careful for parameter 1. We skip the |
118 } | 373 // scoped_refptr check because the binder itself takes care of this. We also |
119 | 374 // disallow binding of an array as the method's target object. |
120 template <typename Sig, typename P1, typename P2, typename P3, typename P4> | 375 COMPILE_ASSERT( |
121 base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1, | 376 internal::HasIsMethodTag<RunnableType>::value || |
122 const P2& p2, const P3& p3, const P4& p4) { | 377 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, |
123 return base::Bind(&internal::BindMoreFunc4<Sig, P1, P2, P3, P4>, callback, | 378 p1_is_refcounted_type_and_needs_scoped_refptr); |
124 p1, p2, p3, p4); | 379 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || |
125 } | 380 !is_array<P1>::value, |
126 | 381 first_bound_argument_to_method_cannot_be_array); |
127 template <typename Sig, typename P1, typename P2, typename P3, typename P4, | 382 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value, |
128 typename P5> | 383 p2_is_refcounted_type_and_needs_scoped_refptr); |
129 base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1, | 384 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value, |
130 const P2& p2, const P3& p3, const P4& p4, const P5& p5) { | 385 p3_is_refcounted_type_and_needs_scoped_refptr); |
131 return base::Bind(&internal::BindMoreFunc5<Sig, P1, P2, P3, P4, P5>, | 386 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value, |
132 callback, p1, p2, p3, p4, p5); | 387 p4_is_refcounted_type_and_needs_scoped_refptr); |
133 } | 388 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value, |
134 | 389 p5_is_refcounted_type_and_needs_scoped_refptr); |
135 template <typename Sig, typename P1, typename P2, typename P3, typename P4, | 390 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value, |
136 typename P5, typename P6> | 391 p6_is_refcounted_type_and_needs_scoped_refptr); |
137 base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1, | 392 |
138 const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) { | 393 return internal::MakeBindStateHolder( |
139 return base::Bind(&internal::BindMoreFunc6<Sig, P1, P2, P3, P4, P5, P6>, | 394 new internal::BindState<RunnableType, RunType, |
140 callback, p1, p2, p3, p4, p5, p6); | 395 void(typename internal::CallbackParamTraits<P1>::StorageType, |
| 396 typename internal::CallbackParamTraits<P2>::StorageType, |
| 397 typename internal::CallbackParamTraits<P3>::StorageType, |
| 398 typename internal::CallbackParamTraits<P4>::StorageType, |
| 399 typename internal::CallbackParamTraits<P5>::StorageType, |
| 400 typename internal::CallbackParamTraits<P6>::StorageType)>( |
| 401 internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6)); |
141 } | 402 } |
142 | 403 |
143 } // namespace base | 404 } // namespace base |
144 | 405 |
145 #endif // BASE_BIND_H_ | 406 #endif // BASE_BIND_H_ |
OLD | NEW |