Audacity  3.0.3
Classes | Macros | Typedefs | Functions
MemoryX.h File Reference
#include <memory>
#include <cstdlib>
#include <functional>
#include <wx/utils.h>
#include <algorithm>
Include dependency graph for MemoryX.h:

Go to the source code of this file.

Classes

struct  std::__make_unique_result< X >
 
struct  std::__make_unique_result< X[]>
 
class  ArrayOf< X >
 This simplifies arrays of arrays, each array separately allocated with NEW[] But it might be better to use std::Array<ArrayOf<X>, N> for some small constant N Or use just one array when sub-arrays have a common size and are not large. More...
 
class  ArraysOf< X >
 memory.h template class for making an array of arrays. More...
 
class  Optional< X >
 Like a smart pointer, allows for object to not exist (nullptr) More...
 
struct  freer
 
struct  Destroyer< T >
 A deleter class to supply the second template parameter of unique_ptr for classes like wxWindow that should be sent a message called Destroy rather than be deleted directly. More...
 
struct  Final_action< F >
 "finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions. typical usage: auto cleanup = finally([&]{ ... code; ... }); More...
 
struct  RestoreValue< T >
 Structure used by ValueRestorer. More...
 
class  ValueRestorer< T >
 Set a variable temporarily in a scope. More...
 
struct  IteratorRange< Iterator >
 A convenience for use with range-for. More...
 
struct  IteratorRange< Iterator >::identity< T >
 
class  wxArrayStringEx
 

Macros

#define safenew   new
 
#define QUANTIZED_TIME(time, rate)   (floor(((double)(time) * (rate)) + 0.5) / (rate))
 
#define DB_TO_LINEAR(x)   (pow(10.0, (x) / 20.0))
 
#define LINEAR_TO_DB(x)   (20.0 * log10(x))
 
#define MAX_AUDIO   (1. - 1./(1<<15))
 

Typedefs

template<typename T >
using MallocPtr = std::unique_ptr< T, freer >
 
template<typename Character = char>
using MallocString = std::unique_ptr< Character[], freer >
 
template<typename T >
using Destroy_ptr = std::unique_ptr< T, Destroyer< T > >
 a convenience for using Destroyer More...
 
template<typename Value , typename Category = std::forward_iterator_tag>
using ValueIterator = std::iterator< Category, const Value, ptrdiff_t, void, const Value >
 A convenience for defining iterators that return rvalue types, so that they cooperate correctly with stl algorithms and std::reverse_iterator. More...
 

Functions

template<typename X , typename... Args>
__make_unique_result< X >::scalar_case std::make_unique (Args &&... args)
 
template<typename X >
__make_unique_result< X >::array_case std::make_unique (size_t count)
 
template<typename F >
Final_action< F > finally (F f)
 Function template with type deduction lets you construct Final_action without typing any angle brackets. More...
 
template<typename T >
ValueRestorer< T > valueRestorer (T &var)
 inline functions provide convenient parameter type deduction More...
 
template<typename T >
ValueRestorer< T > valueRestorer (T &var, const T &newValue)
 
template<typename Iterator >
IteratorRange< Iterator > make_iterator_range (const Iterator &i1, const Iterator &i2)
 
template<typename Container >
IteratorRange< typename Container::iterator > make_iterator_range (Container &container)
 
template<typename Container >
IteratorRange< typename Container::const_iterator > make_iterator_range (const Container &container)
 
template<typename Container , typename Iterator , typename Function >
Container transform_range (Iterator first, Iterator last, Function &&fn)
 
template<typename OutContainer , typename InContainer , typename Function >
OutContainer transform_container (InContainer &inContainer, Function &&fn)
 

Macro Definition Documentation

◆ DB_TO_LINEAR

#define DB_TO_LINEAR (   x)    (pow(10.0, (x) / 20.0))

Definition at line 720 of file MemoryX.h.

◆ LINEAR_TO_DB

#define LINEAR_TO_DB (   x)    (20.0 * log10(x))

Definition at line 721 of file MemoryX.h.

◆ MAX_AUDIO

#define MAX_AUDIO   (1. - 1./(1<<15))

Definition at line 723 of file MemoryX.h.

◆ QUANTIZED_TIME

#define QUANTIZED_TIME (   time,
  rate 
)    (floor(((double)(time) * (rate)) + 0.5) / (rate))

Definition at line 718 of file MemoryX.h.

◆ safenew

#define safenew   new

Definition at line 8 of file MemoryX.h.

Typedef Documentation

◆ Destroy_ptr

template<typename T >
using Destroy_ptr = std::unique_ptr<T, Destroyer<T> >

a convenience for using Destroyer

Definition at line 365 of file MemoryX.h.

◆ MallocPtr

template<typename T >
using MallocPtr = std::unique_ptr< T, freer >

A useful alias for holding the result of malloc

Definition at line 343 of file MemoryX.h.

◆ MallocString

template<typename Character = char>
using MallocString = std::unique_ptr< Character[], freer >

A useful alias for holding the result of strup and similar

Definition at line 349 of file MemoryX.h.

◆ ValueIterator

template<typename Value , typename Category = std::forward_iterator_tag>
using ValueIterator = std::iterator< Category, const Value, ptrdiff_t, void, const Value >

A convenience for defining iterators that return rvalue types, so that they cooperate correctly with stl algorithms and std::reverse_iterator.

Definition at line 442 of file MemoryX.h.

Function Documentation

◆ finally()

template<typename F >
Final_action<F> finally ( f)

Function template with type deduction lets you construct Final_action without typing any angle brackets.

Definition at line 385 of file MemoryX.h.

386 {
387  return Final_action<F>(f);
388 }

◆ make_iterator_range() [1/3]

template<typename Container >
IteratorRange< typename Container::const_iterator > make_iterator_range ( const Container &  container)

Definition at line 639 of file MemoryX.h.

640 {
641  return { container.begin(), container.end() };
642 }

◆ make_iterator_range() [2/3]

template<typename Iterator >
IteratorRange< Iterator > make_iterator_range ( const Iterator &  i1,
const Iterator &  i2 
)

◆ make_iterator_range() [3/3]

template<typename Container >
IteratorRange< typename Container::iterator > make_iterator_range ( Container &  container)

Definition at line 632 of file MemoryX.h.

633 {
634  return { container.begin(), container.end() };
635 }

◆ make_unique() [1/2]

template<typename X , typename... Args>
__make_unique_result<X>::scalar_case std::make_unique ( Args &&...  args)
inline

Definition at line 51 of file MemoryX.h.

52  {
53  return typename __make_unique_result<X>::scalar_case
54  { safenew X(forward<Args>(args)...) };
55  }

References std::make_unique(), and safenew.

Referenced by std::make_unique().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_unique() [2/2]

template<typename X >
__make_unique_result<X>::array_case std::make_unique ( size_t  count)
inline

Definition at line 63 of file MemoryX.h.

64  {
65  return typename __make_unique_result<X>::array_case
66  { safenew typename __make_unique_result<X>::element[count] };
67  }

References std::make_unique(), and safenew.

Here is the call graph for this function:

◆ transform_container()

template<typename OutContainer , typename InContainer , typename Function >
OutContainer transform_container ( InContainer &  inContainer,
Function &&  fn 
)

Definition at line 654 of file MemoryX.h.

655 {
656  return transform_range<OutContainer>(
657  inContainer.begin(), inContainer.end(), fn );
658 }

References fn.

◆ transform_range()

template<typename Container , typename Iterator , typename Function >
Container transform_range ( Iterator  first,
Iterator  last,
Function &&  fn 
)

Definition at line 646 of file MemoryX.h.

647 {
648  Container result;
649  std::transform( first, last, std::back_inserter( result ), fn );
650  return result;
651 }

References fn.

◆ valueRestorer() [1/2]

template<typename T >
ValueRestorer< T > valueRestorer ( T &  var)

◆ valueRestorer() [2/2]

template<typename T >
ValueRestorer< T > valueRestorer ( T &  var,
const T &  newValue 
)

Definition at line 434 of file MemoryX.h.

435 { return ValueRestorer< T >{ var, newValue }; }
fn
static const auto fn
Definition: WaveformView.cpp:1102
Final_action
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
Definition: MemoryX.h:376
ValueRestorer
Set a variable temporarily in a scope.
Definition: MemoryX.h:408
safenew
#define safenew
Definition: MemoryX.h:8