LCOV - code coverage report
Current view: top level - unotools/source/misc - atom.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 35 39 89.7 %
Date: 2014-11-03 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         612 : AtomProvider::AtomProvider()
      27             : {
      28         612 :     m_nAtoms = 1;
      29         612 : }
      30             : 
      31         612 : AtomProvider::~AtomProvider()
      32             : {
      33         612 : }
      34             : 
      35      140496 : int AtomProvider::getAtom( const OUString& rString, bool bCreate )
      36             : {
      37      140496 :     ::boost::unordered_map< OUString, int, OUStringHash >::iterator it = m_aAtomMap.find( rString );
      38      140496 :     if( it != m_aAtomMap.end() )
      39       81132 :         return it->second;
      40       59364 :     if( ! bCreate )
      41           0 :         return INVALID_ATOM;
      42       59364 :     m_aAtomMap[ rString ] = m_nAtoms;
      43       59364 :     m_aStringMap[ m_nAtoms ] = rString;
      44       59364 :     m_nAtoms++;
      45       59364 :     return m_nAtoms-1;
      46             : }
      47             : 
      48      215001 : const OUString& AtomProvider::getString( int nAtom ) const
      49             : {
      50      215001 :     static OUString aEmpty;
      51      215001 :     ::boost::unordered_map< int, OUString, ::boost::hash< int > >::const_iterator it = m_aStringMap.find( nAtom );
      52             : 
      53      215001 :     return it == m_aStringMap.end() ? aEmpty : it->second;
      54             : }
      55             : 
      56         306 : MultiAtomProvider::MultiAtomProvider()
      57             : {
      58         306 : }
      59             : 
      60         612 : MultiAtomProvider::~MultiAtomProvider()
      61             : {
      62         918 :     for( ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it = m_aAtomLists.begin(); it != m_aAtomLists.end(); ++it )
      63         612 :         delete it->second;
      64         306 : }
      65             : 
      66      140496 : int MultiAtomProvider::getAtom( int atomClass, const OUString& rString, bool bCreate )
      67             : {
      68             :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it =
      69      140496 :           m_aAtomLists.find( atomClass );
      70      140496 :     if( it != m_aAtomLists.end() )
      71      139884 :         return it->second->getAtom( rString, bCreate );
      72             : 
      73         612 :     if( bCreate )
      74             :     {
      75             :         AtomProvider* pNewClass;
      76         612 :         m_aAtomLists[ atomClass ] = pNewClass = new AtomProvider();
      77         612 :         return pNewClass->getAtom( rString, bCreate );
      78             :     }
      79           0 :     return INVALID_ATOM;
      80             : }
      81             : 
      82      215001 : const OUString& MultiAtomProvider::getString( int atomClass, int atom ) const
      83             : {
      84             :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::const_iterator it =
      85      215001 :           m_aAtomLists.find( atomClass );
      86      215001 :     if( it != m_aAtomLists.end() )
      87      215001 :         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