Flutter Engine
 
Loading...
Searching...
No Matches
fml::CFRef< T > Class Template Reference

#include <cf_utils.h>

Public Member Functions

 CFRef ()
 Creates a new null CFRef.
 
 CFRef (T instance)
 
 CFRef (const CFRef &other)
 
 CFRef (CFRef &&other)
 
CFRefoperator= (CFRef &&other)
 Takes over ownership of the CoreFoundation object owned by other.
 
 ~CFRef ()
 Releases the underlying CoreFoundation object, if non-null.
 
void Reset (T instance=CFRefTraits< T >::kNullValue)
 
void Retain (T instance=CFRefTraits< T >::kNullValue)
 
Release ()
 
Get () const
 
 operator T () const
 
 operator bool () const
 Returns true if the underlying CoreFoundation object is non-null.
 

Detailed Description

template<class T>
class fml::CFRef< T >

RAII-based smart pointer wrapper for CoreFoundation objects.

CFRef takes over ownership of the object it wraps and ensures that retain and release are called as appropriate on creation, assignment, and disposal.

Definition at line 27 of file cf_utils.h.

Constructor & Destructor Documentation

◆ CFRef() [1/4]

template<class T >
fml::CFRef< T >::CFRef ( )
inline

Creates a new null CFRef.

Definition at line 30 of file cf_utils.h.

30: instance_(CFRefTraits<T>::kNullValue) {}
static constexpr T kNullValue
Definition cf_utils.h:17

◆ CFRef() [2/4]

template<class T >
fml::CFRef< T >::CFRef ( instance)
inlineexplicit

Takes over ownership of instance, which is expected to be already retained.

Definition at line 34 of file cf_utils.h.

34: instance_(instance) {}
VkInstance instance
Definition main.cc:64

◆ CFRef() [3/4]

template<class T >
fml::CFRef< T >::CFRef ( const CFRef< T > &  other)
inline

Copy ctor: Creates a retained copy of the CoreFoundation object owned by other.

Definition at line 38 of file cf_utils.h.

38 : instance_(other.instance_) {
39 if (instance_) {
40 CFRefTraits<T>::Retain(instance_);
41 }
42 }
static void Retain(T instance)
Definition cf_utils.h:18

References fml::CFRefTraits< T >::Retain().

◆ CFRef() [4/4]

template<class T >
fml::CFRef< T >::CFRef ( CFRef< T > &&  other)
inline

Move ctor: Takes over ownership of the CoreFoundation object owned by other. The object owned by other is set to null.

Definition at line 46 of file cf_utils.h.

46 : instance_(other.instance_) {
47 other.instance_ = CFRefTraits<T>::kNullValue;
48 }

◆ ~CFRef()

template<class T >
fml::CFRef< T >::~CFRef ( )
inline

Releases the underlying CoreFoundation object, if non-null.

Definition at line 57 of file cf_utils.h.

57 {
58 if (instance_) {
59 CFRefTraits<T>::Release(instance_);
60 }
62 }
static void Release(T instance)
Definition cf_utils.h:19

References fml::CFRefTraits< T >::Release().

Member Function Documentation

◆ Get()

template<class T >
T fml::CFRef< T >::Get ( ) const
inline

Returns the underlying CoreFoundation object. Ownership of the returned object follows The Get Rule.

See: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-SW1

Definition at line 101 of file cf_utils.h.

101{ return instance_; }

Referenced by fml::testing::TEST(), and fml::testing::TEST().

◆ operator bool()

template<class T >
fml::CFRef< T >::operator bool ( ) const
inlineexplicit

Returns true if the underlying CoreFoundation object is non-null.

Definition at line 112 of file cf_utils.h.

112 {
113 return instance_ != CFRefTraits<T>::kNullValue;
114 }

◆ operator T()

template<class T >
fml::CFRef< T >::operator T ( ) const
inline

Returns the underlying CoreFoundation object. Ownership of the returned object follows The Get Rule.

See: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-SW1

Definition at line 109 of file cf_utils.h.

109{ return instance_; }

◆ operator=()

template<class T >
CFRef & fml::CFRef< T >::operator= ( CFRef< T > &&  other)
inline

Takes over ownership of the CoreFoundation object owned by other.

Definition at line 51 of file cf_utils.h.

51 {
52 Reset(other.Release());
53 return *this;
54 }
void Reset(T instance=CFRefTraits< T >::kNullValue)
Definition cf_utils.h:68

References fml::CFRef< T >::Reset().

◆ Release()

template<class T >
T fml::CFRef< T >::Release ( )
inline

Returns and transfers ownership of the underlying CoreFoundation object to the caller. The caller is responsible for calling CFRelease when done with the object.

Definition at line 90 of file cf_utils.h.

90 {
91 auto instance = instance_;
93 return instance;
94 }

References instance.

◆ Reset()

template<class T >
void fml::CFRef< T >::Reset ( instance = CFRefTraits<T>::kNullValue)
inline

Takes over ownership of instance, null by default. The object is expected to be already retained if non-null.

Releases the previous object, if non-null.

Definition at line 68 of file cf_utils.h.

68 {
69 if (instance_) {
70 CFRefTraits<T>::Release(instance_);
71 }
72 instance_ = instance;
73 }

References instance, and fml::CFRefTraits< T >::Release().

Referenced by impeller::testing::MetalScreenshot::MetalScreenshot(), fml::CFRef< T >::operator=(), fml::CFRef< T >::Retain(), fml::testing::TEST(), and fml::testing::TEST().

◆ Retain()

template<class T >
void fml::CFRef< T >::Retain ( instance = CFRefTraits<T>::kNullValue)
inline

Retains a shared copy of instance. The previous object is released if non-null. Has no effect if instance is the currently-held object.

Definition at line 77 of file cf_utils.h.

77 {
78 if (instance_ == instance) {
79 return;
80 }
81 if (instance) {
83 }
85 }

References instance, fml::CFRef< T >::Reset(), and fml::CFRefTraits< T >::Retain().

Referenced by fml::testing::TEST(), and fml::testing::TEST().


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