Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkAnySubclass< Base, Size > Class Template Reference

#include <SkAnySubclass.h>

Public Member Functions

 SkAnySubclass ()=default
 
 ~SkAnySubclass ()
 
 SkAnySubclass (const SkAnySubclass &)=delete
 
SkAnySubclassoperator= (const SkAnySubclass &)=delete
 
 SkAnySubclass (SkAnySubclass &&)=delete
 
SkAnySubclassoperator= (SkAnySubclass &&)=delete
 
template<typename T , typename... Args>
void emplace (Args &&... args)
 
void reset ()
 
const Base * get () const
 
Base * get ()
 
Base * operator-> ()
 
const Base * operator-> () const
 

Detailed Description

template<typename Base, size_t Size>
class SkAnySubclass< Base, Size >

Stores any subclass T of Base, where sizeof(T) <= Size, without using the heap. Doesn't need advance knowledge of T, so it's particularly suited to platform or backend implementations of a generic interface, where the set of possible subclasses is finite and known, but can't be made available at compile-time.

Definition at line 25 of file SkAnySubclass.h.

Constructor & Destructor Documentation

◆ SkAnySubclass() [1/3]

template<typename Base , size_t Size>
SkAnySubclass< Base, Size >::SkAnySubclass ( )
default

◆ ~SkAnySubclass()

template<typename Base , size_t Size>
SkAnySubclass< Base, Size >::~SkAnySubclass ( )
inline

Definition at line 28 of file SkAnySubclass.h.

28 {
29 this->reset();
30 }

◆ SkAnySubclass() [2/3]

template<typename Base , size_t Size>
SkAnySubclass< Base, Size >::SkAnySubclass ( const SkAnySubclass< Base, Size > &  )
delete

◆ SkAnySubclass() [3/3]

template<typename Base , size_t Size>
SkAnySubclass< Base, Size >::SkAnySubclass ( SkAnySubclass< Base, Size > &&  )
delete

Member Function Documentation

◆ emplace()

template<typename Base , size_t Size>
template<typename T , typename... Args>
void SkAnySubclass< Base, Size >::emplace ( Args &&...  args)
inline

Definition at line 38 of file SkAnySubclass.h.

38 {
39 static_assert(std::is_base_of_v<Base, T>);
40 static_assert(sizeof(T) <= Size);
41 // We're going to clean up our stored object by calling ~Base:
42 static_assert(std::has_virtual_destructor_v<Base> || std::is_trivially_destructible_v<T>);
43 SkASSERT(!fValid);
44 new (fData) T(std::forward<Args>(args)...);
45 fValid = true;
46 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
TSize< Scalar > Size
Definition: size.h:137
#define T
Definition: precompiler.cc:65

◆ get() [1/2]

template<typename Base , size_t Size>
Base * SkAnySubclass< Base, Size >::get ( )
inline

Definition at line 60 of file SkAnySubclass.h.

60 {
61 SkASSERT(fValid);
62 return std::launder(reinterpret_cast<Base*>(fData));
63 }

◆ get() [2/2]

template<typename Base , size_t Size>
const Base * SkAnySubclass< Base, Size >::get ( ) const
inline

Definition at line 55 of file SkAnySubclass.h.

55 {
56 SkASSERT(fValid);
57 return std::launder(reinterpret_cast<const Base*>(fData));
58 }

◆ operator->() [1/2]

template<typename Base , size_t Size>
Base * SkAnySubclass< Base, Size >::operator-> ( )
inline

Definition at line 65 of file SkAnySubclass.h.

65{ return this->get(); }
const Base * get() const
Definition: SkAnySubclass.h:55

◆ operator->() [2/2]

template<typename Base , size_t Size>
const Base * SkAnySubclass< Base, Size >::operator-> ( ) const
inline

Definition at line 66 of file SkAnySubclass.h.

66{ return this->get(); }

◆ operator=() [1/2]

template<typename Base , size_t Size>
SkAnySubclass & SkAnySubclass< Base, Size >::operator= ( const SkAnySubclass< Base, Size > &  )
delete

◆ operator=() [2/2]

template<typename Base , size_t Size>
SkAnySubclass & SkAnySubclass< Base, Size >::operator= ( SkAnySubclass< Base, Size > &&  )
delete

◆ reset()

template<typename Base , size_t Size>
void SkAnySubclass< Base, Size >::reset ( )
inline

Definition at line 48 of file SkAnySubclass.h.

48 {
49 if (fValid) {
50 this->get()->~Base();
51 }
52 fValid = false;
53 }

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