From a893ee61bbb28ee8d2f3002e31b0fe2c57470924 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 17 May 2016 14:59:44 -1000 Subject: [PATCH] Move semantics for IntrusiveAudioGroupData --- include/amuse/AudioGroupData.hpp | 7 +++++++ lib/AudioGroupData.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/amuse/AudioGroupData.hpp b/include/amuse/AudioGroupData.hpp index 1c93a8f..acecb4d 100644 --- a/include/amuse/AudioGroupData.hpp +++ b/include/amuse/AudioGroupData.hpp @@ -30,9 +30,16 @@ public: */ class IntrusiveAudioGroupData : public AudioGroupData { + bool m_owns = true; public: using AudioGroupData::AudioGroupData; ~IntrusiveAudioGroupData(); + + IntrusiveAudioGroupData(const IntrusiveAudioGroupData&)=delete; + IntrusiveAudioGroupData& operator=(const IntrusiveAudioGroupData&)=delete; + + IntrusiveAudioGroupData(IntrusiveAudioGroupData&& other); + IntrusiveAudioGroupData& operator=(IntrusiveAudioGroupData&& other); }; } diff --git a/lib/AudioGroupData.cpp b/lib/AudioGroupData.cpp index eff86f4..92d245d 100644 --- a/lib/AudioGroupData.cpp +++ b/lib/AudioGroupData.cpp @@ -5,10 +5,33 @@ namespace amuse IntrusiveAudioGroupData::~IntrusiveAudioGroupData() { - delete m_pool; - delete m_proj; - delete m_sdir; - delete m_samp; + if (m_owns) + { + delete m_pool; + delete m_proj; + delete m_sdir; + delete m_samp; + } +} + +IntrusiveAudioGroupData::IntrusiveAudioGroupData(IntrusiveAudioGroupData&& other) +: AudioGroupData(other.m_proj, other.m_pool, other.m_sdir, other.m_samp) +{ + m_owns = other.m_owns; + other.m_owns = false; +} + +IntrusiveAudioGroupData& IntrusiveAudioGroupData::operator=(IntrusiveAudioGroupData&& other) +{ + m_owns = other.m_owns; + other.m_owns = false; + + m_proj = other.m_proj; + m_pool = other.m_pool; + m_sdir = other.m_sdir; + m_samp = other.m_samp; + + return *this; } }