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_INTERNAL_H_ | 5 #ifndef BASE_BIND_INTERNAL_H_ |
6 #define BASE_BIND_INTERNAL_H_ | 6 #define BASE_BIND_INTERNAL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <type_traits> | 10 #include <type_traits> |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // is invalidated. | 324 // is invalidated. |
325 static_assert(is_void<ReturnType>::value, | 325 static_assert(is_void<ReturnType>::value, |
326 "weak_ptrs can only bind to methods without return values"); | 326 "weak_ptrs can only bind to methods without return values"); |
327 }; | 327 }; |
328 | 328 |
329 #endif | 329 #endif |
330 | 330 |
331 // Invoker<> | 331 // Invoker<> |
332 // | 332 // |
333 // See description at the top of the file. | 333 // See description at the top of the file. |
334 template <typename BoundIndices, | 334 template <typename BoundIndices, typename StorageType, |
335 typename StorageType, typename Unwrappers, | |
336 typename InvokeHelperType, typename UnboundForwardRunType> | 335 typename InvokeHelperType, typename UnboundForwardRunType> |
337 struct Invoker; | 336 struct Invoker; |
338 | 337 |
339 template <size_t... bound_indices, | 338 template <size_t... bound_indices, |
340 typename StorageType, | 339 typename StorageType, |
341 typename... Unwrappers, | |
342 typename InvokeHelperType, | 340 typename InvokeHelperType, |
343 typename R, | 341 typename R, |
344 typename... UnboundForwardArgs> | 342 typename... UnboundForwardArgs> |
345 struct Invoker<IndexSequence<bound_indices...>, | 343 struct Invoker<IndexSequence<bound_indices...>, StorageType, |
346 StorageType, TypeList<Unwrappers...>, | |
347 InvokeHelperType, R(UnboundForwardArgs...)> { | 344 InvokeHelperType, R(UnboundForwardArgs...)> { |
348 static R Run(BindStateBase* base, | 345 static R Run(BindStateBase* base, |
349 UnboundForwardArgs... unbound_args) { | 346 UnboundForwardArgs... unbound_args) { |
350 StorageType* storage = static_cast<StorageType*>(base); | 347 StorageType* storage = static_cast<StorageType*>(base); |
351 // Local references to make debugger stepping easier. If in a debugger, | 348 // Local references to make debugger stepping easier. If in a debugger, |
352 // you really want to warp ahead and step through the | 349 // you really want to warp ahead and step through the |
353 // InvokeHelper<>::MakeItSo() call below. | 350 // InvokeHelper<>::MakeItSo() call below. |
354 return InvokeHelperType::MakeItSo( | 351 return InvokeHelperType::MakeItSo( |
355 storage->runnable_, | 352 storage->runnable_, |
356 Unwrappers::Unwrap(get<bound_indices>(storage->bound_args_))..., | 353 Unwrap(get<bound_indices>(storage->bound_args_))..., |
357 CallbackForward(unbound_args)...); | 354 CallbackForward(unbound_args)...); |
358 } | 355 } |
359 }; | 356 }; |
360 | 357 |
361 | 358 |
362 // BindState<> | 359 // BindState<> |
363 // | 360 // |
364 // This stores all the state passed into Bind() and is also where most | 361 // This stores all the state passed into Bind() and is also where most |
365 // of the template resolution magic occurs. | 362 // of the template resolution magic occurs. |
366 // | 363 // |
(...skipping 15 matching lines...) Expand all Loading... |
382 private: | 379 private: |
383 using StorageType = BindState<Runnable, R(Args...), BoundArgs...>; | 380 using StorageType = BindState<Runnable, R(Args...), BoundArgs...>; |
384 using RunnableType = Runnable; | 381 using RunnableType = Runnable; |
385 | 382 |
386 // true_type if Runnable is a method invocation and the first bound argument | 383 // true_type if Runnable is a method invocation and the first bound argument |
387 // is a WeakPtr. | 384 // is a WeakPtr. |
388 using IsWeakCall = | 385 using IsWeakCall = |
389 IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>; | 386 IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>; |
390 | 387 |
391 using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>; | 388 using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>; |
392 using Unwrappers = TypeList<UnwrapTraits<BoundArgs>...>; | |
393 using UnboundForwardArgs = DropTypeListItem< | 389 using UnboundForwardArgs = DropTypeListItem< |
394 sizeof...(BoundArgs), | 390 sizeof...(BoundArgs), |
395 TypeList<typename CallbackParamTraits<Args>::ForwardType...>>; | 391 TypeList<typename CallbackParamTraits<Args>::ForwardType...>>; |
396 using UnboundForwardRunType = MakeFunctionType<R, UnboundForwardArgs>; | 392 using UnboundForwardRunType = MakeFunctionType<R, UnboundForwardArgs>; |
397 using InvokeHelperType = InvokeHelper<IsWeakCall::value, R, Runnable>; | 393 using InvokeHelperType = InvokeHelper<IsWeakCall::value, R, Runnable>; |
398 | 394 |
399 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; | 395 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; |
400 | 396 |
401 public: | 397 public: |
402 using InvokerType = Invoker<BoundIndices, StorageType, Unwrappers, | 398 using InvokerType = Invoker<BoundIndices, StorageType, |
403 InvokeHelperType, UnboundForwardRunType>; | 399 InvokeHelperType, UnboundForwardRunType>; |
404 using UnboundRunType = MakeFunctionType<R, UnboundArgs>; | 400 using UnboundRunType = MakeFunctionType<R, UnboundArgs>; |
405 | 401 |
406 template <typename... ForwardArgs> | 402 template <typename... ForwardArgs> |
407 BindState(const Runnable& runnable, ForwardArgs&&... bound_args) | 403 BindState(const Runnable& runnable, ForwardArgs&&... bound_args) |
408 : BindStateBase(&Destroy), | 404 : BindStateBase(&Destroy), |
409 runnable_(runnable), | 405 runnable_(runnable), |
410 ref_(bound_args...), | 406 ref_(bound_args...), |
411 bound_args_(std::forward<ForwardArgs>(bound_args)...) {} | 407 bound_args_(std::forward<ForwardArgs>(bound_args)...) {} |
412 | 408 |
413 RunnableType runnable_; | 409 RunnableType runnable_; |
414 MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_; | 410 MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_; |
415 Tuple<BoundArgs...> bound_args_; | 411 Tuple<BoundArgs...> bound_args_; |
416 | 412 |
417 private: | 413 private: |
418 ~BindState() {} | 414 ~BindState() {} |
419 | 415 |
420 static void Destroy(BindStateBase* self) { | 416 static void Destroy(BindStateBase* self) { |
421 delete static_cast<BindState*>(self); | 417 delete static_cast<BindState*>(self); |
422 } | 418 } |
423 }; | 419 }; |
424 | 420 |
425 } // namespace internal | 421 } // namespace internal |
426 } // namespace base | 422 } // namespace base |
427 | 423 |
428 #endif // BASE_BIND_INTERNAL_H_ | 424 #endif // BASE_BIND_INTERNAL_H_ |
OLD | NEW |