Implement empty constructor for Texture::LockHandle

Useful if lock must be initialized after it was created
While here, deinitialize all fields of an object which was moved-from
This commit is contained in:
Dmitry Marakasov 2014-12-16 23:23:19 +03:00
parent 93a77542d8
commit 1118a9b166
2 changed files with 8 additions and 0 deletions

View File

@ -53,6 +53,7 @@ public:
LockHandle(Texture* texture, const Rect& rect);
public:
LockHandle();
~LockHandle();
LockHandle(LockHandle&& other) noexcept;

View File

@ -28,6 +28,9 @@
namespace SDL2pp {
Texture::LockHandle::LockHandle() : texture_(nullptr) {
}
Texture::LockHandle::LockHandle(Texture* texture, const Rect& rect) : texture_(texture) {
if (SDL_LockTexture(texture_->Get(), rect.Get(), &pixels_, &pitch_) != 0)
throw Exception("SDL_LockTexture failed");
@ -35,6 +38,8 @@ Texture::LockHandle::LockHandle(Texture* texture, const Rect& rect) : texture_(t
Texture::LockHandle::LockHandle(Texture::LockHandle&& other) noexcept : texture_(other.texture_), pixels_(other.pixels_), pitch_(other.pitch_) {
other.texture_ = nullptr;
other.pixels_ = nullptr;
other.pitch_ = 0;
}
Texture::LockHandle& Texture::LockHandle::operator=(Texture::LockHandle&& other) noexcept {
@ -49,6 +54,8 @@ Texture::LockHandle& Texture::LockHandle::operator=(Texture::LockHandle&& other)
pitch_ = other.pitch_;
other.texture_ = nullptr;
other.pixels_ = nullptr;
other.pitch_ = 0;
return *this;
}