From 7ddd3762bbe27c5922dac6c5aa3b934403491d91 Mon Sep 17 00:00:00 2001 From: walbourn_cp Date: Tue, 24 Dec 2013 12:57:42 -0800 Subject: [PATCH] DirectXTex: added move operators for ScratchImage, Blob --- DirectXTex/DirectXTex.h | 12 ++++++++++-- DirectXTex/DirectXTexImage.cpp | 21 +++++++++++++++++++++ DirectXTex/DirectXTexUtil.cpp | 15 +++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index d50ee41..89e8e79 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -244,9 +244,14 @@ namespace DirectX class ScratchImage { public: - ScratchImage() : _nimages(0), _size(0), _image(0), _memory(0) {} + ScratchImage() + : _nimages(0), _size(0), _image(nullptr), _memory(nullptr) {} + ScratchImage(ScratchImage&& moveFrom) + : _nimages(0), _size(0), _image(nullptr), _memory(nullptr) { *this = std::move(moveFrom); } ~ScratchImage() { Release(); } + ScratchImage& operator= (ScratchImage&& moveFrom); + HRESULT Initialize( _In_ const TexMetadata& mdata ); HRESULT Initialize1D( _In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels ); @@ -291,9 +296,12 @@ namespace DirectX class Blob { public: - Blob() : _buffer(0), _size(0) {} + Blob() : _buffer(nullptr), _size(0) {} + Blob(Blob&& moveFrom) : _buffer(nullptr), _size(0) { *this = std::move(moveFrom); } ~Blob() { Release(); } + Blob& operator= (Blob&& moveFrom); + HRESULT Initialize( _In_ size_t size ); void Release(); diff --git a/DirectXTex/DirectXTexImage.cpp b/DirectXTex/DirectXTexImage.cpp index bec6d62..76e91ca 100644 --- a/DirectXTex/DirectXTexImage.cpp +++ b/DirectXTex/DirectXTexImage.cpp @@ -229,6 +229,27 @@ bool _SetupImageArray( uint8_t *pMemory, size_t pixelSize, // ScratchImage - Bitmap image container //===================================================================================== +ScratchImage& ScratchImage::operator= (ScratchImage&& moveFrom) +{ + if ( this != &moveFrom ) + { + Release(); + + _nimages = moveFrom._nimages; + _size = moveFrom._size; + _metadata = moveFrom._metadata; + _image = moveFrom._image; + _memory = moveFrom._memory; + + moveFrom._nimages = 0; + moveFrom._size = 0; + moveFrom._image = nullptr; + moveFrom._memory = nullptr; + } + return *this; +} + + //------------------------------------------------------------------------------------- // Methods //------------------------------------------------------------------------------------- diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index 2af273e..97e399d 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -915,6 +915,21 @@ size_t TexMetadata::ComputeIndex( size_t mip, size_t item, size_t slice ) const // Blob - Bitmap image container //===================================================================================== +Blob& Blob::operator= (Blob&& moveFrom) +{ + if ( this != &moveFrom ) + { + Release(); + + _buffer = moveFrom._buffer; + _size = moveFrom._size; + + moveFrom._buffer = nullptr; + moveFrom._size = 0; + } + return *this; +} + void Blob::Release() { if ( _buffer )