23 #ifndef VLC_CXX_HELPERS_HPP
24 #define VLC_CXX_HELPERS_HPP
34 #include <type_traits>
68 template <
typename T,
typename Releaser>
69 inline 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 )
94 template <
typename T,
typename Releaser>
95 inline 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 )
108 template <
typename T>
109 inline std::unique_ptr<T, void (*)(
void*)> wrap_cptr( T* ptr ) noexcept
111 return wrap_cptr( ptr, &free );
119 template <
typename T>
120 inline std::unique_ptr<T[], void (*)(
void*)> wrap_carray( T* ptr ) noexcept
122 return wrap_carray( ptr, &free );
148 template <
typename T,
typename H,
typename R, H HOLD, R RELEASE>
149 class vlc_shared_data_ptr {
154 vlc_shared_data_ptr() =
default;
167 explicit vlc_shared_data_ptr(T *ptr,
bool hold =
true)
174 vlc_shared_data_ptr(
const vlc_shared_data_ptr &other)
175 : vlc_shared_data_ptr(other.ptr) {}
177 vlc_shared_data_ptr(vlc_shared_data_ptr &&other) noexcept
183 ~vlc_shared_data_ptr()
189 vlc_shared_data_ptr &operator=(
const vlc_shared_data_ptr &other)
191 reset(other.ptr,
true);
195 vlc_shared_data_ptr &operator=(vlc_shared_data_ptr &&other) noexcept
197 reset(other.ptr,
false);
202 bool operator==(
const vlc_shared_data_ptr &other)
const
204 return ptr == other.ptr;
207 bool operator==(std::nullptr_t)
const noexcept
209 return ptr ==
nullptr;
212 bool operator!=(
const vlc_shared_data_ptr &other)
const
214 return !(*
this == other);
217 bool operator!=(std::nullptr_t)
const noexcept
219 return ptr !=
nullptr;
222 explicit operator bool()
const
232 T *operator->()
const
259 void reset(T *newptr =
nullptr,
bool hold =
true)
270 #define vlc_shared_data_ptr_type(type, hold, release) \
271 ::vlc::vlc_shared_data_ptr<type, decltype(&hold), decltype(&release), \
274 #ifdef VLC_THREADS_H_
287 mutex(
const mutex& ) =
delete;
288 mutex& operator=(
const mutex& ) =
delete;
289 mutex( mutex&& ) =
delete;
290 mutex& operator=( mutex&& ) =
delete;
296 void unlock() noexcept
303 friend class condition_variable;
304 friend class mutex_locker;
307 class condition_variable
310 condition_variable() noexcept
314 void signal() noexcept
318 void broadcast() noexcept
322 void wait( mutex& mutex ) noexcept
326 int timedwait( mutex& mutex,
vlc_tick_t deadline ) noexcept
343 mutex_locker( mutex& m ) noexcept
344 : mutex_locker( &m.m_mutex )
351 mutex_locker(
const mutex_locker& ) =
delete;
352 mutex_locker& operator=(
const mutex_locker& ) =
delete;
353 mutex_locker( mutex_locker&& ) =
delete;
354 mutex_locker& operator=( mutex_locker&& ) =
delete;
367 semaphore(
unsigned int count ) noexcept
375 semaphore(
const semaphore& ) =
delete;
376 semaphore& operator=(
const semaphore& ) =
delete;
377 semaphore( semaphore&& ) =
delete;
378 semaphore& operator=( semaphore&& ) =
delete;
389 int wait_i11e() noexcept
400 #endif // VLC_THREADS_H_
407 class invalid :
public std::runtime_error
410 invalid(
const char* url )
411 : std::runtime_error( std::string{
"Invalid url: " } + url )
418 psz_buffer =
nullptr;
419 psz_pathbuffer =
nullptr;
423 url(
const char* str )
426 throw invalid( str );
429 url(
const std::string& str )
439 url(
const url& ) =
delete;
440 url& operator=(
const url& ) =
delete;
442 url( url&& u ) noexcept
446 u.psz_pathbuffer =
nullptr;
447 u.psz_host =
nullptr;
450 url& operator=( url&& u ) noexcept
453 u.psz_buffer =
nullptr;
454 u.psz_pathbuffer =
nullptr;
455 u.psz_host =
nullptr;
466 #endif // VLC_CXX_HELPERS_HPP