VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > Class Template Reference

Wraps a C shared resource having associated Hold() and Release() functions. More...

#include <vlc_cxx_helpers.hpp>

Public Member Functions

 vlc_shared_data_ptr ()=default
 
 vlc_shared_data_ptr (T *ptr, bool hold=true)
 Wrap a shared resource.
 
 vlc_shared_data_ptr (std::nullptr_t)
 
 vlc_shared_data_ptr (const vlc_shared_data_ptr &other)
 
 vlc_shared_data_ptr (vlc_shared_data_ptr &&other) noexcept
 
 ~vlc_shared_data_ptr ()
 
vlc_shared_data_ptroperator= (const vlc_shared_data_ptr &other)
 
vlc_shared_data_ptroperator= (vlc_shared_data_ptr &&other) noexcept
 
bool operator== (const vlc_shared_data_ptr &other) const
 
bool operator== (std::nullptr_t) const noexcept
 
bool operator!= (const vlc_shared_data_ptr &other) const
 
bool operator!= (std::nullptr_t) const noexcept
 
 operator bool () const
 
T & operator* () const
 
T * operator-> () const
 
T * get () const
 
void reset (T *newptr=nullptr, bool hold=true)
 Reset the shared resource.
 

Detailed Description

template<typename T, typename H, typename R, H HOLD, R RELEASE>
class vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >

Wraps a C shared resource having associated Hold() and Release() functions.

This is a RAII wrapper for C shared resources (which are manually managed by calling explicitly their Hold() and Release() functions).

The Hold() and Release() functions must accept exactly one parameter having type T* (the raw pointer type). Their return type is irrelevant.

To create a new shared resource wrapper type for my_type_t, simply declare:

using MyTypePtr =
    vlc_shared_data_ptr_type(my_type_t, my_type_Hold, my_type_Release);

Then use it to wrap a raw C pointer:

my_type_t *raw_ptr = /* ... *&zwj;/;
MyTypePtr ptr(raw_ptr); 

Constructor & Destructor Documentation

◆ vlc_shared_data_ptr() [1/5]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::vlc_shared_data_ptr ( )
default

◆ vlc_shared_data_ptr() [2/5]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::vlc_shared_data_ptr ( T *  ptr,
bool  hold = true 
)
inlineexplicit

Wrap a shared resource.

If the pointer is not nullptr, and hold is true, then the resource is hold (the caller shared ownership is preserved). If hold is false, then the caller transfers the ownership to this wrapper.

Parameters
ptrthe raw pointer (can be nullptr)
holdwhether the resource must be hold

◆ vlc_shared_data_ptr() [3/5]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::vlc_shared_data_ptr ( std::nullptr_t  )
inline

◆ vlc_shared_data_ptr() [4/5]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::vlc_shared_data_ptr ( const vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > &  other)
inline

◆ vlc_shared_data_ptr() [5/5]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::vlc_shared_data_ptr ( vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > &&  other)
inlinenoexcept

◆ ~vlc_shared_data_ptr()

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::~vlc_shared_data_ptr ( )
inline

Member Function Documentation

◆ get()

template<typename T , typename H , typename R , H HOLD, R RELEASE>
T * vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::get ( ) const
inline

◆ operator bool()

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator bool ( ) const
inlineexplicit

◆ operator!=() [1/2]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
bool vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator!= ( const vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > &  other) const
inline

◆ operator!=() [2/2]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
bool vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator!= ( std::nullptr_t  ) const
inlinenoexcept

◆ operator*()

template<typename T , typename H , typename R , H HOLD, R RELEASE>
T & vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator* ( ) const
inline

◆ operator->()

template<typename T , typename H , typename R , H HOLD, R RELEASE>
T * vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator-> ( ) const
inline

◆ operator=() [1/2]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc_shared_data_ptr & vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator= ( const vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > &  other)
inline

◆ operator=() [2/2]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
vlc_shared_data_ptr & vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator= ( vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > &&  other)
inlinenoexcept

◆ operator==() [1/2]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
bool vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator== ( const vlc_shared_data_ptr< T, H, R, HOLD, RELEASE > &  other) const
inline

◆ operator==() [2/2]

template<typename T , typename H , typename R , H HOLD, R RELEASE>
bool vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator== ( std::nullptr_t  ) const
inlinenoexcept

◆ reset()

template<typename T , typename H , typename R , H HOLD, R RELEASE>
void vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::reset ( T *  newptr = nullptr,
bool  hold = true 
)
inline

Reset the shared resource.

ptr.reset(rawptr, hold);

is semantically equivalent to:

ptr = vlc_shared_data_ptr<...>(rawptr, hold);

If the pointer is not nullptr, and hold is true, then the resource is hold (the caller shared ownership is preserved). If hold is false, then the caller transfers the ownership to this wrapper.

Parameters
newptrthe raw pointer (can be nullptr)
holdwhether the resource must be hold

Referenced by vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator=(), and vlc::vlc_shared_data_ptr< T, H, R, HOLD, RELEASE >::operator=().


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