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

#include <SkTLazy.h>

Public Member Functions

 SkTLazy ()=default
 
 SkTLazy (const T *src)
 
 SkTLazy (const SkTLazy &that)
 
 SkTLazy (SkTLazy &&that)
 
 ~SkTLazy ()=default
 
SkTLazyoperator= (const SkTLazy &that)
 
SkTLazyoperator= (SkTLazy &&that)
 
template<typename... Args>
Tinit (Args &&... args)
 
Tset (const T &src)
 
Tset (T &&src)
 
void reset ()
 
bool isValid () const
 
Tget ()
 
const Tget () const
 
Toperator-> ()
 
const Toperator-> () const
 
Toperator* ()
 
const Toperator* () const
 
const TgetMaybeNull () const
 
TgetMaybeNull ()
 

Detailed Description

template<typename T>
class SkTLazy< T >

Efficient way to defer allocating/initializing a class until it is needed (if ever).

Definition at line 20 of file SkTLazy.h.

Constructor & Destructor Documentation

◆ SkTLazy() [1/4]

template<typename T >
SkTLazy< T >::SkTLazy ( )
default

◆ SkTLazy() [2/4]

template<typename T >
SkTLazy< T >::SkTLazy ( const T src)
inlineexplicit

Definition at line 23 of file SkTLazy.h.

23: fValue(src ? std::optional<T>(*src) : std::nullopt) {}
Definition ref_ptr.h:256

◆ SkTLazy() [3/4]

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

Definition at line 24 of file SkTLazy.h.

24: fValue(that.fValue) {}

◆ SkTLazy() [4/4]

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

Definition at line 25 of file SkTLazy.h.

25: fValue(std::move(that.fValue)) {}

◆ ~SkTLazy()

template<typename T >
SkTLazy< T >::~SkTLazy ( )
default

Member Function Documentation

◆ get() [1/2]

template<typename T >
T * SkTLazy< T >::get ( )
inline

Returns the object. This version should only be called when the caller knows that the object has been initialized.

Definition at line 83 of file SkTLazy.h.

83 {
84 SkASSERT(fValue.has_value());
85 return &fValue.value();
86 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ get() [2/2]

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

Definition at line 87 of file SkTLazy.h.

87 {
88 SkASSERT(fValue.has_value());
89 return &fValue.value();
90 }

◆ getMaybeNull() [1/2]

template<typename T >
T * SkTLazy< T >::getMaybeNull ( )
inline

Definition at line 109 of file SkTLazy.h.

109{ return fValue.has_value() ? this->get() : nullptr; }
T * get()
Definition SkTLazy.h:83

◆ getMaybeNull() [2/2]

template<typename T >
const T * SkTLazy< T >::getMaybeNull ( ) const
inline

Like above but doesn't assert if object isn't initialized (in which case nullptr is returned).

Definition at line 108 of file SkTLazy.h.

108{ return fValue.has_value() ? this->get() : nullptr; }

◆ init()

template<typename T >
template<typename... Args>
T * SkTLazy< T >::init ( Args &&...  args)
inline

Return a pointer to an instance of the class initialized with 'args'. If a previous instance had been initialized (either from init() or set()) it will first be destroyed, so that a freshly initialized instance is always returned.

Definition at line 45 of file SkTLazy.h.

45 {
46 fValue.emplace(std::forward<Args>(args)...);
47 return this->get();
48 }
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ isValid()

template<typename T >
bool SkTLazy< T >::isValid ( ) const
inline

Returns true if a valid object has been initialized in the SkTLazy, false otherwise.

Definition at line 77 of file SkTLazy.h.

77{ return fValue.has_value(); }

◆ operator*() [1/2]

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

Definition at line 95 of file SkTLazy.h.

95 {
96 SkASSERT(fValue.has_value());
97 return *fValue;
98 }

◆ operator*() [2/2]

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

Definition at line 99 of file SkTLazy.h.

99 {
100 SkASSERT(fValue.has_value());
101 return *fValue;
102 }

◆ operator->() [1/2]

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

Definition at line 92 of file SkTLazy.h.

92{ return this->get(); }

◆ operator->() [2/2]

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

Definition at line 93 of file SkTLazy.h.

93{ return this->get(); }

◆ operator=() [1/2]

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

Definition at line 29 of file SkTLazy.h.

29 {
30 fValue = that.fValue;
31 return *this;
32 }

◆ operator=() [2/2]

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

Definition at line 34 of file SkTLazy.h.

34 {
35 fValue = std::move(that.fValue);
36 return *this;
37 }

◆ reset()

template<typename T >
void SkTLazy< T >::reset ( )
inline

Destroy the lazy object (if it was created via init() or set())

Definition at line 69 of file SkTLazy.h.

69 {
70 fValue.reset();
71 }

◆ set() [1/2]

template<typename T >
T * SkTLazy< T >::set ( const T src)
inline

Copy src into this, and return a pointer to a copy of it. Note this will always return the same pointer, so if it is called on a lazy that has already been initialized, then this will copy over the previous contents.

Definition at line 56 of file SkTLazy.h.

56 {
57 fValue = src;
58 return this->get();
59 }

◆ set() [2/2]

template<typename T >
T * SkTLazy< T >::set ( T &&  src)
inline

Definition at line 61 of file SkTLazy.h.

61 {
62 fValue = std::move(src);
63 return this->get();
64 }

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