LCOV - code coverage report
Current view: top level - unotools/source/misc - atom.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 39 97.4 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43 80 53.8 %

           Branch data     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 <unotools/atom.hxx>
      22                 :            : 
      23                 :            : using namespace utl;
      24                 :            : using namespace ::com::sun::star::uno;
      25                 :            : using namespace ::com::sun::star::util;
      26                 :            : 
      27 [ +  - ][ +  - ]:        472 : AtomProvider::AtomProvider()
      28                 :            : {
      29                 :        472 :     m_nAtoms = 1;
      30                 :        472 : }
      31                 :            : 
      32         [ +  - ]:        472 : AtomProvider::~AtomProvider()
      33                 :            : {
      34                 :        472 : }
      35                 :            : 
      36                 :     121291 : int AtomProvider::getAtom( const ::rtl::OUString& rString, sal_Bool bCreate )
      37                 :            : {
      38         [ +  - ]:     121291 :     ::boost::unordered_map< ::rtl::OUString, int, ::rtl::OUStringHash >::iterator it = m_aAtomMap.find( rString );
      39 [ +  - ][ +  + ]:     121291 :     if( it != m_aAtomMap.end() )
      40         [ +  - ]:      68633 :         return it->second;
      41         [ +  + ]:      52658 :     if( ! bCreate )
      42                 :        456 :         return INVALID_ATOM;
      43         [ +  - ]:      52202 :     m_aAtomMap[ rString ] = m_nAtoms;
      44         [ +  - ]:      52202 :     m_aStringMap[ m_nAtoms ] = rString;
      45                 :      52202 :     m_nAtoms++;
      46                 :     121291 :     return m_nAtoms-1;
      47                 :            : }
      48                 :            : 
      49                 :     139091 : const ::rtl::OUString& AtomProvider::getString( int nAtom ) const
      50                 :            : {
      51 [ +  + ][ +  - ]:     139091 :     static ::rtl::OUString aEmpty;
      52         [ +  - ]:     139091 :     ::boost::unordered_map< int, ::rtl::OUString, ::boost::hash< int > >::const_iterator it = m_aStringMap.find( nAtom );
      53                 :            : 
      54 [ +  - ][ -  + ]:     139091 :     return it == m_aStringMap.end() ? aEmpty : it->second;
                 [ +  - ]
      55                 :            : }
      56                 :            : 
      57                 :            : // -----------------------------------------------------------------------
      58                 :            : 
      59         [ +  - ]:        236 : MultiAtomProvider::MultiAtomProvider()
      60                 :            : {
      61                 :        236 : }
      62                 :            : 
      63                 :        236 : MultiAtomProvider::~MultiAtomProvider()
      64                 :            : {
      65 [ +  - ][ +  - ]:        708 :     for( ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it = m_aAtomLists.begin(); it != m_aAtomLists.end(); ++it )
                 [ +  + ]
      66 [ +  - ][ +  - ]:        472 :         delete it->second;
                 [ +  - ]
      67                 :        236 : }
      68                 :            : 
      69                 :     121291 : int MultiAtomProvider::getAtom( int atomClass, const ::rtl::OUString& rString, sal_Bool bCreate )
      70                 :            : {
      71                 :            :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it =
      72         [ +  - ]:     121291 :           m_aAtomLists.find( atomClass );
      73 [ +  - ][ +  + ]:     121291 :     if( it != m_aAtomLists.end() )
      74 [ +  - ][ +  - ]:     120819 :         return it->second->getAtom( rString, bCreate );
      75                 :            : 
      76         [ +  - ]:        472 :     if( bCreate )
      77                 :            :     {
      78                 :            :         AtomProvider* pNewClass;
      79 [ +  - ][ +  - ]:        472 :         m_aAtomLists[ atomClass ] = pNewClass = new AtomProvider();
                 [ +  - ]
      80         [ +  - ]:        472 :         return pNewClass->getAtom( rString, bCreate );
      81                 :            :     }
      82                 :     121291 :     return INVALID_ATOM;
      83                 :            : }
      84                 :            : 
      85                 :     139091 : const ::rtl::OUString& MultiAtomProvider::getString( int atomClass, int atom ) const
      86                 :            : {
      87                 :            :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::const_iterator it =
      88         [ +  - ]:     139091 :           m_aAtomLists.find( atomClass );
      89 [ +  - ][ +  - ]:     139091 :     if( it != m_aAtomLists.end() )
      90 [ +  - ][ +  - ]:     139091 :         return it->second->getString( atom );
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 :     static ::rtl::OUString aEmpty;
      93                 :     139091 :     return aEmpty;
      94                 :            : }
      95                 :            : 
      96                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10