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 // This defines a set of argument wrappers and related factory methods that | 5 // This defines a set of argument wrappers and related factory methods that |
6 // can be used specify the refcounting and reference semantics of arguments | 6 // can be used specify the refcounting and reference semantics of arguments |
7 // that are bound by the Bind() function in base/bind.h. | 7 // that are bound by the Bind() function in base/bind.h. |
8 // | 8 // |
9 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return scoper_.Pass(); | 377 return scoper_.Pass(); |
378 } | 378 } |
379 | 379 |
380 private: | 380 private: |
381 mutable bool is_valid_; | 381 mutable bool is_valid_; |
382 mutable T scoper_; | 382 mutable T scoper_; |
383 }; | 383 }; |
384 | 384 |
385 // Unwrap the stored parameters for the wrappers above. | 385 // Unwrap the stored parameters for the wrappers above. |
386 template <typename T> | 386 template <typename T> |
387 struct UnwrapTraits { | 387 struct MoveOnlyUnwrapTraits { |
| 388 typedef T&& ForwardType; |
| 389 static ForwardType Unwrap(T& o) { return std::move(o); } |
| 390 }; |
| 391 |
| 392 template <typename T> |
| 393 struct CopyUnwrapTraits { |
388 typedef const T& ForwardType; | 394 typedef const T& ForwardType; |
389 static ForwardType Unwrap(const T& o) { return o; } | 395 static ForwardType Unwrap(const T& o) { return o; } |
390 }; | 396 }; |
391 | 397 |
| 398 // BindState<> |
| 399 template <typename T, typename U = void> |
| 400 struct UnwrapTraits : public std::conditional<base::is_move_only<T>::value, |
| 401 MoveOnlyUnwrapTraits<T>, |
| 402 CopyUnwrapTraits<T>>::type {}; |
| 403 |
| 404 template <typename T> |
| 405 struct UnwrapTraits< |
| 406 T, |
| 407 typename std::conditional<false, typename T::value_type, void>::type> |
| 408 : public std::conditional<base::is_move_only<typename T::value_type>::value, |
| 409 MoveOnlyUnwrapTraits<T>, |
| 410 CopyUnwrapTraits<T>>::type {}; |
| 411 |
392 template <typename T> | 412 template <typename T> |
393 struct UnwrapTraits<UnretainedWrapper<T> > { | 413 struct UnwrapTraits<UnretainedWrapper<T> > { |
394 typedef T* ForwardType; | 414 typedef T* ForwardType; |
395 static ForwardType Unwrap(UnretainedWrapper<T> unretained) { | 415 static ForwardType Unwrap(UnretainedWrapper<T> unretained) { |
396 return unretained.get(); | 416 return unretained.get(); |
397 } | 417 } |
398 }; | 418 }; |
399 | 419 |
400 template <typename T> | 420 template <typename T> |
401 struct UnwrapTraits<ConstRefWrapper<T> > { | 421 struct UnwrapTraits<ConstRefWrapper<T> > { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 BASE_EXPORT void DoNothing(); | 613 BASE_EXPORT void DoNothing(); |
594 | 614 |
595 template<typename T> | 615 template<typename T> |
596 void DeletePointer(T* obj) { | 616 void DeletePointer(T* obj) { |
597 delete obj; | 617 delete obj; |
598 } | 618 } |
599 | 619 |
600 } // namespace base | 620 } // namespace base |
601 | 621 |
602 #endif // BASE_BIND_HELPERS_H_ | 622 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |