Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (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.
 
template<typename U , typename = skstd::enable_if_t<std::is_convertible<U*, T*>::value>>
 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 = skstd::enable_if_t<std::is_convertible<U*, T*>::value>>
 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.
 
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 = skstd::enable_if_t<std::is_convertible<U*, T*>::value>>
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 = skstd::enable_if_t<std::is_convertible<U*, T*>::value>>
sk_sp< T > & operator= (sk_sp< U > &&that)
 
T & operator* () const
 
 operator unspecified_bool_type () const
 
bool operator! () 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)
 

Private Types

using unspecified_bool_type = T *sk_sp::*
 Supports safe bool idiom. More...
 

Private Attributes

T * fPtr
 

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

template<typename T>
using sk_sp< T >::unspecified_bool_type = T* sk_sp::*
private

Supports safe bool idiom.

Obsolete with explicit operator bool.

Constructor & Destructor Documentation

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.

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.

Member Function Documentation

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.

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.

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.

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.


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