From 5eeaf5a2b57dac9055b99f1a07913eacc63ebfe1 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 26 Dec 2016 19:26:35 +0000 Subject: [PATCH] Added move semantics to AudioBuffer --- .../buffers/juce_AudioSampleBuffer.h | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h index bc3638282f..0d17f25cfb 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h @@ -190,6 +190,39 @@ public: */ ~AudioBuffer() noexcept {} + #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS + /** Move constructor */ + AudioBuffer (AudioBuffer&& other) noexcept + : numChannels (other.numChannels), + size (other.size), + allocatedBytes (other.allocatedBytes), + channels (other.channels), + allocatedData (static_cast&&> (other.allocatedData)), + isClear (other.isClear) + { + memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace)); + other.numChannels = 0; + other.size = 0; + other.allocatedBytes = 0; + } + + /** Move assignment */ + AudioBuffer& operator= (AudioBuffer&& other) noexcept + { + numChannels = other.numChannels; + size = other.size; + allocatedBytes = other.allocatedBytes; + channels = other.channels; + allocatedData = static_cast&&> (other.allocatedData); + isClear = other.isClear; + memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace)); + other.numChannels = 0; + other.size = 0; + other.allocatedBytes = 0; + return *this; + } + #endif + //============================================================================== /** Returns the number of channels of audio data that this buffer contains. @see getSampleData