Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
sk_sp< T > Class Template Reference

#include <SkRefCnt.h>

Public Types

using element_type = T
 
using sk_is_trivially_relocatable = std::true_type
 

Public Member Functions

constexpr sk_sp ()
 
constexpr sk_sp (std::nullptr_t)
 
 sk_sp (const sk_sp< T > &that)
 
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
 sk_sp (const sk_sp< U > &that)
 
 sk_sp (sk_sp< T > &&that)
 
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
 sk_sp (sk_sp< U > &&that)
 
 sk_sp (T *obj)
 
 ~sk_sp ()
 
sk_sp< T > & operator= (std::nullptr_t)
 
sk_sp< T > & operator= (const sk_sp< T > &that)
 
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T > & operator= (const sk_sp< U > &that)
 
sk_sp< T > & operator= (sk_sp< T > &&that)
 
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T > & operator= (sk_sp< U > &&that)
 
Toperator* () const
 
 operator bool () const
 
Tget () const
 
Toperator-> () const
 
void reset (T *ptr=nullptr)
 
Trelease ()
 
void swap (sk_sp< T > &that)
 

Detailed Description

template<typename T>
class sk_sp< T >

Shared pointer class to wrap classes that support a ref()/unref() interface.

This can be used for classes inheriting from SkRefCnt, but it also works for other classes that match the interface, but have different internal choices: e.g. the hosted class may have its ref/unref be thread-safe, but that is not assumed/imposed by sk_sp.

Declared with the trivial_abi attribute where supported so that sk_sp and types containing it may be considered as trivially relocatable by the compiler so that destroying-move operations i.e. move constructor followed by destructor can be optimized to memcpy.

Definition at line 220 of file SkRefCnt.h.

Member Typedef Documentation

◆ element_type

template<typename T >
using sk_sp< T >::element_type = T

Definition at line 222 of file SkRefCnt.h.

◆ sk_is_trivially_relocatable

template<typename T >
using sk_sp< T >::sk_is_trivially_relocatable = std::true_type

Definition at line 335 of file SkRefCnt.h.

Constructor & Destructor Documentation

◆ sk_sp() [1/7]

template<typename T >
constexpr sk_sp< T >::sk_sp ( )
inlineconstexpr

Definition at line 224 of file SkRefCnt.h.

224: fPtr(nullptr) {}

◆ sk_sp() [2/7]

template<typename T >
constexpr sk_sp< T >::sk_sp ( std::nullptr_t  )
inlineconstexpr

Definition at line 225 of file SkRefCnt.h.

225: fPtr(nullptr) {}

◆ sk_sp() [3/7]

template<typename T >
sk_sp< T >::sk_sp ( const sk_sp< T > &  that)
inline

Shares the underlying object by calling ref(), so that both the argument and the newly created sk_sp both have a reference to it.

Definition at line 231 of file SkRefCnt.h.

231: fPtr(SkSafeRef(that.get())) {}
static T * SkSafeRef(T *obj)
Definition SkRefCnt.h:140
T * get() const
Definition SkRefCnt.h:303

◆ sk_sp() [4/7]

template<typename T >
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T >::sk_sp ( const sk_sp< U > &  that)
inline

Definition at line 234 of file SkRefCnt.h.

234: fPtr(SkSafeRef(that.get())) {}

◆ sk_sp() [5/7]

template<typename T >
sk_sp< T >::sk_sp ( sk_sp< T > &&  that)
inline

Move the underlying object from the argument to the newly created sk_sp. Afterwards only the new sk_sp will have a reference to the object, and the argument will point to null. No call to ref() or unref() will be made.

Definition at line 241 of file SkRefCnt.h.

241: fPtr(that.release()) {}
T * release()
Definition SkRefCnt.h:324

◆ sk_sp() [6/7]

template<typename T >
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T >::sk_sp ( sk_sp< U > &&  that)
inline

Definition at line 244 of file SkRefCnt.h.

244: fPtr(that.release()) {}

◆ sk_sp() [7/7]

template<typename T >
sk_sp< T >::sk_sp ( T obj)
inlineexplicit

Adopt the bare pointer into the newly created sk_sp. No call to ref() or unref() will be made.

Definition at line 250 of file SkRefCnt.h.

250: fPtr(obj) {}

◆ ~sk_sp()

template<typename T >
sk_sp< T >::~sk_sp ( )
inline

Calls unref() on the underlying object pointer.

Definition at line 255 of file SkRefCnt.h.

255 {
256 SkSafeUnref(fPtr);
257 SkDEBUGCODE(fPtr = nullptr);
258 }
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static void SkSafeUnref(T *obj)
Definition SkRefCnt.h:149

Member Function Documentation

◆ get()

template<typename T >
T * sk_sp< T >::get ( ) const
inline

Definition at line 303 of file SkRefCnt.h.

303{ return fPtr; }

◆ operator bool()

template<typename T >
sk_sp< T >::operator bool ( ) const
inlineexplicit

Definition at line 301 of file SkRefCnt.h.

301{ return this->get() != nullptr; }

◆ operator*()

template<typename T >
T & sk_sp< T >::operator* ( ) const
inline

Definition at line 296 of file SkRefCnt.h.

296 {
297 SkASSERT(this->get() != nullptr);
298 return *this->get();
299 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ operator->()

template<typename T >
T * sk_sp< T >::operator-> ( ) const
inline

Definition at line 304 of file SkRefCnt.h.

304{ return fPtr; }

◆ operator=() [1/5]

template<typename T >
sk_sp< T > & sk_sp< T >::operator= ( const sk_sp< T > &  that)
inline

Shares the underlying object referenced by the argument by calling ref() on it. If this sk_sp previously had a reference to an object (i.e. not null) it will call unref() on that object.

Definition at line 267 of file SkRefCnt.h.

267 {
268 if (this != &that) {
269 this->reset(SkSafeRef(that.get()));
270 }
271 return *this;
272 }
m reset()

◆ operator=() [2/5]

template<typename T >
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T > & sk_sp< T >::operator= ( const sk_sp< U > &  that)
inline

Definition at line 275 of file SkRefCnt.h.

275 {
276 this->reset(SkSafeRef(that.get()));
277 return *this;
278 }

◆ operator=() [3/5]

template<typename T >
sk_sp< T > & sk_sp< T >::operator= ( sk_sp< T > &&  that)
inline

Move the underlying object from the argument to the sk_sp. If the sk_sp previously held a reference to another object, unref() will be called on that object. No call to ref() will be made.

Definition at line 285 of file SkRefCnt.h.

285 {
286 this->reset(that.release());
287 return *this;
288 }

◆ operator=() [4/5]

template<typename T >
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T > & sk_sp< T >::operator= ( sk_sp< U > &&  that)
inline

Definition at line 291 of file SkRefCnt.h.

291 {
292 this->reset(that.release());
293 return *this;
294 }

◆ operator=() [5/5]

template<typename T >
sk_sp< T > & sk_sp< T >::operator= ( std::nullptr_t  )
inline

Definition at line 260 of file SkRefCnt.h.

260{ this->reset(); return *this; }

◆ release()

template<typename T >
T * sk_sp< T >::release ( )
inline

Return the bare pointer, and set the internal object pointer to nullptr. The caller must assume ownership of the object, and manage its reference count directly. No call to unref() will be made.

Definition at line 324 of file SkRefCnt.h.

324 {
325 T* ptr = fPtr;
326 fPtr = nullptr;
327 return ptr;
328 }
#define T

◆ reset()

template<typename T >
void sk_sp< T >::reset ( T ptr = nullptr)
inline

Adopt the new bare pointer, and call unref() on any previously held object (if not null). No call to ref() will be made.

Definition at line 310 of file SkRefCnt.h.

310 {
311 // Calling fPtr->unref() may call this->~() or this->reset(T*).
312 // http://wg21.cmeerw.net/lwg/issue998
313 // http://wg21.cmeerw.net/lwg/issue2262
314 T* oldPtr = fPtr;
315 fPtr = ptr;
316 SkSafeUnref(oldPtr);
317 }

◆ swap()

template<typename T >
void sk_sp< T >::swap ( sk_sp< T > &  that)
inline

Definition at line 330 of file SkRefCnt.h.

330 {
331 using std::swap;
332 swap(fPtr, that.fPtr);
333 }
void swap(sk_sp< T > &that)
Definition SkRefCnt.h:330

The documentation for this class was generated from the following file: