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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 6 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
7 // 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 |
8 // found in the LICENSE file. | 8 // found in the LICENSE file. |
9 | 9 |
10 #ifndef BASE_CALLBACK_H_ | 10 #ifndef BASE_CALLBACK_H_ |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // HOW THE IMPLEMENTATION WORKS: | 122 // HOW THE IMPLEMENTATION WORKS: |
123 // | 123 // |
124 // There are three main components to the system: | 124 // There are three main components to the system: |
125 // 1) The Callback classes. | 125 // 1) The Callback classes. |
126 // 2) The Bind() functions. | 126 // 2) The Bind() functions. |
127 // 3) The arguments wrappers (e.g., Unretained() and ConstRef()). | 127 // 3) The arguments wrappers (e.g., Unretained() and ConstRef()). |
128 // | 128 // |
129 // The Callback classes represent a generic function pointer. Internally, | 129 // The Callback classes represent a generic function pointer. Internally, |
130 // it stores a refcounted piece of state that represents the target function | 130 // it stores a refcounted piece of state that represents the target function |
131 // and all its bound parameters. Each Callback specialization has a templated | 131 // and all its bound parameters. Each Callback specialization has a templated |
132 // constructor that takes an BindStateHolder<> object. In the context of | 132 // constructor that takes an BindState<>*. In the context of the constructor, |
133 // the constructor, the static type of this BindStateHolder<> object | 133 // the static type of this BindState<> pointer uniquely identifies the |
134 // uniquely identifies the function it is representing, all its bound | 134 // function it is representing, all its bound parameters, and a Run() method |
135 // parameters, and a DoInvoke() that is capable of invoking the target. | 135 // that is capable of invoking the target. |
136 // | 136 // |
137 // Callback's constructor is takes the BindStateHolder<> that has the | 137 // Callback's constructor takes the BindState<>* that has the full static type |
138 // full static type and erases the target function type, and the bound | 138 // and erases the target function type as well as the types of the bound |
139 // parameters. It does this by storing a pointer to the specific DoInvoke() | 139 // parameters. It does this by storing a pointer to the specific Run() |
140 // function, and upcasting the state of BindStateHolder<> to a | 140 // function, and upcasting the state of BindState<>* to a |
141 // BindStateBase. This is safe as long as this BindStateBase pointer | 141 // BindStateBase*. This is safe as long as this BindStateBase pointer |
142 // is only used with the stored DoInvoke() pointer. | 142 // is only used with the stored Run() pointer. |
143 // | 143 // |
144 // To create BindStateHolder<> objects, we use the Bind() functions. | 144 // To BindState<> objects are created inside the Bind() functions. |
145 // These functions, along with a set of internal templates, are reponsible for | 145 // These functions, along with a set of internal templates, are responsible for |
146 // | 146 // |
147 // - Unwrapping the function signature into return type, and parameters | 147 // - Unwrapping the function signature into return type, and parameters |
148 // - Determining the number of parameters that are bound | 148 // - Determining the number of parameters that are bound |
149 // - Creating the storage for the bound parameters | 149 // - Creating the BindState storing the bound parameters |
150 // - Performing compile-time asserts to avoid error-prone behavior | 150 // - Performing compile-time asserts to avoid error-prone behavior |
151 // - Returning an BindStateHolder<> with an DoInvoke() that has an arity | 151 // - Returning an Callback<> with an arity matching the number of unbound |
152 // matching the number of unbound parameters, and knows the correct | 152 // parameters and that knows the correct refcounting semantics for the |
153 // refcounting semantics for the target object if we are binding a class | 153 // target object if we are binding a method. |
154 // method. | |
155 // | 154 // |
156 // The Bind functions do the above using type-inference, and template | 155 // The Bind functions do the above using type-inference, and template |
157 // specializations. | 156 // specializations. |
158 // | 157 // |
159 // By default Bind() will store copies of all bound parameters, and attempt | 158 // By default Bind() will store copies of all bound parameters, and attempt |
160 // to refcount a target object if the function being bound is a class method. | 159 // to refcount a target object if the function being bound is a class method. |
161 // | 160 // |
162 // To change this behavior, we introduce a set of argument wrappers | 161 // To change this behavior, we introduce a set of argument wrappers |
163 // (e.g., Unretained(), and ConstRef()). These are simple container templates | 162 // (e.g., Unretained(), and ConstRef()). These are simple container templates |
164 // that are passed by value, and wrap a pointer to argument. See the | 163 // that are passed by value, and wrap a pointer to argument. See the |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // | 231 // |
233 // After this, create template specializations for 0-7 parameters. Note that | 232 // After this, create template specializations for 0-7 parameters. Note that |
234 // even though the template typelist grows, the specialization still | 233 // even though the template typelist grows, the specialization still |
235 // only has one type: the function signature. | 234 // only has one type: the function signature. |
236 // | 235 // |
237 // If you are thinking of forward declaring Callback in your own header file, | 236 // If you are thinking of forward declaring Callback in your own header file, |
238 // please include "base/callback_forward.h" instead. | 237 // please include "base/callback_forward.h" instead. |
239 template <typename Sig> | 238 template <typename Sig> |
240 class Callback; | 239 class Callback; |
241 | 240 |
| 241 namespace internal { |
| 242 template <typename Runnable, typename RunType, typename BoundArgsType> |
| 243 struct BindState; |
| 244 } // namespace internal |
| 245 |
242 template <typename R> | 246 template <typename R> |
243 class Callback<R(void)> : public internal::CallbackBase { | 247 class Callback<R(void)> : public internal::CallbackBase { |
244 public: | 248 public: |
245 typedef R(RunType)(); | 249 typedef R(RunType)(); |
246 | 250 |
247 Callback() : CallbackBase(NULL, NULL) { } | 251 Callback() : CallbackBase(NULL) { } |
248 | 252 |
249 // We pass BindStateHolder by const ref to avoid incurring an | |
250 // unnecessary AddRef/Unref pair even though we will modify the object. | |
251 // We cannot use a normal reference because the compiler will warn | |
252 // since this is often used on a return value, which is a temporary. | |
253 // | |
254 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 253 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
255 // return the exact Callback<> type. See base/bind.h for details. | 254 // return the exact Callback<> type. See base/bind.h for details. |
256 template <typename T> | 255 template <typename Runnable, typename RunType, typename BoundArgsType> |
257 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 256 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
258 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 257 : CallbackBase(bind_state) { |
259 // Force the assignment to a location variable of PolymorphicInvoke | 258 |
| 259 // Force the assignment to a local variable of PolymorphicInvoke |
260 // so the compiler will typecheck that the passed in Run() method has | 260 // so the compiler will typecheck that the passed in Run() method has |
261 // the correct type. | 261 // the correct type. |
262 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 262 PolymorphicInvoke invoke_func = |
| 263 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 264 ::InvokerType::Run; |
263 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 265 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
264 } | 266 } |
265 | 267 |
266 bool Equals(const Callback& other) const { | 268 bool Equals(const Callback& other) const { |
267 return CallbackBase::Equals(other); | 269 return CallbackBase::Equals(other); |
268 } | 270 } |
269 | 271 |
270 R Run() const { | 272 R Run() const { |
271 PolymorphicInvoke f = | 273 PolymorphicInvoke f = |
272 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 274 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
273 | 275 |
274 return f(bind_state_.get()); | 276 return f(bind_state_.get()); |
275 } | 277 } |
276 | 278 |
277 private: | 279 private: |
278 typedef R(*PolymorphicInvoke)( | 280 typedef R(*PolymorphicInvoke)( |
279 internal::BindStateBase*); | 281 internal::BindStateBase*); |
280 | 282 |
281 }; | 283 }; |
282 | 284 |
283 template <typename R, typename A1> | 285 template <typename R, typename A1> |
284 class Callback<R(A1)> : public internal::CallbackBase { | 286 class Callback<R(A1)> : public internal::CallbackBase { |
285 public: | 287 public: |
286 typedef R(RunType)(A1); | 288 typedef R(RunType)(A1); |
287 | 289 |
288 Callback() : CallbackBase(NULL, NULL) { } | 290 Callback() : CallbackBase(NULL) { } |
289 | 291 |
290 // We pass BindStateHolder by const ref to avoid incurring an | |
291 // unnecessary AddRef/Unref pair even though we will modify the object. | |
292 // We cannot use a normal reference because the compiler will warn | |
293 // since this is often used on a return value, which is a temporary. | |
294 // | |
295 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 292 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
296 // return the exact Callback<> type. See base/bind.h for details. | 293 // return the exact Callback<> type. See base/bind.h for details. |
297 template <typename T> | 294 template <typename Runnable, typename RunType, typename BoundArgsType> |
298 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 295 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
299 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 296 : CallbackBase(bind_state) { |
300 // Force the assignment to a location variable of PolymorphicInvoke | 297 |
| 298 // Force the assignment to a local variable of PolymorphicInvoke |
301 // so the compiler will typecheck that the passed in Run() method has | 299 // so the compiler will typecheck that the passed in Run() method has |
302 // the correct type. | 300 // the correct type. |
303 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 301 PolymorphicInvoke invoke_func = |
| 302 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 303 ::InvokerType::Run; |
304 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 304 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
305 } | 305 } |
306 | 306 |
307 bool Equals(const Callback& other) const { | 307 bool Equals(const Callback& other) const { |
308 return CallbackBase::Equals(other); | 308 return CallbackBase::Equals(other); |
309 } | 309 } |
310 | 310 |
311 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1) const { | 311 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1) const { |
312 PolymorphicInvoke f = | 312 PolymorphicInvoke f = |
313 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 313 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
314 | 314 |
315 return f(bind_state_.get(), a1); | 315 return f(bind_state_.get(), a1); |
316 } | 316 } |
317 | 317 |
318 private: | 318 private: |
319 typedef R(*PolymorphicInvoke)( | 319 typedef R(*PolymorphicInvoke)( |
320 internal::BindStateBase*, | 320 internal::BindStateBase*, |
321 typename internal::CallbackParamTraits<A1>::ForwardType); | 321 typename internal::CallbackParamTraits<A1>::ForwardType); |
322 | 322 |
323 }; | 323 }; |
324 | 324 |
325 template <typename R, typename A1, typename A2> | 325 template <typename R, typename A1, typename A2> |
326 class Callback<R(A1, A2)> : public internal::CallbackBase { | 326 class Callback<R(A1, A2)> : public internal::CallbackBase { |
327 public: | 327 public: |
328 typedef R(RunType)(A1, A2); | 328 typedef R(RunType)(A1, A2); |
329 | 329 |
330 Callback() : CallbackBase(NULL, NULL) { } | 330 Callback() : CallbackBase(NULL) { } |
331 | 331 |
332 // We pass BindStateHolder by const ref to avoid incurring an | |
333 // unnecessary AddRef/Unref pair even though we will modify the object. | |
334 // We cannot use a normal reference because the compiler will warn | |
335 // since this is often used on a return value, which is a temporary. | |
336 // | |
337 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 332 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
338 // return the exact Callback<> type. See base/bind.h for details. | 333 // return the exact Callback<> type. See base/bind.h for details. |
339 template <typename T> | 334 template <typename Runnable, typename RunType, typename BoundArgsType> |
340 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 335 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
341 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 336 : CallbackBase(bind_state) { |
342 // Force the assignment to a location variable of PolymorphicInvoke | 337 |
| 338 // Force the assignment to a local variable of PolymorphicInvoke |
343 // so the compiler will typecheck that the passed in Run() method has | 339 // so the compiler will typecheck that the passed in Run() method has |
344 // the correct type. | 340 // the correct type. |
345 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 341 PolymorphicInvoke invoke_func = |
| 342 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 343 ::InvokerType::Run; |
346 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 344 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
347 } | 345 } |
348 | 346 |
349 bool Equals(const Callback& other) const { | 347 bool Equals(const Callback& other) const { |
350 return CallbackBase::Equals(other); | 348 return CallbackBase::Equals(other); |
351 } | 349 } |
352 | 350 |
353 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 351 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
354 typename internal::CallbackParamTraits<A2>::ForwardType a2) const { | 352 typename internal::CallbackParamTraits<A2>::ForwardType a2) const { |
355 PolymorphicInvoke f = | 353 PolymorphicInvoke f = |
356 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 354 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
357 | 355 |
358 return f(bind_state_.get(), a1, | 356 return f(bind_state_.get(), a1, |
359 a2); | 357 a2); |
360 } | 358 } |
361 | 359 |
362 private: | 360 private: |
363 typedef R(*PolymorphicInvoke)( | 361 typedef R(*PolymorphicInvoke)( |
364 internal::BindStateBase*, | 362 internal::BindStateBase*, |
365 typename internal::CallbackParamTraits<A1>::ForwardType, | 363 typename internal::CallbackParamTraits<A1>::ForwardType, |
366 typename internal::CallbackParamTraits<A2>::ForwardType); | 364 typename internal::CallbackParamTraits<A2>::ForwardType); |
367 | 365 |
368 }; | 366 }; |
369 | 367 |
370 template <typename R, typename A1, typename A2, typename A3> | 368 template <typename R, typename A1, typename A2, typename A3> |
371 class Callback<R(A1, A2, A3)> : public internal::CallbackBase { | 369 class Callback<R(A1, A2, A3)> : public internal::CallbackBase { |
372 public: | 370 public: |
373 typedef R(RunType)(A1, A2, A3); | 371 typedef R(RunType)(A1, A2, A3); |
374 | 372 |
375 Callback() : CallbackBase(NULL, NULL) { } | 373 Callback() : CallbackBase(NULL) { } |
376 | 374 |
377 // We pass BindStateHolder by const ref to avoid incurring an | |
378 // unnecessary AddRef/Unref pair even though we will modify the object. | |
379 // We cannot use a normal reference because the compiler will warn | |
380 // since this is often used on a return value, which is a temporary. | |
381 // | |
382 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 375 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
383 // return the exact Callback<> type. See base/bind.h for details. | 376 // return the exact Callback<> type. See base/bind.h for details. |
384 template <typename T> | 377 template <typename Runnable, typename RunType, typename BoundArgsType> |
385 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 378 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
386 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 379 : CallbackBase(bind_state) { |
387 // Force the assignment to a location variable of PolymorphicInvoke | 380 |
| 381 // Force the assignment to a local variable of PolymorphicInvoke |
388 // so the compiler will typecheck that the passed in Run() method has | 382 // so the compiler will typecheck that the passed in Run() method has |
389 // the correct type. | 383 // the correct type. |
390 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 384 PolymorphicInvoke invoke_func = |
| 385 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 386 ::InvokerType::Run; |
391 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 387 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
392 } | 388 } |
393 | 389 |
394 bool Equals(const Callback& other) const { | 390 bool Equals(const Callback& other) const { |
395 return CallbackBase::Equals(other); | 391 return CallbackBase::Equals(other); |
396 } | 392 } |
397 | 393 |
398 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 394 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
399 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 395 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
400 typename internal::CallbackParamTraits<A3>::ForwardType a3) const { | 396 typename internal::CallbackParamTraits<A3>::ForwardType a3) const { |
(...skipping 12 matching lines...) Expand all Loading... |
413 typename internal::CallbackParamTraits<A2>::ForwardType, | 409 typename internal::CallbackParamTraits<A2>::ForwardType, |
414 typename internal::CallbackParamTraits<A3>::ForwardType); | 410 typename internal::CallbackParamTraits<A3>::ForwardType); |
415 | 411 |
416 }; | 412 }; |
417 | 413 |
418 template <typename R, typename A1, typename A2, typename A3, typename A4> | 414 template <typename R, typename A1, typename A2, typename A3, typename A4> |
419 class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase { | 415 class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase { |
420 public: | 416 public: |
421 typedef R(RunType)(A1, A2, A3, A4); | 417 typedef R(RunType)(A1, A2, A3, A4); |
422 | 418 |
423 Callback() : CallbackBase(NULL, NULL) { } | 419 Callback() : CallbackBase(NULL) { } |
424 | 420 |
425 // We pass BindStateHolder by const ref to avoid incurring an | |
426 // unnecessary AddRef/Unref pair even though we will modify the object. | |
427 // We cannot use a normal reference because the compiler will warn | |
428 // since this is often used on a return value, which is a temporary. | |
429 // | |
430 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 421 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
431 // return the exact Callback<> type. See base/bind.h for details. | 422 // return the exact Callback<> type. See base/bind.h for details. |
432 template <typename T> | 423 template <typename Runnable, typename RunType, typename BoundArgsType> |
433 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 424 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
434 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 425 : CallbackBase(bind_state) { |
435 // Force the assignment to a location variable of PolymorphicInvoke | 426 |
| 427 // Force the assignment to a local variable of PolymorphicInvoke |
436 // so the compiler will typecheck that the passed in Run() method has | 428 // so the compiler will typecheck that the passed in Run() method has |
437 // the correct type. | 429 // the correct type. |
438 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 430 PolymorphicInvoke invoke_func = |
| 431 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 432 ::InvokerType::Run; |
439 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 433 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
440 } | 434 } |
441 | 435 |
442 bool Equals(const Callback& other) const { | 436 bool Equals(const Callback& other) const { |
443 return CallbackBase::Equals(other); | 437 return CallbackBase::Equals(other); |
444 } | 438 } |
445 | 439 |
446 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 440 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
447 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 441 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
448 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 442 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
(...skipping 16 matching lines...) Expand all Loading... |
465 typename internal::CallbackParamTraits<A4>::ForwardType); | 459 typename internal::CallbackParamTraits<A4>::ForwardType); |
466 | 460 |
467 }; | 461 }; |
468 | 462 |
469 template <typename R, typename A1, typename A2, typename A3, typename A4, | 463 template <typename R, typename A1, typename A2, typename A3, typename A4, |
470 typename A5> | 464 typename A5> |
471 class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase { | 465 class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase { |
472 public: | 466 public: |
473 typedef R(RunType)(A1, A2, A3, A4, A5); | 467 typedef R(RunType)(A1, A2, A3, A4, A5); |
474 | 468 |
475 Callback() : CallbackBase(NULL, NULL) { } | 469 Callback() : CallbackBase(NULL) { } |
476 | 470 |
477 // We pass BindStateHolder by const ref to avoid incurring an | |
478 // unnecessary AddRef/Unref pair even though we will modify the object. | |
479 // We cannot use a normal reference because the compiler will warn | |
480 // since this is often used on a return value, which is a temporary. | |
481 // | |
482 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 471 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
483 // return the exact Callback<> type. See base/bind.h for details. | 472 // return the exact Callback<> type. See base/bind.h for details. |
484 template <typename T> | 473 template <typename Runnable, typename RunType, typename BoundArgsType> |
485 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 474 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
486 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 475 : CallbackBase(bind_state) { |
487 // Force the assignment to a location variable of PolymorphicInvoke | 476 |
| 477 // Force the assignment to a local variable of PolymorphicInvoke |
488 // so the compiler will typecheck that the passed in Run() method has | 478 // so the compiler will typecheck that the passed in Run() method has |
489 // the correct type. | 479 // the correct type. |
490 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 480 PolymorphicInvoke invoke_func = |
| 481 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 482 ::InvokerType::Run; |
491 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 483 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
492 } | 484 } |
493 | 485 |
494 bool Equals(const Callback& other) const { | 486 bool Equals(const Callback& other) const { |
495 return CallbackBase::Equals(other); | 487 return CallbackBase::Equals(other); |
496 } | 488 } |
497 | 489 |
498 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 490 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
499 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 491 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
500 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 492 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
(...skipping 19 matching lines...) Expand all Loading... |
520 typename internal::CallbackParamTraits<A5>::ForwardType); | 512 typename internal::CallbackParamTraits<A5>::ForwardType); |
521 | 513 |
522 }; | 514 }; |
523 | 515 |
524 template <typename R, typename A1, typename A2, typename A3, typename A4, | 516 template <typename R, typename A1, typename A2, typename A3, typename A4, |
525 typename A5, typename A6> | 517 typename A5, typename A6> |
526 class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase { | 518 class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase { |
527 public: | 519 public: |
528 typedef R(RunType)(A1, A2, A3, A4, A5, A6); | 520 typedef R(RunType)(A1, A2, A3, A4, A5, A6); |
529 | 521 |
530 Callback() : CallbackBase(NULL, NULL) { } | 522 Callback() : CallbackBase(NULL) { } |
531 | 523 |
532 // We pass BindStateHolder by const ref to avoid incurring an | |
533 // unnecessary AddRef/Unref pair even though we will modify the object. | |
534 // We cannot use a normal reference because the compiler will warn | |
535 // since this is often used on a return value, which is a temporary. | |
536 // | |
537 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 524 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
538 // return the exact Callback<> type. See base/bind.h for details. | 525 // return the exact Callback<> type. See base/bind.h for details. |
539 template <typename T> | 526 template <typename Runnable, typename RunType, typename BoundArgsType> |
540 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 527 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
541 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 528 : CallbackBase(bind_state) { |
542 // Force the assignment to a location variable of PolymorphicInvoke | 529 |
| 530 // Force the assignment to a local variable of PolymorphicInvoke |
543 // so the compiler will typecheck that the passed in Run() method has | 531 // so the compiler will typecheck that the passed in Run() method has |
544 // the correct type. | 532 // the correct type. |
545 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 533 PolymorphicInvoke invoke_func = |
| 534 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 535 ::InvokerType::Run; |
546 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 536 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
547 } | 537 } |
548 | 538 |
549 bool Equals(const Callback& other) const { | 539 bool Equals(const Callback& other) const { |
550 return CallbackBase::Equals(other); | 540 return CallbackBase::Equals(other); |
551 } | 541 } |
552 | 542 |
553 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 543 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
554 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 544 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
555 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 545 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
(...skipping 22 matching lines...) Expand all Loading... |
578 typename internal::CallbackParamTraits<A6>::ForwardType); | 568 typename internal::CallbackParamTraits<A6>::ForwardType); |
579 | 569 |
580 }; | 570 }; |
581 | 571 |
582 template <typename R, typename A1, typename A2, typename A3, typename A4, | 572 template <typename R, typename A1, typename A2, typename A3, typename A4, |
583 typename A5, typename A6, typename A7> | 573 typename A5, typename A6, typename A7> |
584 class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase { | 574 class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase { |
585 public: | 575 public: |
586 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); | 576 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); |
587 | 577 |
588 Callback() : CallbackBase(NULL, NULL) { } | 578 Callback() : CallbackBase(NULL) { } |
589 | 579 |
590 // We pass BindStateHolder by const ref to avoid incurring an | |
591 // unnecessary AddRef/Unref pair even though we will modify the object. | |
592 // We cannot use a normal reference because the compiler will warn | |
593 // since this is often used on a return value, which is a temporary. | |
594 // | |
595 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 580 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
596 // return the exact Callback<> type. See base/bind.h for details. | 581 // return the exact Callback<> type. See base/bind.h for details. |
597 template <typename T> | 582 template <typename Runnable, typename RunType, typename BoundArgsType> |
598 Callback(const internal::BindStateHolder<T>& bind_state_holder) | 583 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) |
599 : CallbackBase(NULL, &bind_state_holder.bind_state_) { | 584 : CallbackBase(bind_state) { |
600 // Force the assignment to a location variable of PolymorphicInvoke | 585 |
| 586 // Force the assignment to a local variable of PolymorphicInvoke |
601 // so the compiler will typecheck that the passed in Run() method has | 587 // so the compiler will typecheck that the passed in Run() method has |
602 // the correct type. | 588 // the correct type. |
603 PolymorphicInvoke invoke_func = &T::InvokerType::Run; | 589 PolymorphicInvoke invoke_func = |
| 590 &internal::BindState<Runnable, RunType, BoundArgsType> |
| 591 ::InvokerType::Run; |
604 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 592 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
605 } | 593 } |
606 | 594 |
607 bool Equals(const Callback& other) const { | 595 bool Equals(const Callback& other) const { |
608 return CallbackBase::Equals(other); | 596 return CallbackBase::Equals(other); |
609 } | 597 } |
610 | 598 |
611 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 599 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
612 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 600 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
613 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 601 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
(...skipping 27 matching lines...) Expand all Loading... |
641 }; | 629 }; |
642 | 630 |
643 | 631 |
644 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 632 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
645 // will be used in a lot of APIs with delayed execution. | 633 // will be used in a lot of APIs with delayed execution. |
646 typedef Callback<void(void)> Closure; | 634 typedef Callback<void(void)> Closure; |
647 | 635 |
648 } // namespace base | 636 } // namespace base |
649 | 637 |
650 #endif // BASE_CALLBACK_H | 638 #endif // BASE_CALLBACK_H |
OLD | NEW |