1#ifndef __AUDACITY_MEMORY_X_H__
2#define __AUDACITY_MEMORY_X_H__
27class ArrayOf :
public std::unique_ptr<X[]>
32 template<
typename Integral>
33 explicit ArrayOf(Integral count,
bool initialize =
false)
35 static_assert(std::is_unsigned<Integral>::value,
"Unsigned arguments only");
42 :
std::unique_ptr < X[] >
43 (
std::move((
std::unique_ptr < X[] >&)(that)))
48 std::unique_ptr<X[]>::operator=(std::move(that));
53 std::unique_ptr<X[]>::operator=(std::move(that));
57 template<
typename Integral >
59 bool initialize =
false)
61 static_assert(std::is_unsigned<Integral>::value,
"Unsigned arguments only");
64 std::unique_ptr<X[]>::reset(
safenew X[count]{});
67 std::unique_ptr<X[]>::reset(
safenew X[count]);
86 template<
typename Integral>
91 template<
typename Integral1,
typename Integral2 >
92 ArraysOf(Integral1 N, Integral2 M,
bool initialize =
false)
95 static_assert(std::is_unsigned<Integral1>::value,
"Unsigned arguments only");
96 static_assert(std::is_unsigned<Integral2>::value,
"Unsigned arguments only");
97 for (
size_t ii = 0; ii < N; ++ii)
109 template<
typename Integral >
115 template<
typename Integral >
116 void reinit(Integral count,
bool initialize)
121 template<
typename Integral1,
typename Integral2 >
122 void reinit(Integral1 countN, Integral2 countM,
bool initialize =
false)
124 static_assert(std::is_unsigned<Integral1>::value,
"Unsigned arguments only");
125 static_assert(std::is_unsigned<Integral2>::value,
"Unsigned arguments only");
127 for (
size_t ii = 0; ii < countN; ++ii)
128 (*
this)[ii].reinit(countM, initialize);
140template<
typename T >
146template <
typename Character =
char>
201template<
typename T >
211template<
typename T >
214 using std::unique_ptr< T, RestoreValue<T> >::reset;
228 std::unique_ptr < T, RestoreValue<T> >::operator=(std::move(that));
236template<
typename T >
251template<
typename T >
255template<
typename T >
265#if defined(_WIN32) && defined(_MSC_VER)
267 std::hardware_destructive_interference_size
275 static void *
operator new(std::size_t count, std::align_val_t al);
276 static void operator delete(
void *ptr, std::align_val_t al);
278#if defined (_MSC_VER) && defined(_DEBUG)
282 static void *
operator new(
283 std::size_t count, std::align_val_t al, int,
const char *, int)
284 {
return operator new(count, al); }
285 static void operator delete(
286 void *ptr, std::align_val_t al, int,
const char *, int)
287 {
return operator delete(ptr, al); }
298 template<
typename... Args>
308 <T>(std::forward<Args>(args)...);
324 T::operator =(other);
330 T::operator =(std::move(other));
335#define QUANTIZED_TIME(time, rate) (floor(((double)(time) * (rate)) + 0.5) / (rate))
337#define DB_TO_LINEAR(x) (pow(10.0, (x) / 20.0))
338#define LINEAR_TO_DB(x) (20.0 * log10(x))
340#define MAX_AUDIO (1. - 1./(1<<15))
346 static_assert(AtomicUniquePointer::is_always_lock_free);
347 using std::atomic<T*>::atomic;
353 delete this->exchange(p, std::memory_order_release);
356 template<
typename... Args>
void emplace(Args &&... args) {
362 using std::atomic<T*>::fetch_add;
363 using std::atomic<T*>::fetch_sub;
369 const std::uint32_t x = 1u;
370 return static_cast<const unsigned char*
>(
static_cast<const void*
>(&x))[0];
375template <
typename IntType>
378 static_assert(std::is_integral<IntType>::value,
"Integral type required");
380 constexpr auto size =
sizeof(IntType);
385 if constexpr (
size == 1)
387 else if constexpr (
size == 2)
388 return (value >> 8) | (value << 8);
389 else if constexpr (
size == 4)
390 return ((value >> 24) & 0xFF) | ((value >> 8) & 0xFF00) |
391 ((value << 8) & 0xFF0000) | ((value << 24) & 0xFF000000);
392 else if constexpr (
size == 8)
393 return ((value >> 56) & 0xFF) | ((value >> 40) & 0xFF00) |
394 ((value >> 24) & 0xFF0000) | ((value >> 8) & 0xFF000000) |
395 ((value << 8) & 0xFF00000000) | ((value << 24) & 0xFF0000000000) |
396 ((value << 40) & 0xFF000000000000) |
397 ((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