LibreOffice Module vcl (master)  1
scopedbitmapaccess.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
21 #define INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
22 
23 #include <sal/types.h>
24 
25 namespace vcl
26 {
27 
48 template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class ScopedBitmapAccess
49 {
50 public:
51  explicit ScopedBitmapAccess( Bitmap& rBitmap ) :
52  mpAccess( nullptr ),
53  mpBitmap( &rBitmap )
54  {
55  mpAccess = (mpBitmap->*Acquire)();
56  }
57 
58  ScopedBitmapAccess( Access* pAccess, Bitmap& rBitmap ) :
59  mpAccess( pAccess ),
60  mpBitmap( &rBitmap )
61  {
62  }
63 
65  mpAccess( nullptr ),
66  mpBitmap( nullptr )
67  {
68  }
69 
70  // Move semantics
72  {
73  mpAccess=other.mpAccess;
74  mpBitmap=other.mpBitmap;
75  other.mpAccess = nullptr;
76  other.mpBitmap = nullptr;
77  return *this;
78  }
79 
80  // Disable copy from lvalue.
81  ScopedBitmapAccess(const ScopedBitmapAccess&) = delete;
83 
84  ~ScopedBitmapAccess() COVERITY_NOEXCEPT_FALSE
85  {
86  if (mpAccess)
88  }
89 
90  void reset()
91  {
92  if (mpAccess)
93  {
95  mpAccess = nullptr;
96  }
97  }
98 
99  bool operator!() const { return !mpAccess; }
100  explicit operator bool() const
101  {
102  return mpAccess;
103  }
104 
105  Access* get() { return mpAccess; }
106  const Access* get() const { return mpAccess; }
107 
108  Access* operator->() { return mpAccess; }
109  const Access* operator->() const { return mpAccess; }
110 
111  Access& operator*() { return *mpAccess; }
112  const Access& operator*() const { return *mpAccess; }
113 
114 private:
117 };
118 
119 }
120 
121 #endif // INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This template handles BitmapAccess the RAII way.
ScopedBitmapAccess(Access *pAccess, Bitmap &rBitmap)
const Access & operator*() const
static void ReleaseAccess(BitmapInfoAccess *pAccess)
ScopedBitmapAccess & operator=(ScopedBitmapAccess &&other)
ScopedBitmapAccess(Bitmap &rBitmap)
const Access * operator->() const
~ScopedBitmapAccess() COVERITY_NOEXCEPT_FALSE