Skia
2D Graphics Library
sk_sp< T > Class Template Reference

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

#include <SkRefCnt.h>

Public Types

using element_type = T
 

Public Member Functions

constexpr sk_sp ()
 
constexpr sk_sp (std::nullptr_t)
 
 sk_sp (const sk_sp< T > &that)
 Shares the underlying object by calling ref(), so that both the argument and the newly created sk_sp both have a reference to it. More...
 
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)
 Move the underlying object from the argument to the newly created sk_sp. More...
 
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)
 Adopt the bare pointer into the newly created sk_sp. More...
 
 ~sk_sp ()
 Calls unref() on the underlying object pointer. More...
 
sk_sp< T > & operator= (std::nullptr_t)
 
sk_sp< T > & operator= (const sk_sp< T > &that)
 Shares the underlying object referenced by the argument by calling ref() on it. More...
 
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)
 Move the underlying object from the argument to the sk_sp. More...
 
template<typename U , typename = typename std::enable_if<std::is_convertible<U*, T*>::value>::type>
sk_sp< T > & operator= (sk_sp< U > &&that)
 
T & operator* () const
 
 operator bool () const
 
T * get () const
 
T * operator-> () const
 
void reset (T *ptr=nullptr)
 Adopt the new bare pointer, and call unref() on any previously held object (if not null). More...
 
T *SK_WARN_UNUSED_RESULT release ()
 Return the bare pointer, and set the internal object pointer to nullptr. More...
 
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.

Member Typedef Documentation

◆ element_type

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

Constructor & Destructor Documentation

◆ sk_sp() [1/7]

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

◆ sk_sp() [2/7]

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

◆ 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.

◆ 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

◆ 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.

◆ 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

◆ 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.

◆ ~sk_sp()

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

Calls unref() on the underlying object pointer.

Member Function Documentation

◆ get()

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

◆ operator bool()

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

◆ operator*()

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

◆ operator->()

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

◆ operator=() [1/5]

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

◆ operator=() [2/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.

◆ operator=() [3/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

◆ operator=() [4/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.

◆ operator=() [5/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

◆ release()

template<typename T>
T* SK_WARN_UNUSED_RESULT 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.

◆ 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.

◆ swap()

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

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