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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 #ifndef BASE_BIND_HELPERS_H_ | 143 #ifndef BASE_BIND_HELPERS_H_ |
144 #define BASE_BIND_HELPERS_H_ | 144 #define BASE_BIND_HELPERS_H_ |
145 | 145 |
146 #include <stddef.h> | 146 #include <stddef.h> |
147 | 147 |
148 #include <type_traits> | 148 #include <type_traits> |
149 #include <utility> | 149 #include <utility> |
150 | 150 |
151 #include "base/callback.h" | 151 #include "base/callback.h" |
152 #include "base/memory/weak_ptr.h" | 152 #include "base/memory/weak_ptr.h" |
153 #include "base/template_util.h" | |
154 #include "build/build_config.h" | 153 #include "build/build_config.h" |
155 | 154 |
156 namespace base { | 155 namespace base { |
157 namespace internal { | 156 namespace internal { |
158 | 157 |
159 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T | 158 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T |
160 // for the existence of AddRef() and Release() functions of the correct | 159 // for the existence of AddRef() and Release() functions of the correct |
161 // signature. | 160 // signature. |
162 // | 161 // |
163 // http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error | 162 // http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 template <typename > | 254 template <typename > |
256 static Yes& Check(...); | 255 static Yes& Check(...); |
257 | 256 |
258 public: | 257 public: |
259 enum { value = sizeof(Check<Base>(0)) == sizeof(Yes) }; | 258 enum { value = sizeof(Check<Base>(0)) == sizeof(Yes) }; |
260 }; | 259 }; |
261 | 260 |
262 // Helpers to assert that arguments of a recounted type are bound with a | 261 // Helpers to assert that arguments of a recounted type are bound with a |
263 // scoped_refptr. | 262 // scoped_refptr. |
264 template <bool IsClasstype, typename T> | 263 template <bool IsClasstype, typename T> |
265 struct UnsafeBindtoRefCountedArgHelper : false_type { | 264 struct UnsafeBindtoRefCountedArgHelper : std::false_type { |
266 }; | 265 }; |
267 | 266 |
268 template <typename T> | 267 template <typename T> |
269 struct UnsafeBindtoRefCountedArgHelper<true, T> | 268 struct UnsafeBindtoRefCountedArgHelper<true, T> |
270 : integral_constant<bool, SupportsAddRefAndRelease<T>::value> { | 269 : std::integral_constant<bool, SupportsAddRefAndRelease<T>::value> { |
271 }; | 270 }; |
272 | 271 |
273 template <typename T> | 272 template <typename T> |
274 struct UnsafeBindtoRefCountedArg : false_type { | 273 struct UnsafeBindtoRefCountedArg : std::false_type { |
275 }; | 274 }; |
276 | 275 |
277 template <typename T> | 276 template <typename T> |
278 struct UnsafeBindtoRefCountedArg<T*> | 277 struct UnsafeBindtoRefCountedArg<T*> |
279 : UnsafeBindtoRefCountedArgHelper<is_class<T>::value, T> { | 278 : UnsafeBindtoRefCountedArgHelper<std::is_class<T>::value, T> { |
280 }; | 279 }; |
281 | 280 |
282 template <typename T> | 281 template <typename T> |
283 class HasIsMethodTag { | 282 class HasIsMethodTag { |
284 using Yes = char[1]; | 283 using Yes = char[1]; |
285 using No = char[2]; | 284 using No = char[2]; |
286 | 285 |
287 template <typename U> | 286 template <typename U> |
288 static Yes& Check(typename U::IsMethod*); | 287 static Yes& Check(typename U::IsMethod*); |
289 | 288 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 } | 425 } |
427 | 426 |
428 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a | 427 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a |
429 // method. It is used internally by Bind() to select the correct | 428 // method. It is used internally by Bind() to select the correct |
430 // InvokeHelper that will no-op itself in the event the WeakPtr<> for | 429 // InvokeHelper that will no-op itself in the event the WeakPtr<> for |
431 // the target object is invalidated. | 430 // the target object is invalidated. |
432 // | 431 // |
433 // The first argument should be the type of the object that will be received by | 432 // The first argument should be the type of the object that will be received by |
434 // the method. | 433 // the method. |
435 template <bool IsMethod, typename... Args> | 434 template <bool IsMethod, typename... Args> |
436 struct IsWeakMethod : public false_type {}; | 435 struct IsWeakMethod : public std::false_type {}; |
437 | 436 |
438 template <typename T, typename... Args> | 437 template <typename T, typename... Args> |
439 struct IsWeakMethod<true, WeakPtr<T>, Args...> : public true_type {}; | 438 struct IsWeakMethod<true, WeakPtr<T>, Args...> : public std::true_type {}; |
440 | 439 |
441 template <typename T, typename... Args> | 440 template <typename T, typename... Args> |
442 struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...> | 441 struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...> |
443 : public true_type {}; | 442 : public std::true_type {}; |
444 | 443 |
445 | 444 |
446 // Packs a list of types to hold them in a single type. | 445 // Packs a list of types to hold them in a single type. |
447 template <typename... Types> | 446 template <typename... Types> |
448 struct TypeList {}; | 447 struct TypeList {}; |
449 | 448 |
450 // Used for DropTypeListItem implementation. | 449 // Used for DropTypeListItem implementation. |
451 template <size_t n, typename List> | 450 template <size_t n, typename List> |
452 struct DropTypeListItemImpl; | 451 struct DropTypeListItemImpl; |
453 | 452 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 BASE_EXPORT void DoNothing(); | 589 BASE_EXPORT void DoNothing(); |
591 | 590 |
592 template<typename T> | 591 template<typename T> |
593 void DeletePointer(T* obj) { | 592 void DeletePointer(T* obj) { |
594 delete obj; | 593 delete obj; |
595 } | 594 } |
596 | 595 |
597 } // namespace base | 596 } // namespace base |
598 | 597 |
599 #endif // BASE_BIND_HELPERS_H_ | 598 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |