NAP
Public Member Functions | Protected Member Functions | List of all members
SafeOwner< T > Class Template Reference

#include <audio/utility/safeptr.h>

Public Member Functions

 SafeOwner ()=default
 
 SafeOwner (DeletionQueue &deletionQueue, T *ptr)
 
 ~SafeOwner ()
 
 SafeOwner (const std::nullptr_t)
 
SafeOwneroperator= (const std::nullptr_t)
 
 SafeOwner (const SafeOwner &other)=delete
 
SafeOwneroperator= (const SafeOwner &other)=delete
 
 SafeOwner (SafeOwner< T > &&other)
 
SafeOwner< T > & operator= (SafeOwner< T > &&other)
 
template<typename OTHER >
 SafeOwner (SafeOwner< OTHER > &&other)
 
template<typename OTHER >
SafeOwner< T > & operator= (SafeOwner< OTHER > &&other)
 
const T & operator* () const
 
T & operator* ()
 
T * operator-> () const
 
T * operator-> ()
 
template<typename OTHER >
bool operator== (const OTHER *ptr) const
 
template<typename OTHER >
bool operator!= (const OTHER *ptr) const
 
bool operator== (const std::nullptr_t) const
 
bool operator!= (const std::nullptr_t) const
 
SafePtr< T > get ()
 
SafePtr< T > get () const
 
T * getRaw ()
 
T * getRaw () const
 

Protected Member Functions

void * getData () override
 
void setData (void *data) override
 
DeletionQueuegetDeletionQueue () override
 
void setDeletionQueue (DeletionQueue *queue) override
 

Description

template<typename T>
class nap::audio::SafeOwner< T >

SafeOwner is a special case smart pointer to an object that is used in multiple threads. It serves the purpose of making sure that the object is destructed in a thread safe manner when the SafeOwner goes out of scope. It works very much like unique_ptr in such that it takes ownership over the object it points to and takes responsibility for it's destruction. The difference to unique_ptr is that instead of letting the object destruct itself when the pointer goes out of scope, it throws the object in a DeletionQueue. Objects in the DeletionQueue are kept alive until the DeletionQueue is cleared at a moment when there is noone else using the object anymore. This is done to prevent the objects to be destroyed while they are possibly being used in another thread at the same time.

Constructor & Destructor Documentation

◆ SafeOwner() [1/6]

SafeOwner ( )
default

◆ SafeOwner() [2/6]

SafeOwner ( DeletionQueue deletionQueue,
T *  ptr 
)

The constructor takes the DeletionQueue that the owner will use to dispose it's managed object and a pointer to the object it will manage.

◆ ~SafeOwner()

~SafeOwner ( )

The destructor of the SafeOwner base class. Instead of letting the managed object destruct itself it is thrown into the DeletionQueue, from which it will be deleted on a safe moment.

◆ SafeOwner() [3/6]

SafeOwner ( const std::nullptr_t  )

◆ SafeOwner() [4/6]

SafeOwner ( const SafeOwner< T > &  other)
delete

◆ SafeOwner() [5/6]

SafeOwner ( SafeOwner< T > &&  other)

◆ SafeOwner() [6/6]

SafeOwner ( SafeOwner< OTHER > &&  other)

Member Function Documentation

◆ get() [1/2]

SafePtr<T> get ( )

Returns a SafePtr to the owned object. The SafePtr (and all it's future copies) will be set to nullptr when the managed object will be destroyed by the DeletionQueue.

◆ get() [2/2]

SafePtr<T> get ( ) const

Returns a const SafePtr to the owned object. The SafePtr (and all it's future copies) will be set to nullptr when the managed object will be destroyed by the DeletionQueue.

◆ getData()

void* getData ( )
overrideprotected

◆ getDeletionQueue()

DeletionQueue* getDeletionQueue ( )
overrideprotected

◆ getRaw() [1/2]

T* getRaw ( )

Returns a raw pointer to the owned object.

◆ getRaw() [2/2]

T* getRaw ( ) const

Returns a const raw pointer to the owned object.

◆ operator!=() [1/2]

bool operator!= ( const OTHER *  ptr) const

◆ operator!=() [2/2]

bool operator!= ( const std::nullptr_t  ) const

◆ operator*() [1/2]

T& operator* ( )

◆ operator*() [2/2]

const T& operator* ( ) const

◆ operator->() [1/2]

T* operator-> ( )

◆ operator->() [2/2]

T* operator-> ( ) const

◆ operator=() [1/4]

SafeOwner& operator= ( const SafeOwner< T > &  other)
delete

◆ operator=() [2/4]

SafeOwner& operator= ( const std::nullptr_t  )

◆ operator=() [3/4]

SafeOwner<T>& operator= ( SafeOwner< OTHER > &&  other)

◆ operator=() [4/4]

SafeOwner<T>& operator= ( SafeOwner< T > &&  other)

◆ operator==() [1/2]

bool operator== ( const OTHER *  ptr) const

◆ operator==() [2/2]

bool operator== ( const std::nullptr_t  ) const

◆ setData()

void setData ( void *  data)
overrideprotected

◆ setDeletionQueue()

void setDeletionQueue ( DeletionQueue queue)
overrideprotected