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 <tuple> | 10 #include <tuple> |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 IsNull(const Functor& functor) { | 366 IsNull(const Functor& functor) { |
367 return !functor; | 367 return !functor; |
368 } | 368 } |
369 | 369 |
370 template <typename Functor> | 370 template <typename Functor> |
371 typename std::enable_if<!FunctorTraits<Functor>::is_nullable, bool>::type | 371 typename std::enable_if<!FunctorTraits<Functor>::is_nullable, bool>::type |
372 IsNull(const Functor&) { | 372 IsNull(const Functor&) { |
373 return false; | 373 return false; |
374 } | 374 } |
375 | 375 |
| 376 template <typename Functor, typename... BoundArgs> |
| 377 struct BindState; |
| 378 |
| 379 template <typename BindStateType, typename SFINAE = void> |
| 380 struct CancellationChecker { |
| 381 static bool Run(const BindStateBase*) { |
| 382 return false; |
| 383 } |
| 384 }; |
| 385 |
| 386 template <typename Functor, typename... BoundArgs> |
| 387 struct CancellationChecker< |
| 388 BindState<Functor, BoundArgs...>, |
| 389 typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method, |
| 390 BoundArgs...>::value>::type> { |
| 391 static bool Run(const BindStateBase* base) { |
| 392 using BindStateType = BindState<Functor, BoundArgs...>; |
| 393 const BindStateType* bind_state = static_cast<const BindStateType*>(base); |
| 394 return !base::get<0>(bind_state->bound_args_); |
| 395 } |
| 396 }; |
| 397 |
| 398 template <typename Signature, typename... BoundArgs> |
| 399 struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> { |
| 400 static bool Run(const BindStateBase* base) { |
| 401 using Functor = Callback<Signature>; |
| 402 using BindStateType = BindState<Functor, BoundArgs...>; |
| 403 const BindStateType* bind_state = static_cast<const BindStateType*>(base); |
| 404 return bind_state->functor_.IsCancelled(); |
| 405 } |
| 406 }; |
| 407 |
376 // BindState<> | 408 // BindState<> |
377 // | 409 // |
378 // This stores all the state passed into Bind(). | 410 // This stores all the state passed into Bind(). |
379 template <typename Functor, typename... BoundArgs> | 411 template <typename Functor, typename... BoundArgs> |
380 struct BindState final : BindStateBase { | 412 struct BindState final : BindStateBase { |
381 template <typename ForwardFunctor, typename... ForwardBoundArgs> | 413 template <typename ForwardFunctor, typename... ForwardBoundArgs> |
382 explicit BindState(BindStateBase::InvokeFuncStorage invoke_func, | 414 explicit BindState(BindStateBase::InvokeFuncStorage invoke_func, |
383 ForwardFunctor&& functor, | 415 ForwardFunctor&& functor, |
384 ForwardBoundArgs&&... bound_args) | 416 ForwardBoundArgs&&... bound_args) |
385 : BindStateBase(invoke_func, &Destroy), | 417 : BindStateBase(invoke_func, &Destroy, |
| 418 &CancellationChecker<BindState>::Run), |
386 functor_(std::forward<ForwardFunctor>(functor)), | 419 functor_(std::forward<ForwardFunctor>(functor)), |
387 bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) { | 420 bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) { |
388 DCHECK(!IsNull(functor_)); | 421 DCHECK(!IsNull(functor_)); |
389 } | 422 } |
390 | 423 |
391 Functor functor_; | 424 Functor functor_; |
392 std::tuple<BoundArgs...> bound_args_; | 425 std::tuple<BoundArgs...> bound_args_; |
393 | 426 |
394 private: | 427 private: |
395 ~BindState() {} | 428 ~BindState() {} |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 480 |
448 // Returns a RunType of bound functor. | 481 // Returns a RunType of bound functor. |
449 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). | 482 // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). |
450 template <typename Functor, typename... BoundArgs> | 483 template <typename Functor, typename... BoundArgs> |
451 using MakeUnboundRunType = | 484 using MakeUnboundRunType = |
452 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type; | 485 typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type; |
453 | 486 |
454 } // namespace base | 487 } // namespace base |
455 | 488 |
456 #endif // BASE_BIND_INTERNAL_H_ | 489 #endif // BASE_BIND_INTERNAL_H_ |
OLD | NEW |