LCOV - code coverage report
Current view: top level - sd/source/ui/tools - IconCache.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 27 27 100.0 %
Date: 2014-04-11 Functions: 8 8 100.0 %
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             : 
      21             : #include "tools/IconCache.hxx"
      22             : 
      23             : #include "sdresid.hxx"
      24             : #include <boost/unordered_map.hpp>
      25             : #include <osl/doublecheckedlocking.h>
      26             : #include <osl/getglobalmutex.hxx>
      27             : 
      28             : namespace sd {
      29             : 
      30             : //===== IconCache::Implementation =============================================
      31             : 
      32          16 : class IconCache::Implementation
      33             : {
      34             : private:
      35             :     friend class IconCache;
      36             : 
      37             :     /** This pointer holds a valid reference from first time that
      38             :         IconCache::Instance() is called to the end of the sd module when the
      39             :         cache is destroyed from SdGlobalResourceContainer.
      40             :     */
      41             :     static IconCache* mpInstance;
      42             : 
      43             :     typedef ::boost::unordered_map<sal_uInt16,Image> ImageContainer;
      44             :     ImageContainer maContainer;
      45             : 
      46             :     Image GetIcon (sal_uInt16 nResourceId);
      47             : };
      48             : 
      49             : IconCache* IconCache::Implementation::mpInstance = NULL;
      50             : 
      51             : 
      52             : 
      53         642 : Image IconCache::Implementation::GetIcon (sal_uInt16 nResourceId)
      54             : {
      55         642 :     Image aResult;
      56         642 :     ImageContainer::iterator iImage;
      57         642 :     iImage = maContainer.find (nResourceId);
      58         642 :     if (iImage == maContainer.end())
      59             :     {
      60          16 :         aResult = Image(BitmapEx(SdResId(nResourceId)));
      61          16 :         maContainer[nResourceId] = aResult;
      62             :     }
      63             :     else
      64         626 :         aResult = iImage->second;
      65         642 :     return aResult;
      66             : }
      67             : 
      68             : 
      69             : 
      70             : 
      71             : //===== IconCache =============================================================
      72             : 
      73             : //static
      74         642 : IconCache& IconCache::Instance (void)
      75             : {
      76         642 :     if (Implementation::mpInstance == NULL)
      77             :     {
      78             :         ::osl::GetGlobalMutex aMutexFunctor;
      79           8 :         ::osl::MutexGuard aGuard (aMutexFunctor());
      80           8 :         if (Implementation::mpInstance == NULL)
      81             :         {
      82           8 :             IconCache* pCache = new IconCache ();
      83           8 :             SdGlobalResourceContainer::Instance().AddResource (
      84          16 :                 ::std::auto_ptr<SdGlobalResource>(pCache));
      85             :             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
      86           8 :             Implementation::mpInstance = pCache;
      87           8 :         }
      88             :     }
      89             :     else
      90             :     {
      91             :         OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
      92             :     }
      93             : 
      94             :     DBG_ASSERT(Implementation::mpInstance!=NULL,
      95             :         "IconCache::Instance(): instance is NULL");
      96         642 :     return *Implementation::mpInstance;
      97             : }
      98             : 
      99             : 
     100             : 
     101             : 
     102         642 : Image IconCache::GetIcon (sal_uInt16 nResourceId)
     103             : {
     104         642 :     return mpImpl->GetIcon (nResourceId);
     105             : }
     106             : 
     107             : 
     108             : 
     109             : 
     110           8 : IconCache::IconCache (void)
     111           8 :     : mpImpl (new Implementation())
     112             : {
     113           8 : }
     114             : 
     115             : 
     116             : 
     117             : 
     118          16 : IconCache::~IconCache (void)
     119             : {
     120             :     // empty
     121          16 : }
     122             : 
     123             : } // end of namespace sd
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10