| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 /** | 247 /** |
| 248 * Shares the underlying object by calling ref(), so that both the argument
and the newly | 248 * 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. | 249 * created sk_sp both have a reference to it. |
| 250 */ | 250 */ |
| 251 sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {} | 251 sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {} |
| 252 template <typename U, | 252 template <typename U, |
| 253 typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>> | 253 typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value
>> |
| 254 sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {} | 254 sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {} |
| 255 | 255 |
| 256 /** | 256 /** |
| 257 * Move the underlying object from the argument to the newly created sk_sp.
Afterwards only | 257 * Move the underlying object from the argument to the newly created sk_sp.
Afterwards only |
| 258 * the new sk_sp will have a reference to the object, and the argument will
point to null. | 258 * the new sk_sp will have a reference to the object, and the argument will
point to null. |
| 259 * No call to ref() or unref() will be made. | 259 * No call to ref() or unref() will be made. |
| 260 */ | 260 */ |
| 261 sk_sp(sk_sp<T>&& that) : fPtr(that.release()) {} | 261 sk_sp(sk_sp<T>&& that) : fPtr(that.release()) {} |
| 262 template <typename U, | 262 template <typename U, |
| 263 typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>> | 263 typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value
>> |
| 264 sk_sp(sk_sp<U>&& that) : fPtr(that.release()) {} | 264 sk_sp(sk_sp<U>&& that) : fPtr(that.release()) {} |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * Adopt the bare pointer into the newly created sk_sp. | 267 * Adopt the bare pointer into the newly created sk_sp. |
| 268 * No call to ref() or unref() will be made. | 268 * No call to ref() or unref() will be made. |
| 269 */ | 269 */ |
| 270 explicit sk_sp(T* obj) : fPtr(obj) {} | 270 explicit sk_sp(T* obj) : fPtr(obj) {} |
| 271 | 271 |
| 272 /** | 272 /** |
| 273 * Calls unref() on the underlying object pointer. | 273 * Calls unref() on the underlying object pointer. |
| 274 */ | 274 */ |
| 275 ~sk_sp() { | 275 ~sk_sp() { |
| 276 SkSafeUnref(fPtr); | 276 SkSafeUnref(fPtr); |
| 277 } | 277 } |
| 278 | 278 |
| 279 sk_sp<T>& operator=(std::nullptr_t) { this->reset(); return *this; } | 279 sk_sp<T>& operator=(std::nullptr_t) { this->reset(); return *this; } |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * Shares the underlying object referenced by the argument by calling ref()
on it. If this | 282 * Shares the underlying object referenced by the argument by calling ref()
on it. If this |
| 283 * sk_sp previously had a reference to an object (i.e. not null) it will ca
ll unref() on that | 283 * sk_sp previously had a reference to an object (i.e. not null) it will ca
ll unref() on that |
| 284 * object. | 284 * object. |
| 285 */ | 285 */ |
| 286 sk_sp<T>& operator=(const sk_sp<T>& that) { | 286 sk_sp<T>& operator=(const sk_sp<T>& that) { |
| 287 this->reset(SkSafeRef(that.get())); | 287 this->reset(SkSafeRef(that.get())); |
| 288 return *this; | 288 return *this; |
| 289 } | 289 } |
| 290 template <typename U, | 290 template <typename U, |
| 291 typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>> | 291 typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value
>> |
| 292 sk_sp<T>& operator=(const sk_sp<U>& that) { | 292 sk_sp<T>& operator=(const sk_sp<U>& that) { |
| 293 this->reset(SkSafeRef(that.get())); | 293 this->reset(SkSafeRef(that.get())); |
| 294 return *this; | 294 return *this; |
| 295 } | 295 } |
| 296 | 296 |
| 297 /** | 297 /** |
| 298 * Move the underlying object from the argument to the sk_sp. If the sk_sp
previously held | 298 * Move the underlying object from the argument to the sk_sp. If the sk_sp
previously held |
| 299 * a reference to another object, unref() will be called on that object. No
call to ref() | 299 * a reference to another object, unref() will be called on that object. No
call to ref() |
| 300 * will be made. | 300 * will be made. |
| 301 */ | 301 */ |
| 302 sk_sp<T>& operator=(sk_sp<T>&& that) { | 302 sk_sp<T>& operator=(sk_sp<T>&& that) { |
| 303 this->reset(that.release()); | 303 this->reset(that.release()); |
| 304 return *this; | 304 return *this; |
| 305 } | 305 } |
| 306 template <typename U, | 306 template <typename U, |
| 307 typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>> | 307 typename = skstd::enable_if_t<skstd::is_convertible<U*, T*>::value
>> |
| 308 sk_sp<T>& operator=(sk_sp<U>&& that) { | 308 sk_sp<T>& operator=(sk_sp<U>&& that) { |
| 309 this->reset(that.release()); | 309 this->reset(that.release()); |
| 310 return *this; | 310 return *this; |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool operator==(std::nullptr_t) const { return this->get() == nullptr; } | 313 bool operator==(std::nullptr_t) const { return this->get() == nullptr; } |
| 314 bool operator!=(std::nullptr_t) const { return this->get() != nullptr; } | 314 bool operator!=(std::nullptr_t) const { return this->get() != nullptr; } |
| 315 | 315 |
| 316 template <typename U> | 316 template <typename U> |
| 317 bool operator==(const sk_sp<U>& that) const { return this->get() == that.get
(); } | 317 bool operator==(const sk_sp<U>& that) const { return this->get() == that.get
(); } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 private: | 358 private: |
| 359 T* fPtr; | 359 T* fPtr; |
| 360 }; | 360 }; |
| 361 | 361 |
| 362 template <typename T, typename... Args> | 362 template <typename T, typename... Args> |
| 363 sk_sp<T> sk_make_sp(Args&&... args) { | 363 sk_sp<T> sk_make_sp(Args&&... args) { |
| 364 return sk_sp<T>(new T(std::forward<Args>(args)...)); | 364 return sk_sp<T>(new T(std::forward<Args>(args)...)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 #endif | 367 #endif |
| OLD | NEW |