- Fix process callbakc handling during export
[ardour.git] / libs / audiographer / audiographer / type_utils.h
1 #ifndef AUDIOGRAPHER_TYPE_UTILS_H
2 #define AUDIOGRAPHER_TYPE_UTILS_H
3
4 #include "types.h"
5 #include <boost/static_assert.hpp>
6 #include <boost/type_traits.hpp>
7 #include <memory>
8 #include <algorithm>
9
10 namespace AudioGrapher
11 {
12
13 class TypeUtilsBase
14 {
15   protected:
16         
17         template<typename T, bool b>
18         static void do_fill(T * buffer, nframes_t frames, const boost::integral_constant<bool, b>&)
19                 { std::uninitialized_fill_n (buffer, frames, T()); }
20
21         template<typename T>
22         static void do_fill(T * buffer, nframes_t frames, const boost::true_type&)
23                 { memset (buffer, frames * sizeof(T), 0); }
24         
25   private:
26 };
27
28 template<typename T>
29 class TypeUtils : private TypeUtilsBase
30 {
31         BOOST_STATIC_ASSERT (boost::has_trivial_destructor<T>::value);
32         
33         typedef boost::integral_constant<bool, 
34                         boost::is_floating_point<T>::value ||
35                         boost::is_signed<T>::value> zero_fillable;
36   public:
37         inline static void zero_fill (T * buffer, nframes_t frames)
38                 { do_zero_fill(buffer, frames, zero_fillable()); }
39         
40         inline static void copy (T* source, T* destination, nframes_t frames)
41                 { std::uninitialized_copy (source, &source[frames], destination); }
42         
43         inline static void move (T* source, T* destination, nframes_t frames)
44         {
45                 if (destination < source) {
46                         std::copy (source, &source[frames], destination);
47                 } else {
48                         std::copy_backward (source, &source[frames], destination);
49                 }
50         }
51         
52   private:
53
54 };
55
56
57 } // namespace
58
59 #endif // AUDIOGRAPHER_TYPE_UTILS_H