diff --git a/include/SFML/Audio/SoundRecorder.hpp b/include/SFML/Audio/SoundRecorder.hpp index b6748ac3a..e6851ac8b 100644 --- a/include/SFML/Audio/SoundRecorder.hpp +++ b/include/SFML/Audio/SoundRecorder.hpp @@ -47,7 +47,7 @@ class SFML_AUDIO_API SoundRecorder : AlResource public: //////////////////////////////////////////////////////////// - /// \brief destructor + /// \brief Destructor /// //////////////////////////////////////////////////////////// virtual ~SoundRecorder(); diff --git a/include/SFML/Audio/SoundSource.hpp b/include/SFML/Audio/SoundSource.hpp index c03621d8b..ad997fa84 100644 --- a/include/SFML/Audio/SoundSource.hpp +++ b/include/SFML/Audio/SoundSource.hpp @@ -62,6 +62,14 @@ public: //////////////////////////////////////////////////////////// SoundSource(const SoundSource& copy); + //////////////////////////////////////////////////////////// + /// \brief Move constructor + /// + /// \param other Instance to move + /// + //////////////////////////////////////////////////////////// + SoundSource(SoundSource&& other) noexcept; + //////////////////////////////////////////////////////////// /// \brief Destructor /// @@ -225,7 +233,7 @@ public: float getAttenuation() const; //////////////////////////////////////////////////////////// - /// \brief Overload of assignment operator + /// \brief Overload of copy assignment operator /// /// \param right Instance to assign /// @@ -234,6 +242,16 @@ public: //////////////////////////////////////////////////////////// SoundSource& operator =(const SoundSource& right); + //////////////////////////////////////////////////////////// + /// \brief Overload of move assignment operator + /// + /// \param right Instance to assign + /// + /// \return Reference to self + /// + //////////////////////////////////////////////////////////// + SoundSource& operator =(SoundSource&& right) noexcept; + //////////////////////////////////////////////////////////// /// \brief Start or resume playing the sound source /// diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 0391e36e2..4ab8d9c3b 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -54,6 +54,7 @@ namespace sf { //////////////////////////////////////////////////////////// SoundRecorder::SoundRecorder() : +AlResource (), m_thread (), m_sampleRate (0), m_processingInterval(milliseconds(100)), diff --git a/src/SFML/Audio/SoundSource.cpp b/src/SFML/Audio/SoundSource.cpp index b8283b106..cb0879bb5 100644 --- a/src/SFML/Audio/SoundSource.cpp +++ b/src/SFML/Audio/SoundSource.cpp @@ -27,6 +27,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #if defined(__APPLE__) #if defined(__clang__) @@ -39,7 +40,8 @@ namespace sf { //////////////////////////////////////////////////////////// -SoundSource::SoundSource() +SoundSource::SoundSource() : +AlResource() { alCheck(alGenSources(1, &m_source)); alCheck(alSourcei(m_source, AL_BUFFER, 0)); @@ -47,7 +49,8 @@ SoundSource::SoundSource() //////////////////////////////////////////////////////////// -SoundSource::SoundSource(const SoundSource& copy) +SoundSource::SoundSource(const SoundSource& copy) : +AlResource(copy) { alCheck(alGenSources(1, &m_source)); alCheck(alSourcei(m_source, AL_BUFFER, 0)); @@ -61,11 +64,19 @@ SoundSource::SoundSource(const SoundSource& copy) } +//////////////////////////////////////////////////////////// +SoundSource::SoundSource(SoundSource&& other) noexcept : +AlResource(std::move(other)), +m_source(std::exchange(other.m_source, 0u /* null source */)) +{ +} + + //////////////////////////////////////////////////////////// SoundSource::~SoundSource() { alCheck(alSourcei(m_source, AL_BUFFER, 0)); - alCheck(alDeleteSources(1, &m_source)); + alCheck(alDeleteSources(1, &m_source)); // Note: deleting a null source is fine } @@ -174,6 +185,11 @@ float SoundSource::getAttenuation() const //////////////////////////////////////////////////////////// SoundSource& SoundSource::operator =(const SoundSource& right) { + if (&right == this) + return *this; + + AlResource::operator=(right); + // Leave m_source untouched -- it's not necessary to destroy and // recreate the OpenAL sound source, hence no copy-and-swap idiom @@ -189,6 +205,18 @@ SoundSource& SoundSource::operator =(const SoundSource& right) } +//////////////////////////////////////////////////////////// +SoundSource& SoundSource::operator =(SoundSource&& right) noexcept +{ + if (&right == this) + return *this; + + AlResource::operator=(std::move(right)); + + m_source = std::exchange(right.m_source, 0u /* null source */); + return *this; +} + //////////////////////////////////////////////////////////// SoundSource::Status SoundSource::getStatus() const {