1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
21 #define INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
26 /** This template handles BitmapAccess the RAII way.
28 Please don't use directly, but through the ready-made typedefs
29 ScopedReadAccess and ScopedWriteAccess in classes Bitmap and
34 Bitmap::ScopedReadAccess pReadAccess( aBitmap );
35 pReadAccess->SetPixel()...
38 Bitmap::ScopedWriteAccess pWriteAccess( bCond ? aBitmap2.AcquireWriteAccess() : 0, aBitmap2 );
39 if ( pWriteAccess )...
41 @attention for practical reasons, ScopedBitmapAccess stores a
42 reference to the provided bitmap, thus, make sure that the bitmap
43 specified at construction time lives at least as long as the
46 template < class Access
, class Bitmap
, Access
* (Bitmap::* Acquire
)() > class ScopedBitmapAccess
48 typedef ScopedBitmapAccess
< Access
, Bitmap
, Acquire
> self_type
;
49 typedef bool (self_type::* unspecified_bool_type
)() const;
52 explicit ScopedBitmapAccess( Bitmap
& rBitmap
) :
56 mpAccess
= (mpBitmap
->*Acquire
)();
59 ScopedBitmapAccess( Access
* pAccess
, Bitmap
& rBitmap
) :
65 ScopedBitmapAccess( ) :
72 ScopedBitmapAccess
&operator=(ScopedBitmapAccess
&&other
)
74 mpAccess
=other
.mpAccess
;
75 mpBitmap
=other
.mpBitmap
;
76 other
.mpAccess
= nullptr;
77 other
.mpBitmap
= nullptr;
81 // Disable copy from lvalue.
82 ScopedBitmapAccess(const ScopedBitmapAccess
&) = delete;
83 ScopedBitmapAccess
&operator=(const ScopedBitmapAccess
&) = delete;
88 mpBitmap
->ReleaseAccess( mpAccess
);
95 mpBitmap
->ReleaseAccess( mpAccess
);
100 bool operator!() const { return !mpAccess
; }
101 operator unspecified_bool_type() const
103 return mpAccess
? &self_type::operator! : 0;
106 Access
* get() { return mpAccess
; }
107 const Access
* get() const { return mpAccess
; }
109 Access
* operator->() { return mpAccess
; }
110 const Access
* operator->() const { return mpAccess
; }
112 Access
& operator*() { return *mpAccess
; }
113 const Access
& operator*() const { return *mpAccess
; }
122 #endif // INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */