1 #ifndef AUDIOGRAPHER_TYPE_UTILS_H
2 #define AUDIOGRAPHER_TYPE_UTILS_H
5 #include <boost/static_assert.hpp>
6 #include <boost/type_traits.hpp>
10 namespace AudioGrapher
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()); }
22 static void do_fill(T * buffer, nframes_t frames, const boost::true_type&)
23 { memset (buffer, frames * sizeof(T), 0); }
29 class TypeUtils : private TypeUtilsBase
31 BOOST_STATIC_ASSERT (boost::has_trivial_destructor<T>::value);
33 typedef boost::integral_constant<bool,
34 boost::is_floating_point<T>::value ||
35 boost::is_signed<T>::value> zero_fillable;
37 inline static void zero_fill (T * buffer, nframes_t frames)
38 { do_zero_fill(buffer, frames, zero_fillable()); }
40 inline static void copy (T* source, T* destination, nframes_t frames)
41 { std::uninitialized_copy (source, &source[frames], destination); }
43 inline static void move (T* source, T* destination, nframes_t frames)
45 if (destination < source) {
46 std::copy (source, &source[frames], destination);
48 std::copy_backward (source, &source[frames], destination);
59 #endif // AUDIOGRAPHER_TYPE_UTILS_H