Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLazyStorage< T, Args > Class Template Reference

#include <KisLazyStorage.h>

Classes

struct  init_value_tag
 

Public Member Functions

 KisLazyStorage (Args... args)
 
 KisLazyStorage (const KisLazyStorage &rhs)=delete
 
 KisLazyStorage (init_value_tag, T &&value)
 
 KisLazyStorage (KisLazyStorage &&rhs)
 
T & operator* ()
 
T * operator-> ()
 
KisLazyStorageoperator= (const KisLazyStorage &rhs)=delete
 
KisLazyStorageoperator= (KisLazyStorage &&rhs)
 
 ~KisLazyStorage ()
 

Private Member Functions

T * getPointer ()
 

Static Private Member Functions

static T * constructObject (Args... args)
 

Private Attributes

std::tuple< Args... > m_constructionArgs
 
std::atomic< T * > m_data
 
std::mutex m_mutex
 

Detailed Description

template<typename T, typename... Args>
class KisLazyStorage< T, Args >

KisLazyStorage is a special class implementing some kind of lazy evaluation. It mimics the behavior of a normal pointer type, but creates T only on the first trt to dereference this pointer.

Definition at line 24 of file KisLazyStorage.h.

Constructor & Destructor Documentation

◆ KisLazyStorage() [1/4]

template<typename T , typename... Args>
KisLazyStorage< T, Args >::KisLazyStorage ( Args... args)
inlineexplicit

Create a storage with a deferred creation of the object T. The arguments args are passed to the constructor of T on the first dereference operation on the storage.

Definition at line 34 of file KisLazyStorage.h.

35 : m_constructionArgs(std::forward<Args>(args)...),
36 m_data(0)
37 {
38 }
std::atomic< T * > m_data
std::tuple< Args... > m_constructionArgs

◆ KisLazyStorage() [2/4]

template<typename T , typename... Args>
KisLazyStorage< T, Args >::KisLazyStorage ( init_value_tag ,
T && value )
inlineexplicit

Create a storage and initialize it with value right away without any deferring. Please take it into account that the storage will still store a default- initialized values of types Args... in an internal tuple. If you want to avoid this default-construction, then just wrap the arguments into std::optional.

Definition at line 48 of file KisLazyStorage.h.

49 : m_data(new T(std::forward<T>(value)))
50 {
51 }
float value(const T *src, size_t ch)

◆ KisLazyStorage() [3/4]

template<typename T , typename... Args>
KisLazyStorage< T, Args >::KisLazyStorage ( const KisLazyStorage< T, Args > & rhs)
delete

◆ KisLazyStorage() [4/4]

template<typename T , typename... Args>
KisLazyStorage< T, Args >::KisLazyStorage ( KisLazyStorage< T, Args > && rhs)
inline

Definition at line 56 of file KisLazyStorage.h.

56 {
57 *this = std::move(rhs);
58 }

◆ ~KisLazyStorage()

template<typename T , typename... Args>
KisLazyStorage< T, Args >::~KisLazyStorage ( )
inline

Definition at line 71 of file KisLazyStorage.h.

71 {
72 delete m_data.load();
73 }

References KisLazyStorage< T, Args >::m_data.

Member Function Documentation

◆ constructObject()

template<typename T , typename... Args>
static T * KisLazyStorage< T, Args >::constructObject ( Args... args)
inlinestaticprivate

Definition at line 94 of file KisLazyStorage.h.

94 {
95 return new T(std::forward<Args>(args)...);
96 }

◆ getPointer()

template<typename T , typename... Args>
T * KisLazyStorage< T, Args >::getPointer ( )
inlineprivate

Definition at line 84 of file KisLazyStorage.h.

84 {
85 if(!m_data) {
86 std::unique_lock l(m_mutex);
87 if(!m_data) {
89 }
90 }
91 return m_data;
92 }
static T * constructObject(Args... args)
std::mutex m_mutex

References KisLazyStorage< T, Args >::constructObject(), KisLazyStorage< T, Args >::m_constructionArgs, KisLazyStorage< T, Args >::m_data, and KisLazyStorage< T, Args >::m_mutex.

◆ operator*()

template<typename T , typename... Args>
T & KisLazyStorage< T, Args >::operator* ( )
inline

Definition at line 79 of file KisLazyStorage.h.

79 {
80 return *getPointer();
81 }

References KisLazyStorage< T, Args >::getPointer().

◆ operator->()

template<typename T , typename... Args>
T * KisLazyStorage< T, Args >::operator-> ( )
inline

Definition at line 75 of file KisLazyStorage.h.

75 {
76 return getPointer();
77 }

References KisLazyStorage< T, Args >::getPointer().

◆ operator=() [1/2]

template<typename T , typename... Args>
KisLazyStorage & KisLazyStorage< T, Args >::operator= ( const KisLazyStorage< T, Args > & rhs)
delete

◆ operator=() [2/2]

template<typename T , typename... Args>
KisLazyStorage & KisLazyStorage< T, Args >::operator= ( KisLazyStorage< T, Args > && rhs)
inline

Definition at line 60 of file KisLazyStorage.h.

60 {
61 std::scoped_lock lock(m_mutex, rhs.m_mutex);
62
64 delete m_data.load();
65 m_data.store(rhs.m_data.load());
66 rhs.m_data.store(0);
67
68 return *this;
69 }

References KisLazyStorage< T, Args >::m_constructionArgs, KisLazyStorage< T, Args >::m_data, and KisLazyStorage< T, Args >::m_mutex.

Member Data Documentation

◆ m_constructionArgs

template<typename T , typename... Args>
std::tuple<Args...> KisLazyStorage< T, Args >::m_constructionArgs
private

Definition at line 99 of file KisLazyStorage.h.

◆ m_data

template<typename T , typename... Args>
std::atomic<T*> KisLazyStorage< T, Args >::m_data
private

Definition at line 100 of file KisLazyStorage.h.

◆ m_mutex

template<typename T , typename... Args>
std::mutex KisLazyStorage< T, Args >::m_mutex
private

Definition at line 101 of file KisLazyStorage.h.


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