23#ifndef VLC_CXX_HELPERS_HPP
24#define VLC_CXX_HELPERS_HPP
30#if defined(__cplusplus) || defined(DOC)
68template <
typename T,
typename Releaser>
69inline auto wrap_cptr( T* ptr, Releaser&& r )
noexcept
70 -> std::unique_ptr<T,
typename std::decay<
decltype( r )>::type>
72 return std::unique_ptr<T,
typename std::decay<
decltype( r )>::type>{
73 ptr, std::forward<Releaser>( r )
94template <
typename T,
typename Releaser>
95inline auto wrap_carray( T* ptr, Releaser&& r )
noexcept
96 -> std::unique_ptr<T[],
typename std::decay<
decltype( r )>::type>
98 return std::unique_ptr<T[],
typename std::decay<
decltype( r )>::type>{
99 ptr, std::forward<Releaser>( r )
109inline std::unique_ptr<T, void (*)(
void*)> wrap_cptr( T* ptr )
noexcept
111 return wrap_cptr( ptr, &free );
120inline std::unique_ptr<T[], void (*)(
void*)> wrap_carray( T* ptr )
noexcept
122 return wrap_carray( ptr, &free );
148template <
typename T,
typename H,
typename R, H HOLD, R RELEASE>
196 reset(other.ptr,
true);
202 reset(other.ptr,
false);
209 return ptr == other.ptr;
214 return ptr ==
nullptr;
219 return !(*
this == other);
224 return ptr !=
nullptr;
227 explicit operator bool()
const
264 void reset(T *newptr =
nullptr,
bool hold =
true)
275#define vlc_shared_data_ptr_type(type, hold, release) \
276 ::vlc::vlc_shared_data_ptr<type, decltype(&hold), decltype(&release), \
279#if defined(VLC_THREADS_H_) || defined(DOC)
412 class invalid :
public std::runtime_error
415 explicit invalid(
const char* url )
416 : std::runtime_error( std::string{
"Invalid url: " } + url )
423 psz_buffer =
nullptr;
424 psz_pathbuffer =
nullptr;
428 explicit url(
const char* str )
433 throw invalid( str );
437 explicit url(
const std::string& str )
447 url(
const url& ) =
delete;
448 url& operator=(
const url& ) =
delete;
450 url( url&& u ) noexcept
454 u.psz_pathbuffer =
nullptr;
455 u.psz_host =
nullptr;
458 url& operator=( url&& u )
noexcept
462 u.psz_buffer =
nullptr;
463 u.psz_pathbuffer =
nullptr;
464 u.psz_host =
nullptr;
Definition vlc_cxx_helpers.hpp:313
void wait(mutex &mutex) noexcept
Definition vlc_cxx_helpers.hpp:327
int timedwait(mutex &mutex, vlc_tick_t deadline) noexcept
Definition vlc_cxx_helpers.hpp:331
void signal() noexcept
Definition vlc_cxx_helpers.hpp:319
condition_variable() noexcept
Definition vlc_cxx_helpers.hpp:315
void broadcast() noexcept
Definition vlc_cxx_helpers.hpp:323
Definition vlc_cxx_helpers.hpp:341
mutex_locker & operator=(const mutex_locker &)=delete
mutex_locker(mutex_locker &&)=delete
~mutex_locker()
Definition vlc_cxx_helpers.hpp:352
mutex_locker(mutex &m) noexcept
Definition vlc_cxx_helpers.hpp:348
mutex_locker(const mutex_locker &)=delete
mutex_locker(vlc_mutex_t *m) noexcept
Definition vlc_cxx_helpers.hpp:343
mutex_locker & operator=(mutex_locker &&)=delete
Definition vlc_cxx_helpers.hpp:285
mutex(const mutex &)=delete
mutex & operator=(mutex &&)=delete
void unlock() noexcept
Definition vlc_cxx_helpers.hpp:301
mutex() noexcept
Definition vlc_cxx_helpers.hpp:287
mutex & operator=(const mutex &)=delete
void lock() noexcept
Definition vlc_cxx_helpers.hpp:297
Definition vlc_cxx_helpers.hpp:366
semaphore(unsigned int count) noexcept
Definition vlc_cxx_helpers.hpp:372
~semaphore()
Definition vlc_cxx_helpers.hpp:376
semaphore & operator=(const semaphore &)=delete
void wait() noexcept
Definition vlc_cxx_helpers.hpp:389
semaphore(const semaphore &)=delete
semaphore & operator=(semaphore &&)=delete
semaphore() noexcept
Definition vlc_cxx_helpers.hpp:368
semaphore(semaphore &&)=delete
int post() noexcept
Definition vlc_cxx_helpers.hpp:385
int wait_i11e() noexcept
Definition vlc_cxx_helpers.hpp:394
Wraps a C shared resource having associated Hold() and Release() functions.
Definition vlc_cxx_helpers.hpp:149
vlc_shared_data_ptr(const vlc_shared_data_ptr &other)
Definition vlc_cxx_helpers.hpp:179
vlc_shared_data_ptr(vlc_shared_data_ptr &&other) noexcept
Definition vlc_cxx_helpers.hpp:182
vlc_shared_data_ptr & operator=(vlc_shared_data_ptr &&other) noexcept
Definition vlc_cxx_helpers.hpp:200
bool operator==(const vlc_shared_data_ptr &other) const
Definition vlc_cxx_helpers.hpp:207
~vlc_shared_data_ptr()
Definition vlc_cxx_helpers.hpp:188
vlc_shared_data_ptr & operator=(const vlc_shared_data_ptr &other)
Definition vlc_cxx_helpers.hpp:194
T * operator->() const
Definition vlc_cxx_helpers.hpp:237
vlc_shared_data_ptr(std::nullptr_t)
Definition vlc_cxx_helpers.hpp:174
void reset(T *newptr=nullptr, bool hold=true)
Reset the shared resource.
Definition vlc_cxx_helpers.hpp:264
vlc_shared_data_ptr(T *ptr, bool hold=true)
Wrap a shared resource.
Definition vlc_cxx_helpers.hpp:167
T * get() const
Definition vlc_cxx_helpers.hpp:242
bool operator==(std::nullptr_t) const noexcept
Definition vlc_cxx_helpers.hpp:212
bool operator!=(const vlc_shared_data_ptr &other) const
Definition vlc_cxx_helpers.hpp:217
vlc_shared_data_ptr()=default
T & operator*() const
Definition vlc_cxx_helpers.hpp:232
bool operator!=(std::nullptr_t) const noexcept
Definition vlc_cxx_helpers.hpp:222
size_t count
Definition core.c:403
void vlc_cond_signal(vlc_cond_t *cond)
Wakes up one thread waiting on a condition variable.
Definition threads.c:193
int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex, vlc_tick_t deadline)
Waits on a condition variable up to a certain date.
Definition threads.c:292
void vlc_cond_broadcast(vlc_cond_t *cond)
Wakes up all threads waiting on a condition variable.
Definition threads.c:220
void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
Waits on a condition variable.
Definition threads.c:280
void vlc_cond_init(vlc_cond_t *cond)
Initializes a condition variable.
Definition threads.c:174
int vlc_sem_wait_i11e(vlc_sem_t *sem)
Interruptible variant of vlc_sem_wait().
Definition interrupt.c:206
void vlc_mutex_unlock(vlc_mutex_t *mtx)
Releases a mutex.
Definition threads.c:149
void vlc_mutex_init(vlc_mutex_t *mtx)
Initializes a fast mutex.
Definition threads.c:75
void vlc_mutex_lock(vlc_mutex_t *mtx)
Acquires a mutex.
Definition threads.c:95
void vlc_sem_wait(vlc_sem_t *sem)
Waits on a semaphore.
Definition threads.c:344
void vlc_sem_init(vlc_sem_t *sem, unsigned value)
Initializes a semaphore.
Definition threads.c:323
int vlc_sem_post(vlc_sem_t *sem)
Increments the value of a semaphore.
Definition threads.c:328
int vlc_UrlParse(vlc_url_t *url, const char *str)
Parses an URI or IRI.
Definition url.c:581
Definition vlc_cxx_helpers.hpp:46
Condition variable.
Definition vlc_threads.h:270
Mutex.
Definition vlc_threads.h:143
Semaphore.
Definition vlc_threads.h:368
char * psz_buffer
Definition vlc_url.h:156
void vlc_UrlClean(vlc_url_t *restrict url)
Definition url.c:621
This file declares interruptible sleep functions.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48