LCOV - code coverage report
Current view: top level - unotools/source/misc - atom.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 35 39 89.7 %
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             : #include <unotools/atom.hxx>
      21             : 
      22             : using namespace utl;
      23             : using namespace ::com::sun::star::uno;
      24             : using namespace ::com::sun::star::util;
      25             : 
      26         274 : AtomProvider::AtomProvider()
      27             : {
      28         274 :     m_nAtoms = 1;
      29         274 : }
      30             : 
      31         274 : AtomProvider::~AtomProvider()
      32             : {
      33         274 : }
      34             : 
      35       88059 : int AtomProvider::getAtom( const OUString& rString, bool bCreate )
      36             : {
      37       88059 :     ::boost::unordered_map< OUString, int, OUStringHash >::iterator it = m_aAtomMap.find( rString );
      38       88059 :     if( it != m_aAtomMap.end() )
      39       52028 :         return it->second;
      40       36031 :     if( ! bCreate )
      41           0 :         return INVALID_ATOM;
      42       36031 :     m_aAtomMap[ rString ] = m_nAtoms;
      43       36031 :     m_aStringMap[ m_nAtoms ] = rString;
      44       36031 :     m_nAtoms++;
      45       36031 :     return m_nAtoms-1;
      46             : }
      47             : 
      48      142650 : const OUString& AtomProvider::getString( int nAtom ) const
      49             : {
      50      142650 :     static OUString aEmpty;
      51      142650 :     ::boost::unordered_map< int, OUString, ::boost::hash< int > >::const_iterator it = m_aStringMap.find( nAtom );
      52             : 
      53      142650 :     return it == m_aStringMap.end() ? aEmpty : it->second;
      54             : }
      55             : 
      56         137 : MultiAtomProvider::MultiAtomProvider()
      57             : {
      58         137 : }
      59             : 
      60         274 : MultiAtomProvider::~MultiAtomProvider()
      61             : {
      62         411 :     for( ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it = m_aAtomLists.begin(); it != m_aAtomLists.end(); ++it )
      63         274 :         delete it->second;
      64         137 : }
      65             : 
      66       88059 : int MultiAtomProvider::getAtom( int atomClass, const OUString& rString, bool bCreate )
      67             : {
      68             :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it =
      69       88059 :           m_aAtomLists.find( atomClass );
      70       88059 :     if( it != m_aAtomLists.end() )
      71       87785 :         return it->second->getAtom( rString, bCreate );
      72             : 
      73         274 :     if( bCreate )
      74             :     {
      75             :         AtomProvider* pNewClass;
      76         274 :         m_aAtomLists[ atomClass ] = pNewClass = new AtomProvider();
      77         274 :         return pNewClass->getAtom( rString, bCreate );
      78             :     }
      79           0 :     return INVALID_ATOM;
      80             : }
      81             : 
      82      142650 : const OUString& MultiAtomProvider::getString( int atomClass, int atom ) const
      83             : {
      84             :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::const_iterator it =
      85      142650 :           m_aAtomLists.find( atomClass );
      86      142650 :     if( it != m_aAtomLists.end() )
      87      142650 :         return it->second->getString( atom );
      88             : 
      89           0 :     static OUString aEmpty;
      90           0 :     return aEmpty;
      91             : }
      92             : 
      93             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10