Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkTLazy< T > Class Template Reference

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

#include <SkTLazy.h>

Public Member Functions

 SkTLazy (const T *src)
 
 SkTLazy (const SkTLazy &src)
 
SkTLazyoperator= (const SkTLazy &src)
 
template<typename... Args>
T * init (Args &&...args)
 Return a pointer to an instance of the class initialized with 'args'. More...
 
T * set (const T &src)
 Copy src into this, and return a pointer to a copy of it. More...
 
void reset ()
 Destroy the lazy object (if it was created via init() or set())
 
bool isValid () const
 Returns true if a valid object has been initialized in the SkTLazy, false otherwise.
 
T * get () const
 Returns the object. More...
 
T * getMaybeNull () const
 Like above but doesn't assert if object isn't initialized (in which case nullptr is returned).
 

Private Attributes

SkAlignedSTStorage< 1, T > fStorage
 
T * fPtr
 

Detailed Description

template<typename T>
class SkTLazy< T >

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

Member Function Documentation

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

Returns the object.

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

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.

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.


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