LCOV - code coverage report
Current view: top level - sw/source/core/doc - swstylemanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 60 78.3 %
Date: 2012-08-25 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 48 118 40.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "swstylemanager.hxx"
      30                 :            : #include <boost/unordered_map.hpp>
      31                 :            : #include <svl/stylepool.hxx>
      32                 :            : #include <doc.hxx>
      33                 :            : #include <charfmt.hxx>
      34                 :            : #include <docary.hxx>
      35                 :            : #include <swtypes.hxx>
      36                 :            : #include <istyleaccess.hxx>
      37                 :            : 
      38                 :            : typedef ::boost::unordered_map< const ::rtl::OUString,
      39                 :            :                          StylePool::SfxItemSet_Pointer_t,
      40                 :            :                          ::rtl::OUStringHash,
      41                 :            :                          ::std::equal_to< ::rtl::OUString > > SwStyleNameCache;
      42                 :            : 
      43                 :         43 : class SwStyleCache
      44                 :            : {
      45                 :            :     SwStyleNameCache mMap;
      46                 :            : public:
      47         [ +  - ]:         43 :     SwStyleCache() {}
      48                 :         75 :     void addStyleName( StylePool::SfxItemSet_Pointer_t pStyle )
      49 [ +  - ][ +  - ]:         75 :         { mMap[ StylePool::nameOf(pStyle) ] = pStyle; }
                 [ +  - ]
      50                 :            :     void addCompletePool( StylePool& rPool );
      51                 :        164 :     StylePool::SfxItemSet_Pointer_t getByName( const rtl::OUString& rName ) { return mMap[rName]; }
      52                 :            : };
      53                 :            : 
      54                 :          0 : void SwStyleCache::addCompletePool( StylePool& rPool )
      55                 :            : {
      56         [ #  # ]:          0 :     IStylePoolIteratorAccess *pIter = rPool.createIterator();
      57         [ #  # ]:          0 :     StylePool::SfxItemSet_Pointer_t pStyle = pIter->getNext();
      58         [ #  # ]:          0 :     while( pStyle.get() )
      59                 :            :     {
      60 [ #  # ][ #  # ]:          0 :         rtl::OUString aName( StylePool::nameOf(pStyle) );
                 [ #  # ]
      61 [ #  # ][ #  # ]:          0 :         mMap[ aName ] = pStyle;
      62 [ #  # ][ #  # ]:          0 :         pStyle = pIter->getNext();
                 [ #  # ]
      63                 :          0 :     }
      64 [ #  # ][ #  # ]:          0 :     delete pIter;
                 [ #  # ]
      65                 :          0 : }
      66                 :            : 
      67                 :            : class SwStyleManager : public IStyleAccess
      68                 :            : {
      69                 :            :     StylePool aAutoCharPool;
      70                 :            :     StylePool aAutoParaPool;
      71                 :            :     SwStyleCache *mpCharCache;
      72                 :            :     SwStyleCache *mpParaCache;
      73                 :            : 
      74                 :            : public:
      75                 :            :     // accept empty item set for ignorable paragraph items.
      76                 :       1549 :     SwStyleManager( SfxItemSet* pIgnorableParagraphItems )
      77                 :            :         : aAutoCharPool(),
      78                 :            :           aAutoParaPool( pIgnorableParagraphItems ),
      79                 :            :           mpCharCache(0),
      80 [ +  - ][ +  - ]:       1549 :           mpParaCache(0)
      81                 :       1549 :     {}
      82                 :            :     virtual ~SwStyleManager();
      83                 :            :     virtual StylePool::SfxItemSet_Pointer_t getAutomaticStyle( const SfxItemSet& rSet,
      84                 :            :                                                                IStyleAccess::SwAutoStyleFamily eFamily );
      85                 :            :     virtual StylePool::SfxItemSet_Pointer_t getByName( const rtl::OUString& rName,
      86                 :            :                                                                IStyleAccess::SwAutoStyleFamily eFamily );
      87                 :            :     virtual void getAllStyles( std::vector<StylePool::SfxItemSet_Pointer_t> &rStyles,
      88                 :            :                                                                IStyleAccess::SwAutoStyleFamily eFamily );
      89                 :            :     virtual StylePool::SfxItemSet_Pointer_t cacheAutomaticStyle( const SfxItemSet& rSet,
      90                 :            :                                                                SwAutoStyleFamily eFamily );
      91                 :            :     virtual void clearCaches();
      92                 :            : };
      93                 :            : 
      94                 :       1549 : IStyleAccess *createStyleManager( SfxItemSet* pIgnorableParagraphItems )
      95                 :            : {
      96         [ +  - ]:       1549 :     return new SwStyleManager( pIgnorableParagraphItems );
      97                 :            : }
      98                 :            : 
      99 [ +  - ][ +  - ]:       1458 : SwStyleManager::~SwStyleManager()
     100                 :            : {
     101 [ -  + ][ #  # ]:       1458 :     delete mpCharCache;
     102 [ -  + ][ #  # ]:       1458 :     delete mpParaCache;
     103         [ -  + ]:       2916 : }
     104                 :            : 
     105                 :         63 : void SwStyleManager::clearCaches()
     106                 :            : {
     107         [ +  + ]:         63 :     delete mpCharCache;
     108                 :         63 :     mpCharCache = 0;
     109         [ +  + ]:         63 :     delete mpParaCache;
     110                 :         63 :     mpParaCache = 0;
     111                 :         63 : }
     112                 :            : 
     113                 :      68234 : StylePool::SfxItemSet_Pointer_t SwStyleManager::getAutomaticStyle( const SfxItemSet& rSet,
     114                 :            :                                                                    IStyleAccess::SwAutoStyleFamily eFamily )
     115                 :            : {
     116         [ +  + ]:      68234 :     StylePool& rAutoPool = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? aAutoCharPool : aAutoParaPool;
     117                 :      68234 :     return rAutoPool.insertItemSet( rSet );
     118                 :            : }
     119                 :            : 
     120                 :         75 : StylePool::SfxItemSet_Pointer_t SwStyleManager::cacheAutomaticStyle( const SfxItemSet& rSet,
     121                 :            :                                                                    IStyleAccess::SwAutoStyleFamily eFamily )
     122                 :            : {
     123         [ +  + ]:         75 :     StylePool& rAutoPool = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? aAutoCharPool : aAutoParaPool;
     124                 :         75 :     StylePool::SfxItemSet_Pointer_t pStyle = rAutoPool.insertItemSet( rSet );
     125                 :            :     SwStyleCache* &rpCache = eFamily == IStyleAccess::AUTO_STYLE_CHAR ?
     126         [ +  + ]:         75 :                              mpCharCache : mpParaCache;
     127         [ +  + ]:         75 :     if( !rpCache )
     128 [ +  - ][ +  - ]:         43 :         rpCache = new SwStyleCache();
     129 [ +  - ][ +  - ]:         75 :     rpCache->addStyleName( pStyle );
                 [ +  - ]
     130                 :         75 :     return pStyle;
     131                 :            : }
     132                 :            : 
     133                 :        164 : StylePool::SfxItemSet_Pointer_t SwStyleManager::getByName( const rtl::OUString& rName,
     134                 :            :                                                            IStyleAccess::SwAutoStyleFamily eFamily )
     135                 :            : {
     136         [ +  + ]:        164 :     StylePool& rAutoPool = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? aAutoCharPool : aAutoParaPool;
     137         [ +  + ]:        164 :     SwStyleCache* &rpCache = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? mpCharCache : mpParaCache;
     138         [ -  + ]:        164 :     if( !rpCache )
     139         [ #  # ]:          0 :         rpCache = new SwStyleCache();
     140                 :        164 :     StylePool::SfxItemSet_Pointer_t pStyle = rpCache->getByName( rName );
     141         [ -  + ]:        164 :     if( !pStyle.get() )
     142                 :            :     {
     143                 :            :         // Ok, ok, it's allowed to ask for uncached styles (from UNO) but it should not be done
     144                 :            :         // during loading a document
     145                 :            :         OSL_FAIL( "Don't ask for uncached styles" );
     146         [ #  # ]:          0 :         rpCache->addCompletePool( rAutoPool );
     147 [ #  # ][ #  # ]:          0 :         pStyle = rpCache->getByName( rName );
                 [ #  # ]
     148                 :            :     }
     149                 :        164 :     return pStyle;
     150                 :            : }
     151                 :            : 
     152                 :         42 : void SwStyleManager::getAllStyles( std::vector<StylePool::SfxItemSet_Pointer_t> &rStyles,
     153                 :            :                                    IStyleAccess::SwAutoStyleFamily eFamily )
     154                 :            : {
     155         [ +  + ]:         42 :     StylePool& rAutoPool = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? aAutoCharPool : aAutoParaPool;
     156                 :            :     // setup <StylePool> iterator, which skips unused styles and ignorable items
     157         [ +  - ]:         42 :     IStylePoolIteratorAccess *pIter = rAutoPool.createIterator( true, true );
     158         [ +  - ]:         42 :     StylePool::SfxItemSet_Pointer_t pStyle = pIter->getNext();
     159         [ +  + ]:         49 :     while( pStyle.get() )
     160                 :            :     {
     161         [ +  - ]:          7 :         rStyles.push_back( pStyle );
     162                 :            : 
     163 [ +  - ][ +  - ]:          7 :         pStyle = pIter->getNext();
                 [ +  - ]
     164                 :            :     }
     165 [ +  - ][ +  - ]:         42 :     delete pIter;
                 [ +  - ]
     166                 :         42 : }
     167                 :            : 
     168                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10