LCOV - code coverage report
Current view: top level - include/vcl - scopedbitmapaccess.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 14 15 93.3 %
Date: 2014-04-11 Functions: 10 22 45.5 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : namespace vcl
      24             : {
      25             : 
      26             : /** This template handles BitmapAccess the RAII way.
      27             : 
      28             :     Please don't use directly, but through the ready-made typedefs
      29             :     ScopedReadAccess and ScopedWriteAccess in classes Bitmap and
      30             :     AlphaMask.
      31             : 
      32             :     Use as follows:
      33             :     Bitmap aBitmap;
      34             :     Bitmap::ScopedReadAccess pReadAccess( aBitmap );
      35             :     pReadAccess->SetPixel()...
      36             : 
      37             :     Bitmap aBitmap2;
      38             :     Bitmap::ScopedWriteAccess pWriteAccess( bCond ? aBitmap2.AcquireWriteAccess() : 0, aBitmap2 );
      39             :     if ( pWriteAccess )...
      40             : 
      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
      44             :     ScopedBitmapAccess.
      45             :  */
      46             : template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class ScopedBitmapAccess
      47             : {
      48             :     typedef ScopedBitmapAccess< Access, Bitmap, Acquire > self_type;
      49             :     typedef bool (self_type::* unspecified_bool_type)() const;
      50             : 
      51             : public:
      52        6195 :     explicit ScopedBitmapAccess( Bitmap& rBitmap ) :
      53             :         mpAccess( 0 ),
      54        6195 :         mrBitmap( rBitmap )
      55             :     {
      56        6195 :         mpAccess = (mrBitmap.*Acquire)();
      57        6195 :     }
      58             : 
      59           2 :     ScopedBitmapAccess( Access* pAccess, Bitmap& rBitmap ) :
      60             :         mpAccess( pAccess ),
      61           2 :         mrBitmap( rBitmap )
      62             :     {
      63           2 :     }
      64             : 
      65        6197 :     ~ScopedBitmapAccess()
      66             :     {
      67        6197 :         mrBitmap.ReleaseAccess( mpAccess );
      68        6197 :     }
      69             : 
      70           0 :     bool operator!() const { return !mpAccess; }
      71        6168 :     operator unspecified_bool_type() const
      72             :     {
      73        6168 :         return mpAccess ? &self_type::operator! : 0;
      74             :     }
      75             : 
      76          32 :     Access*         get() { return mpAccess; }
      77             :     const Access*   get() const { return mpAccess; }
      78             : 
      79    76241572 :     Access*         operator->() { return mpAccess; }
      80             :     const Access*   operator->() const { return mpAccess; }
      81             : 
      82             :     Access&         operator*() { return *mpAccess; }
      83             :     const Access&   operator*() const { return *mpAccess; }
      84             : 
      85             : private:
      86             :     Access*     mpAccess;
      87             :     Bitmap&     mrBitmap;
      88             : };
      89             : 
      90             : }
      91             : 
      92             : #endif // INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX
      93             : 
      94             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10