1#ifndef __AUDACITY_MEMORY_X_H__
2#define __AUDACITY_MEMORY_X_H__
25class ArrayOf :
public std::unique_ptr<X[]>
30 template<
typename Integral>
31 explicit ArrayOf(Integral count,
bool initialize =
false)
33 static_assert(std::is_unsigned<Integral>::value,
"Unsigned arguments only");
40 :
std::unique_ptr < X[] >
41 (
std::move((
std::unique_ptr < X[] >&)(that)))
46 std::unique_ptr<X[]>::operator=(std::move(that));
51 std::unique_ptr<X[]>::operator=(std::move(that));
55 template<
typename Integral >
57 bool initialize =
false)
59 static_assert(std::is_unsigned<Integral>::value,
"Unsigned arguments only");
62 std::unique_ptr<X[]>::reset(
safenew X[count]{});
65 std::unique_ptr<X[]>::reset(
safenew X[count]);
84 template<
typename Integral>
89 template<
typename Integral1,
typename Integral2 >
90 ArraysOf(Integral1 N, Integral2 M,
bool initialize =
false)
93 static_assert(std::is_unsigned<Integral1>::value,
"Unsigned arguments only");
94 static_assert(std::is_unsigned<Integral2>::value,
"Unsigned arguments only");
95 for (
size_t ii = 0; ii < N; ++ii)
107 template<
typename Integral >
113 template<
typename Integral >
114 void reinit(Integral count,
bool initialize)
119 template<
typename Integral1,
typename Integral2 >
120 void reinit(Integral1 countN, Integral2 countM,
bool initialize =
false)
122 static_assert(std::is_unsigned<Integral1>::value,
"Unsigned arguments only");
123 static_assert(std::is_unsigned<Integral2>::value,
"Unsigned arguments only");
125 for (
size_t ii = 0; ii < countN; ++ii)
126 (*
this)[ii].reinit(countM, initialize);
138template<
typename T >
144template <
typename Character =
char>
199template<
typename T >
209template<
typename T >
212 using std::unique_ptr< T, RestoreValue<T> >::reset;
226 std::unique_ptr < T, RestoreValue<T> >::operator=(std::move(that));
234template<
typename T >
249template<
typename T >
253template<
typename T >
263#if defined(_WIN32) && defined(_MSC_VER)
265 std::hardware_destructive_interference_size
273 static void *
operator new(std::size_t count, std::align_val_t al);
274 static void operator delete(
void *ptr, std::align_val_t al);
276#if defined (_MSC_VER) && defined(_DEBUG)
280 static void *
operator new(
281 std::size_t count, std::align_val_t al, int,
const char *, int)
282 {
return operator new(count, al); }
283 static void operator delete(
284 void *ptr, std::align_val_t al, int,
const char *, int)
285 {
return operator delete(ptr, al); }
296 template<
typename... Args>
306 <T>(std::forward<Args>(args)...);
322 T::operator =(other);
328 T::operator =(std::move(other));
333#define QUANTIZED_TIME(time, rate) (floor(((double)(time) * (rate)) + 0.5) / (rate))
335#define DB_TO_LINEAR(x) (pow(10.0, (x) / 20.0))
336#define LINEAR_TO_DB(x) (20.0 * log10(x))
338#define MAX_AUDIO (1. - 1./(1<<15))
344 static_assert(AtomicUniquePointer::is_always_lock_free);
345 using std::atomic<T*>::atomic;
351 delete this->exchange(p, std::memory_order_release);
354 template<
typename... Args>
void emplace(Args &&... args) {
360 using std::atomic<T*>::fetch_add;
361 using std::atomic<T*>::fetch_sub;
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
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Finally(F) -> Finally< F >
std::unique_ptr< T, freer > MallocPtr
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