diff options
author | Mark Page <aptitude@btconnect.com> | 2016-12-01 13:53:30 +0000 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2016-12-02 11:18:16 +0000 |
commit | 677246466c471fbe3522c35be3639afa008a46c0 (patch) | |
tree | ccee5e72c1b274d3c51c0f4d11c369270de11fe4 /include | |
parent | 4d2c210c74567d9af6bededf3fae6bfd62406f14 (diff) |
Extend ScopedBitmapAccess and modify various classes to use it
Exception safety, ensure the Access classes are always destroyed.
Change-Id: I4889358476267853ffbd7fafc24950d84b4e9331
Reviewed-on: https://gerrit.libreoffice.org/31494
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/scopedbitmapaccess.hxx | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/include/vcl/scopedbitmapaccess.hxx b/include/vcl/scopedbitmapaccess.hxx index bb5c8bf61c17..29941368f340 100644 --- a/include/vcl/scopedbitmapaccess.hxx +++ b/include/vcl/scopedbitmapaccess.hxx @@ -51,20 +51,50 @@ template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class Sco public: explicit ScopedBitmapAccess( Bitmap& rBitmap ) : mpAccess( nullptr ), - mrBitmap( rBitmap ) + mpBitmap( &rBitmap ) { - mpAccess = (mrBitmap.*Acquire)(); + mpAccess = (mpBitmap->*Acquire)(); } ScopedBitmapAccess( Access* pAccess, Bitmap& rBitmap ) : mpAccess( pAccess ), - mrBitmap( rBitmap ) + mpBitmap( &rBitmap ) { } + ScopedBitmapAccess( ) : + mpAccess( nullptr ), + mpBitmap( nullptr ) + { + } + + // Move semantics + ScopedBitmapAccess &operator=(ScopedBitmapAccess&&other) + { + mpAccess=other.mpAccess; + mpBitmap=other.mpBitmap; + other.mpAccess = nullptr; + other.mpBitmap = nullptr; + return *this; + } + + // Disable copy from lvalue. + ScopedBitmapAccess(const ScopedBitmapAccess&) = delete; + ScopedBitmapAccess &operator=(const ScopedBitmapAccess&) = delete; + ~ScopedBitmapAccess() { - mrBitmap.ReleaseAccess( mpAccess ); + if (mpAccess) + mpBitmap->ReleaseAccess( mpAccess ); + } + + void reset() + { + if (mpAccess) + { + mpBitmap->ReleaseAccess( mpAccess ); + mpAccess = nullptr; + } } bool operator!() const { return !mpAccess; } @@ -84,7 +114,7 @@ public: private: Access* mpAccess; - Bitmap& mrBitmap; + Bitmap* mpBitmap; }; } |