X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Faudiographer%2Faudiographer%2Ftype_utils.h;h=c16b0f942a0b2c907b000425ea9a3c0098c1c3a5;hb=16ef78ade0faf1cbdbdb2dc6c4430fb4996c0323;hp=84a28f3d071014cfbf9c1a1fba99fe2c6566bc8b;hpb=8da27200d18fe4c471a759dde8e10d85ff29d277;p=ardour.git diff --git a/libs/audiographer/audiographer/type_utils.h b/libs/audiographer/audiographer/type_utils.h index 84a28f3d07..c16b0f942a 100644 --- a/libs/audiographer/audiographer/type_utils.h +++ b/libs/audiographer/audiographer/type_utils.h @@ -1,56 +1,69 @@ #ifndef AUDIOGRAPHER_TYPE_UTILS_H #define AUDIOGRAPHER_TYPE_UTILS_H -#include "types.h" #include #include #include #include +#include + +#include "audiographer/visibility.h" +#include "audiographer/types.h" namespace AudioGrapher { -class TypeUtilsBase +/// Non-template base class for TypeUtils +class LIBAUDIOGRAPHER_API TypeUtilsBase { protected: - + template - static void do_fill(T * buffer, nframes_t frames, const boost::integral_constant&) - { std::uninitialized_fill_n (buffer, frames, T()); } + static void do_zero_fill(T * buffer, samplecnt_t samples, const boost::integral_constant&) + { std::uninitialized_fill_n (buffer, samples, T()); } template - static void do_fill(T * buffer, nframes_t frames, const boost::true_type&) - { memset (buffer, frames * sizeof(T), 0); } - - private: + static void do_zero_fill(T * buffer, samplecnt_t samples, const boost::true_type&) + { memset (buffer, 0, samples * sizeof(T)); } }; -template -class TypeUtils : private TypeUtilsBase +/// Utilities for initializing, copying, moving, etc. data +template +class /*LIBAUDIOGRAPHER_API*/ TypeUtils : private TypeUtilsBase { BOOST_STATIC_ASSERT (boost::has_trivial_destructor::value); - - typedef boost::integral_constant::value || boost::is_signed::value> zero_fillable; public: - inline static void zero_fill (T * buffer, nframes_t frames) - { do_zero_fill(buffer, frames, zero_fillable()); } - - inline static void copy (T* source, T* destination, nframes_t frames) - { std::uninitialized_copy (source, &source[frames], destination); } - - inline static void move (T* source, T* destination, nframes_t frames) + /** Fill buffer with a zero value + * The value used for filling is either 0 or the value of T() + * if T is not a floating point or signed integer type + * \n RT safe + */ + inline static void zero_fill (T * buffer, samplecnt_t samples) + { do_zero_fill(buffer, samples, zero_fillable()); } + + /** Copies \a samples frames of data from \a source to \a destination + * The source and destination may NOT overlap. + * \n RT safe + */ + inline static void copy (T const * source, T * destination, samplecnt_t samples) + { std::uninitialized_copy (source, &source[samples], destination); } + + /** Moves \a samples frames of data from \a source to \a destination + * The source and destination may overlap in any way. + * \n RT safe + */ + inline static void move (T const * source, T * destination, samplecnt_t samples) { if (destination < source) { - std::copy (source, &source[frames], destination); - } else { - std::copy_backward (source, &source[frames], destination); + std::copy (source, &source[samples], destination); + } else if (destination > source) { + std::copy_backward (source, &source[samples], destination + samples); } } - - private: - };