VLC 4.0.0-dev
|
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_ptr & | operator= (const vlc_shared_data_ptr &other) |
vlc_shared_data_ptr & | operator= (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. | |
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 = /* ... *‍/; MyTypePtr ptr(raw_ptr);
|
default |
|
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.
ptr | the raw pointer (can be nullptr) |
hold | whether the resource must be hold |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlineexplicit |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
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.
newptr | the raw pointer (can be nullptr) |
hold | whether 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=().