Ardour  8.7-15-gadf511264b
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 <boost/static_assert.hpp>
5 #include <boost/type_traits.hpp>
6 #include <memory>
7 #include <algorithm>
8 #include <cstring>
9 
11 #include "audiographer/types.h"
12 
13 namespace AudioGrapher
14 {
15 
18 {
19  protected:
20 
21  template<typename T, bool b>
22  static void do_zero_fill(T * buffer, samplecnt_t samples, const boost::integral_constant<bool, b>&)
23  { std::uninitialized_fill_n (buffer, samples, T()); }
24 
25  template<typename T>
26  static void do_zero_fill(T * buffer, samplecnt_t samples, const boost::true_type&)
27  { memset (buffer, 0, samples * sizeof(T)); }
28 };
29 
31 template<typename T = DefaultSampleType>
32 class /*LIBAUDIOGRAPHER_API*/ TypeUtils : private TypeUtilsBase
33 {
34  BOOST_STATIC_ASSERT (boost::has_trivial_destructor<T>::value);
35 
36  typedef boost::integral_constant<bool,
37  boost::is_floating_point<T>::value ||
38  boost::is_signed<T>::value> zero_fillable;
39  public:
45  inline static void zero_fill (T * buffer, samplecnt_t samples)
46  { do_zero_fill(buffer, samples, zero_fillable()); }
47 
52  inline static void copy (T const * source, T * destination, samplecnt_t samples)
53  { std::uninitialized_copy (source, &source[samples], destination); }
54 
59  inline static void move (T const * source, T * destination, samplecnt_t samples)
60  {
61  if (destination < source) {
62  std::copy (source, &source[samples], destination);
63  } else if (destination > source) {
64  std::copy_backward (source, &source[samples], destination + samples);
65  }
66  }
67 };
68 
69 
70 } // namespace
71 
72 #endif // AUDIOGRAPHER_TYPE_UTILS_H
Non-template base class for TypeUtils.
Definition: type_utils.h:18
static void do_zero_fill(T *buffer, samplecnt_t samples, const boost::integral_constant< bool, b > &)
Definition: type_utils.h:22
static void do_zero_fill(T *buffer, samplecnt_t samples, const boost::true_type &)
Definition: type_utils.h:26
Utilities for initializing, copying, moving, etc. data.
Definition: type_utils.h:33
static void move(T const *source, T *destination, samplecnt_t samples)
Definition: type_utils.h:59
BOOST_STATIC_ASSERT(boost::has_trivial_destructor< T >::value)
boost::integral_constant< bool, boost::is_floating_point< T >::value||boost::is_signed< T >::value > zero_fillable
Definition: type_utils.h:38
static void zero_fill(T *buffer, samplecnt_t samples)
Definition: type_utils.h:45
static void copy(T const *source, T *destination, samplecnt_t samples)
Definition: type_utils.h:52
void memset(float *data, const float val, const uint32_t n_samples)