Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkRefCnt_DEFINED | 8 #ifndef SkRefCnt_DEFINED |
| 9 #define SkRefCnt_DEFINED | 9 #define SkRefCnt_DEFINED |
| 10 | 10 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 * classes that match the interface, but have different internal choices: e.g. the hosted class | 237 * classes that match the interface, but have different internal choices: e.g. the hosted class |
| 238 * may have its ref/unref be thread-safe, but that is not assumed/imposed by sk _sp. | 238 * may have its ref/unref be thread-safe, but that is not assumed/imposed by sk _sp. |
| 239 */ | 239 */ |
| 240 template <typename T> class sk_sp { | 240 template <typename T> class sk_sp { |
| 241 /** Supports safe bool idiom. Obsolete with explicit operator bool. */ | 241 /** Supports safe bool idiom. Obsolete with explicit operator bool. */ |
| 242 using unspecified_bool_type = T* sk_sp::*; | 242 using unspecified_bool_type = T* sk_sp::*; |
| 243 public: | 243 public: |
| 244 sk_sp() : fPtr(nullptr) {} | 244 sk_sp() : fPtr(nullptr) {} |
| 245 sk_sp(std::nullptr_t) : fPtr(nullptr) {} | 245 sk_sp(std::nullptr_t) : fPtr(nullptr) {} |
| 246 | 246 |
| 247 // TODO: for all these constructors and assignments that take <typename U>, | |
| 248 // can we add static assertions that sk_sp<T> -> sk_sp<U> doesn't slice | |
| 249 // (something like, T has a trivial destructor or U's destructor is virtual) ? | |
| 250 | |
|
bungeman-skia
2016/03/07 19:29:45
Putting this here is a bit over constrained. sk_sp
mtklein_C
2016/03/07 19:40:46
Agreed. Now gone.
| |
| 247 /** | 251 /** |
| 248 * Shares the underlying object by calling ref(), so that both the argument and the newly | 252 * Shares the underlying object by calling ref(), so that both the argument and the newly |
| 249 * created sk_sp both have a reference to it. | 253 * created sk_sp both have a reference to it. |
| 250 */ | 254 */ |
| 251 sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {} | 255 sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {} |
| 252 template <typename U, | 256 template <typename U, |
| 253 typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value >> | 257 typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value >> |
| 254 sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {} | 258 sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {} |
| 255 | 259 |
| 256 /** | 260 /** |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 private: | 360 private: |
| 357 T* fPtr; | 361 T* fPtr; |
| 358 }; | 362 }; |
| 359 | 363 |
| 360 template <typename T, typename... Args> | 364 template <typename T, typename... Args> |
| 361 sk_sp<T> sk_make_sp(Args&&... args) { | 365 sk_sp<T> sk_make_sp(Args&&... args) { |
| 362 return sk_sp<T>(new T(std::forward<Args>(args)...)); | 366 return sk_sp<T>(new T(std::forward<Args>(args)...)); |
| 363 } | 367 } |
| 364 | 368 |
| 365 #endif | 369 #endif |
| OLD | NEW |