Ardour  9.0-pre0-427-gd2a3450e2f
type_utils.h
Go to the documentation of this file.
1 #ifndef AUDIOGRAPHER_TYPE_UTILS_H
2 #define AUDIOGRAPHER_TYPE_UTILS_H
3 
4 #include <memory>
5 #include <algorithm>
6 #include <cstring>
7 
9 #include "audiographer/types.h"
10 
11 namespace AudioGrapher
12 {
13 
16 {
17  protected:
18 
19  template<typename T, bool b>
20  static void do_zero_fill(T * buffer, samplecnt_t samples, const std::bool_constant<b>&)
21  { std::uninitialized_fill_n (buffer, samples, T()); }
22 
23  template<typename T>
24  static void do_zero_fill(T * buffer, samplecnt_t samples, const std::true_type&)
25  { memset (buffer, 0, samples * sizeof(T)); }
26 };
27 
29 template<typename T = DefaultSampleType>
30 class /*LIBAUDIOGRAPHER_API*/ TypeUtils : private TypeUtilsBase
31 {
32  static_assert (std::is_trivially_destructible<T>::value);
33 
34  typedef std::bool_constant<std::is_floating_point<T>::value ||
35  std::is_signed<T>::value> zero_fillable;
36  public:
42  inline static void zero_fill (T * buffer, samplecnt_t samples)
43  { do_zero_fill(buffer, samples, zero_fillable()); }
44 
49  inline static void copy (T const * source, T * destination, samplecnt_t samples)
50  { std::uninitialized_copy (source, &source[samples], destination); }
51 
56  inline static void move (T const * source, T * destination, samplecnt_t samples)
57  {
58  if (destination < source) {
59  std::copy (source, &source[samples], destination);
60  } else if (destination > source) {
61  std::copy_backward (source, &source[samples], destination + samples);
62  }
63  }
64 };
65 
66 
67 } // namespace
68 
69 #endif // AUDIOGRAPHER_TYPE_UTILS_H
Non-template base class for TypeUtils.
Definition: type_utils.h:16
static void do_zero_fill(T *buffer, samplecnt_t samples, const std::bool_constant< b > &)
Definition: type_utils.h:20
static void do_zero_fill(T *buffer, samplecnt_t samples, const std::true_type &)
Definition: type_utils.h:24
Utilities for initializing, copying, moving, etc. data.
Definition: type_utils.h:31
static void move(T const *source, T *destination, samplecnt_t samples)
Definition: type_utils.h:56
std::bool_constant< std::is_floating_point< T >::value||std::is_signed< T >::value > zero_fillable
Definition: type_utils.h:32
static void zero_fill(T *buffer, samplecnt_t samples)
Definition: type_utils.h:42
static void copy(T const *source, T *destination, samplecnt_t samples)
Definition: type_utils.h:49
void memset(float *data, const float val, const uint32_t n_samples)