LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/misc - atom.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 39 89.7 %
Date: 2012-12-27 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             : 
      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          40 : AtomProvider::AtomProvider()
      28             : {
      29          40 :     m_nAtoms = 1;
      30          40 : }
      31             : 
      32          40 : AtomProvider::~AtomProvider()
      33             : {
      34          40 : }
      35             : 
      36        7040 : int AtomProvider::getAtom( const ::rtl::OUString& rString, sal_Bool bCreate )
      37             : {
      38        7040 :     ::boost::unordered_map< ::rtl::OUString, int, ::rtl::OUStringHash >::iterator it = m_aAtomMap.find( rString );
      39        7040 :     if( it != m_aAtomMap.end() )
      40        3540 :         return it->second;
      41        3500 :     if( ! bCreate )
      42           0 :         return INVALID_ATOM;
      43        3500 :     m_aAtomMap[ rString ] = m_nAtoms;
      44        3500 :     m_aStringMap[ m_nAtoms ] = rString;
      45        3500 :     m_nAtoms++;
      46        3500 :     return m_nAtoms-1;
      47             : }
      48             : 
      49        8888 : const ::rtl::OUString& AtomProvider::getString( int nAtom ) const
      50             : {
      51        8888 :     static ::rtl::OUString aEmpty;
      52        8888 :     ::boost::unordered_map< int, ::rtl::OUString, ::boost::hash< int > >::const_iterator it = m_aStringMap.find( nAtom );
      53             : 
      54        8888 :     return it == m_aStringMap.end() ? aEmpty : it->second;
      55             : }
      56             : 
      57             : // -----------------------------------------------------------------------
      58             : 
      59          20 : MultiAtomProvider::MultiAtomProvider()
      60             : {
      61          20 : }
      62             : 
      63          40 : MultiAtomProvider::~MultiAtomProvider()
      64             : {
      65          60 :     for( ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::iterator it = m_aAtomLists.begin(); it != m_aAtomLists.end(); ++it )
      66          40 :         delete it->second;
      67          20 : }
      68             : 
      69        7040 : 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        7040 :           m_aAtomLists.find( atomClass );
      73        7040 :     if( it != m_aAtomLists.end() )
      74        7000 :         return it->second->getAtom( rString, bCreate );
      75             : 
      76          40 :     if( bCreate )
      77             :     {
      78             :         AtomProvider* pNewClass;
      79          40 :         m_aAtomLists[ atomClass ] = pNewClass = new AtomProvider();
      80          40 :         return pNewClass->getAtom( rString, bCreate );
      81             :     }
      82           0 :     return INVALID_ATOM;
      83             : }
      84             : 
      85        8888 : const ::rtl::OUString& MultiAtomProvider::getString( int atomClass, int atom ) const
      86             : {
      87             :     ::boost::unordered_map< int, AtomProvider*, ::boost::hash< int > >::const_iterator it =
      88        8888 :           m_aAtomLists.find( atomClass );
      89        8888 :     if( it != m_aAtomLists.end() )
      90        8888 :         return it->second->getString( atom );
      91             : 
      92           0 :     static ::rtl::OUString aEmpty;
      93           0 :     return aEmpty;
      94             : }
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10