Browse Source

Audio: make Buffer and Source nothrow movable.

The reason it wasn't done is likely just neglect, that the code wasn't
updated since it was made originally, before I knew what noexcept is
useful for.
pull/680/head
Vladimír Vondruš 11 months ago
parent
commit
e149093007
  1. 8
      src/Magnum/Audio/Buffer.h
  2. 8
      src/Magnum/Audio/Source.h
  3. 29
      src/Magnum/Audio/Test/BufferALTest.cpp
  4. 29
      src/Magnum/Audio/Test/SourceALTest.cpp

8
src/Magnum/Audio/Buffer.h

@ -72,13 +72,13 @@ class MAGNUM_AUDIO_EXPORT Buffer {
Buffer(const Buffer&) = delete;
/** @brief Move constructor */
Buffer(Buffer&& other);
Buffer(Buffer&& other) noexcept;
/** @brief Copying is not allowed */
Buffer& operator=(const Buffer&) = delete;
/** @brief Move assignment */
Buffer& operator=(Buffer&& other);
Buffer& operator=(Buffer&& other) noexcept;
/** @brief OpenAL buffer ID */
ALuint id() const { return _id; }
@ -228,11 +228,11 @@ class MAGNUM_AUDIO_EXPORT Buffer {
ALuint _id;
};
inline Buffer::Buffer(Buffer&& other): _id(other._id) {
inline Buffer::Buffer(Buffer&& other) noexcept: _id(other._id) {
other._id = 0;
}
inline Buffer& Buffer::operator=(Buffer&& other) {
inline Buffer& Buffer::operator=(Buffer&& other) noexcept {
using Utility::swap;
swap(_id, other._id);
return *this;

8
src/Magnum/Audio/Source.h

@ -78,13 +78,13 @@ class MAGNUM_AUDIO_EXPORT Source {
Source(const Source&) = delete;
/** @brief Move constructor */
Source(Source&& other);
Source(Source&& other) noexcept;
/** @brief Copying is not allowed */
Source& operator=(const Source&) = delete;
/** @brief Move assignment */
Source& operator=(Source&& other);
Source& operator=(Source&& other) noexcept;
/** @brief OpenAL source ID */
ALuint id() const { return _id; }
@ -776,11 +776,11 @@ MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Source::State value);
/** @debugoperatorclassenum{Source,Source::Type} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Source::Type value);
inline Source::Source(Source&& other): _id(other._id) {
inline Source::Source(Source&& other) noexcept: _id(other._id) {
other._id = 0;
}
inline Source& Source::operator=(Source&& other) {
inline Source& Source::operator=(Source&& other) noexcept {
using Utility::swap;
swap(_id, other._id);
return *this;

29
src/Magnum/Audio/Test/BufferALTest.cpp

@ -41,6 +41,8 @@ struct BufferALTest: TestSuite::Tester {
explicit BufferALTest();
void construct();
void constructCopy();
void constructMove();
void properties();
@ -58,6 +60,8 @@ BufferALTest::BufferALTest():
_context{arguments().first(), arguments().second()}
{
addTests({&BufferALTest::construct,
&BufferALTest::constructCopy,
&BufferALTest::constructMove,
&BufferALTest::properties,
@ -73,6 +77,31 @@ void BufferALTest::construct() {
CORRADE_VERIFY(buf.id() != 0);
}
void BufferALTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<Buffer>{});
CORRADE_VERIFY(!std::is_copy_assignable<Buffer>{});
}
void BufferALTest::constructMove() {
Buffer a;
const ALuint id = a.id();
CORRADE_VERIFY(a.id() != 0);
Buffer b{Utility::move(a)};
CORRADE_COMPARE(a.id(), 0);
CORRADE_COMPARE(b.id(), id);
Buffer c;
const ALuint cId = c.id();
c = Utility::move(b);
CORRADE_VERIFY(cId != 0);
CORRADE_COMPARE(b.id(), cId);
CORRADE_COMPARE(c.id(), id);
CORRADE_VERIFY(std::is_nothrow_move_constructible<Buffer>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<Buffer>::value);
}
void BufferALTest::properties() {
Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };

29
src/Magnum/Audio/Test/SourceALTest.cpp

@ -38,6 +38,8 @@ struct SourceALTest: TestSuite::Tester {
explicit SourceALTest();
void construct();
void constructCopy();
void constructMove();
void position();
void direction();
@ -60,6 +62,8 @@ SourceALTest::SourceALTest():
_context{arguments().first(), arguments().second()}
{
addTests({&SourceALTest::construct,
&SourceALTest::constructCopy,
&SourceALTest::constructMove,
&SourceALTest::position,
&SourceALTest::direction,
@ -80,6 +84,31 @@ void SourceALTest::construct() {
CORRADE_VERIFY(source.id() != 0);
}
void SourceALTest::constructCopy() {
CORRADE_VERIFY(!std::is_copy_constructible<Source>{});
CORRADE_VERIFY(!std::is_copy_assignable<Source>{});
}
void SourceALTest::constructMove() {
Source a;
const ALuint id = a.id();
CORRADE_VERIFY(a.id() != 0);
Source b{Utility::move(a)};
CORRADE_COMPARE(a.id(), 0);
CORRADE_COMPARE(b.id(), id);
Source c;
const ALuint cId = c.id();
c = Utility::move(b);
CORRADE_VERIFY(cId != 0);
CORRADE_COMPARE(b.id(), cId);
CORRADE_COMPARE(c.id(), id);
CORRADE_VERIFY(std::is_nothrow_move_constructible<Source>::value);
CORRADE_VERIFY(std::is_nothrow_move_assignable<Source>::value);
}
void SourceALTest::position() {
Source source;
constexpr Vector3 pos{3.0f, 5.0f, 6.0f};

Loading…
Cancel
Save