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