1#ifndef __AUDACITY_MEMORY_X_H__
2#define __AUDACITY_MEMORY_X_H__
28class ArrayOf :
public std::unique_ptr<X[]>
33 template<
typename Integral>
34 explicit ArrayOf(Integral count,
bool initialize =
false)
36 static_assert(std::is_unsigned<Integral>::value,
"Unsigned arguments only");
43 :
std::unique_ptr < X[] >
44 (
std::move((
std::unique_ptr < X[] >&)(that)))
49 std::unique_ptr<X[]>::operator=(std::move(that));
54 std::unique_ptr<X[]>::operator=(std::move(that));
58 template<
typename Integral >
60 bool initialize =
false)
62 static_assert(std::is_unsigned<Integral>::value,
"Unsigned arguments only");
65 std::unique_ptr<X[]>::reset(
safenew X[count]{});
68 std::unique_ptr<X[]>::reset(
safenew X[count]);
87 template<
typename Integral>
92 template<
typename Integral1,
typename Integral2 >
93 ArraysOf(Integral1 N, Integral2 M,
bool initialize =
false)
96 static_assert(std::is_unsigned<Integral1>::value,
"Unsigned arguments only");
97 static_assert(std::is_unsigned<Integral2>::value,
"Unsigned arguments only");
98 for (
size_t ii = 0; ii < N; ++ii)
110 template<
typename Integral >
116 template<
typename Integral >
117 void reinit(Integral count,
bool initialize)
122 template<
typename Integral1,
typename Integral2 >
123 void reinit(Integral1 countN, Integral2 countM,
bool initialize =
false)
125 static_assert(std::is_unsigned<Integral1>::value,
"Unsigned arguments only");
126 static_assert(std::is_unsigned<Integral2>::value,
"Unsigned arguments only");
128 for (
size_t ii = 0; ii < countN; ++ii)
129 (*
this)[ii].reinit(countM, initialize);
141template<
typename T >
147template <
typename Character =
char>
202template<
typename T >
212template<
typename T >
215 using std::unique_ptr< T, RestoreValue<T> >::reset;
229 std::unique_ptr < T, RestoreValue<T> >::operator=(std::move(that));
237template<
typename T >
252template<
typename T >
256template<
typename T >
266#if defined(_WIN32) && defined(_MSC_VER)
268 std::hardware_destructive_interference_size
276 static void *
operator new(std::size_t count, std::align_val_t al);
277 static void operator delete(
void *ptr, std::align_val_t al);
279#if defined (_MSC_VER) && defined(_DEBUG)
283 static void *
operator new(
284 std::size_t count, std::align_val_t al, int,
const char *, int)
285 {
return operator new(count, al); }
286 static void operator delete(
287 void *ptr, std::align_val_t al, int,
const char *, int)
288 {
return operator delete(ptr, al); }
299 template<
typename... Args>
309 <T>(std::forward<Args>(args)...);
325 T::operator =(other);
331 T::operator =(std::move(other));
336#define QUANTIZED_TIME(time, rate) (floor(((double)(time) * (rate)) + 0.5) / (rate))
338#define DB_TO_LINEAR(x) (pow(10.0, (x) / 20.0))
339#define LINEAR_TO_DB(x) (20.0 * log10(x))
341#define MAX_AUDIO (1. - 1./(1<<15))
347 static_assert(AtomicUniquePointer::is_always_lock_free);
348 using std::atomic<T*>::atomic;
354 delete this->exchange(p, std::memory_order_release);
357 template<
typename... Args>
void emplace(Args &&... args) {
363 using std::atomic<T*>::fetch_add;
364 using std::atomic<T*>::fetch_sub;
370 const std::uint32_t x = 1u;
371 return static_cast<const unsigned char*
>(
static_cast<const void*
>(&x))[0];
376template <
typename IntType>
379 static_assert(std::is_integral<IntType>::value,
"Integral type required");
381 constexpr auto size =
sizeof(IntType);
386 if constexpr (
size == 1)
388 else if constexpr (
size == 2)
389 return (value >> 8) | (value << 8);
390 else if constexpr (
size == 4)
391 return ((value >> 24) & 0xFF) | ((value >> 8) & 0xFF00) |
392 ((value << 8) & 0xFF0000) | ((value << 24) & 0xFF000000);
393 else if constexpr (
size == 8)
394 return ((value >> 56) & 0xFF) | ((value >> 40) & 0xFF00) |
395 ((value >> 24) & 0xFF0000) | ((value >> 8) & 0xFF000000) |
396 ((value << 8) & 0xFF00000000) | ((value << 24) & 0xFF0000000000) |
397 ((value << 40) & 0xFF000000000000) |
398 ((value << 56) & 0xFF00000000000000);
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
struct UTILITY_API alignas(64) NonInterferingBase
Non-template helper for class template NonInterfering.
std::unique_ptr< Character[], freer > MallocString
constexpr IntType SwapIntBytes(IntType value) noexcept
Swap bytes in an integer.
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Finally(F) -> Finally< F >
std::unique_ptr< T, freer > MallocPtr
bool IsLittleEndian() noexcept
Check that machine is little-endian.
This simplifies arrays of arrays, each array separately allocated with NEW[] But it might be better t...
ArrayOf(const ArrayOf &)=delete
ArrayOf & operator=(ArrayOf &&that)
void reinit(Integral count, bool initialize=false)
ArrayOf(Integral count, bool initialize=false)
void reinit(Integral count)
ArraysOf(Integral1 N, Integral2 M, bool initialize=false)
ArraysOf(const ArraysOf &)=delete
ArraysOf & operator=(ArraysOf &&that)
void reinit(Integral1 countN, Integral2 countM, bool initialize=false)
void reinit(Integral count, bool initialize)
Set a variable temporarily in a scope.
ValueRestorer(T &var, const T &newValue)
ValueRestorer & operator=(ValueRestorer &&that)
ValueRestorer(ValueRestorer &&that)
void emplace(Args &&... args)
reset to a pointer to a new object with given ctor arguments
std::shared_ptr< T > pointer
CopyableValueRestorer(T &var, const T &newValue)
CopyableValueRestorer(T &var)
A deleter class to supply the second template parameter of unique_ptr for classes like wxWindow that ...
void operator()(T *p) const
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
void Set(T &&other)
Allow assignment from default-aligned base type.
void Set(const T &other)
Allow assignment from default-aligned base type.
Structure used by ValueRestorer.
void operator()(T *p) const
Workaround for std::make_shared not working on macOs with over-alignment.
static std::shared_ptr< T > make_shared(Args &&...args)
void operator()(void *p) const