LCOV - code coverage report
Current view: top level - xmloff/source/core - attrlist.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 97 106 91.5 %
Date: 2015-06-13 12:38:46 Functions: 29 31 93.5 %
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 <string.h>
      22             : #include <vector>
      23             : #include <osl/mutex.hxx>
      24             : #include <osl/diagnose.h>
      25             : #include <xmloff/xmltoken.hxx>
      26             : #include <comphelper/servicehelper.hxx>
      27             : 
      28             : #include <xmloff/attrlist.hxx>
      29             : 
      30             : 
      31             : using namespace ::osl;
      32             : using namespace ::com::sun::star;
      33             : using namespace ::xmloff::token;
      34             : 
      35      754727 : struct SvXMLTagAttribute_Impl
      36             : {
      37      363793 :     SvXMLTagAttribute_Impl( const OUString &rName,
      38             :                          const OUString &rValue )
      39             :         : sName(rName),
      40      363793 :         sValue(rValue)
      41             :     {
      42      363793 :     }
      43             : 
      44      390224 :     SvXMLTagAttribute_Impl( const SvXMLTagAttribute_Impl& r ) :
      45             :         sName(r.sName),
      46      390224 :         sValue(r.sValue)
      47             :     {
      48      390224 :     }
      49             : 
      50             :     OUString sName;
      51             :     OUString sValue;
      52             : };
      53             : 
      54       36682 : struct SvXMLAttributeList_Impl
      55             : {
      56       35011 :     SvXMLAttributeList_Impl()
      57       35011 :     {
      58             :         // performance improvement during adding
      59       35011 :         vecAttribute.reserve(20);
      60       35011 :     }
      61             : 
      62         412 :     SvXMLAttributeList_Impl( const SvXMLAttributeList_Impl& r ) :
      63         412 :             vecAttribute( r.vecAttribute )
      64             :     {
      65         412 :     }
      66             : 
      67             :     ::std::vector<struct SvXMLTagAttribute_Impl> vecAttribute;
      68             :     typedef ::std::vector<struct SvXMLTagAttribute_Impl>::size_type size_type;
      69             : };
      70             : 
      71             : 
      72             : 
      73      226833 : sal_Int16 SAL_CALL SvXMLAttributeList::getLength() throw( ::com::sun::star::uno::RuntimeException, std::exception )
      74             : {
      75      226833 :     return sal::static_int_cast< sal_Int16 >(m_pImpl->vecAttribute.size());
      76             : }
      77             : 
      78             : 
      79         412 : SvXMLAttributeList::SvXMLAttributeList( const SvXMLAttributeList &r ) :
      80             :     cppu::WeakImplHelper3<com::sun::star::xml::sax::XAttributeList, com::sun::star::util::XCloneable, com::sun::star::lang::XUnoTunnel>(r),
      81         412 :     m_pImpl( new SvXMLAttributeList_Impl( *r.m_pImpl ) )
      82             : {
      83         412 : }
      84             : 
      85        3793 : SvXMLAttributeList::SvXMLAttributeList( const uno::Reference<
      86             :         xml::sax::XAttributeList> & rAttrList )
      87        3793 :     : sType( GetXMLToken(XML_CDATA) )
      88             : {
      89        3793 :     m_pImpl = new SvXMLAttributeList_Impl;
      90             : 
      91             :     SvXMLAttributeList* pImpl =
      92        3793 :         SvXMLAttributeList::getImplementation( rAttrList );
      93             : 
      94        3793 :     if( pImpl )
      95        1259 :         *m_pImpl = *(pImpl->m_pImpl);
      96             :     else
      97        2534 :         AppendAttributeList( rAttrList );
      98        3793 : }
      99             : 
     100      467732 : OUString SAL_CALL SvXMLAttributeList::getNameByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     101             : {
     102      467732 :     return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sName : OUString();
     103             : }
     104             : 
     105             : 
     106        1050 : OUString SAL_CALL SvXMLAttributeList::getTypeByIndex(sal_Int16) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     107             : {
     108        1050 :     return sType;
     109             : }
     110             : 
     111      379318 : OUString SAL_CALL  SvXMLAttributeList::getValueByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     112             : {
     113      379318 :     return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sValue : OUString();
     114             : }
     115             : 
     116           0 : OUString SAL_CALL SvXMLAttributeList::getTypeByName( const OUString& ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     117             : {
     118           0 :     return sType;
     119             : }
     120             : 
     121        4715 : OUString SAL_CALL SvXMLAttributeList::getValueByName(const OUString& sName) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     122             : {
     123        4715 :     ::std::vector<struct SvXMLTagAttribute_Impl>::iterator ii = m_pImpl->vecAttribute.begin();
     124             : 
     125       23206 :     for( ; ii != m_pImpl->vecAttribute.end() ; ++ii ) {
     126       20860 :         if( (*ii).sName == sName ) {
     127        2369 :             return (*ii).sValue;
     128             :         }
     129             :     }
     130        2346 :     return OUString();
     131             : }
     132             : 
     133             : 
     134         412 : uno::Reference< ::com::sun::star::util::XCloneable >  SvXMLAttributeList::createClone() throw( ::com::sun::star::uno::RuntimeException, std::exception )
     135             : {
     136         412 :     uno::Reference< ::com::sun::star::util::XCloneable >  r = new SvXMLAttributeList( *this );
     137         412 :     return r;
     138             : }
     139             : 
     140             : 
     141       31218 : SvXMLAttributeList::SvXMLAttributeList()
     142       31218 :     : sType( GetXMLToken(XML_CDATA) )
     143             : {
     144       31218 :     m_pImpl = new SvXMLAttributeList_Impl;
     145       31218 : }
     146             : 
     147             : 
     148             : 
     149      106269 : SvXMLAttributeList::~SvXMLAttributeList()
     150             : {
     151       35423 :     delete m_pImpl;
     152       70846 : }
     153             : 
     154             : 
     155      343140 : void SvXMLAttributeList::AddAttribute(  const OUString &sName ,
     156             :                                         const OUString &sValue )
     157             : {
     158      343140 :     m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl( sName , sValue ) );
     159      343140 : }
     160             : 
     161      132013 : void SvXMLAttributeList::Clear()
     162             : {
     163      132013 :     m_pImpl->vecAttribute.clear();
     164             : 
     165             :     OSL_ASSERT( ! getLength() );
     166      132013 : }
     167             : 
     168        3784 : void SvXMLAttributeList::RemoveAttribute( const OUString& sName )
     169             : {
     170        3784 :     ::std::vector<struct SvXMLTagAttribute_Impl>::iterator ii = m_pImpl->vecAttribute.begin();
     171             : 
     172       13433 :     for( ; ii != m_pImpl->vecAttribute.end() ; ++ii ) {
     173       11274 :         if( (*ii).sName == sName ) {
     174        1625 :             m_pImpl->vecAttribute.erase( ii );
     175        1625 :             break;
     176             :         }
     177             :     }
     178        3784 : }
     179             : 
     180        3858 : void SvXMLAttributeList::AppendAttributeList( const uno::Reference< ::com::sun::star::xml::sax::XAttributeList >  &r )
     181             : {
     182             :     OSL_ASSERT( r.is() );
     183             : 
     184        3858 :     sal_Int16 nMax = r->getLength();
     185             :     SvXMLAttributeList_Impl::size_type nTotalSize =
     186        3858 :         m_pImpl->vecAttribute.size() + nMax;
     187        3858 :     m_pImpl->vecAttribute.reserve( nTotalSize );
     188             : 
     189       24511 :     for( sal_Int16 i = 0 ; i < nMax ; ++i ) {
     190             :         m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl(
     191       20653 :             r->getNameByIndex( i ) ,
     192       41306 :             r->getValueByIndex( i )));
     193             :     }
     194             : 
     195             :     OSL_ASSERT( nTotalSize == (SvXMLAttributeList_Impl::size_type)getLength());
     196        3858 : }
     197             : 
     198        2003 : void SvXMLAttributeList::SetValueByIndex( sal_Int16 i,
     199             :         const OUString& rValue )
     200             : {
     201        2003 :     if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
     202        2003 :             < m_pImpl->vecAttribute.size() )
     203             :     {
     204        2003 :         m_pImpl->vecAttribute[i].sValue = rValue;
     205             :     }
     206        2003 : }
     207             : 
     208         212 : void SvXMLAttributeList::RemoveAttributeByIndex( sal_Int16 i )
     209             : {
     210         212 :     if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
     211         212 :             < m_pImpl->vecAttribute.size() )
     212         212 :         m_pImpl->vecAttribute.erase( m_pImpl->vecAttribute.begin() + i );
     213         212 : }
     214             : 
     215         551 : void SvXMLAttributeList::RenameAttributeByIndex( sal_Int16 i,
     216             :                                                  const OUString& rNewName )
     217             : {
     218         551 :     if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
     219         551 :             < m_pImpl->vecAttribute.size() )
     220             :     {
     221         551 :         m_pImpl->vecAttribute[i].sName = rNewName;
     222             :     }
     223         551 : }
     224             : 
     225           0 : sal_Int16 SvXMLAttributeList::GetIndexByName( const OUString& rName ) const
     226             : {
     227             :     ::std::vector<struct SvXMLTagAttribute_Impl>::iterator ii =
     228           0 :         m_pImpl->vecAttribute.begin();
     229             : 
     230           0 :     for( sal_Int16 nIndex=0; ii!=m_pImpl->vecAttribute.end(); ++ii, ++nIndex )
     231             :     {
     232           0 :         if( (*ii).sName == rName )
     233             :         {
     234           0 :             return nIndex;
     235             :         }
     236             :     }
     237           0 :     return -1;
     238             : }
     239             : 
     240             : namespace
     241             : {
     242             :     class theSvXMLAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLAttributeListUnoTunnelId> {};
     243             : }
     244             : 
     245             : // XUnoTunnel & co
     246        2619 : const uno::Sequence< sal_Int8 > & SvXMLAttributeList::getUnoTunnelId() throw()
     247             : {
     248        2619 :     return theSvXMLAttributeListUnoTunnelId::get().getSeq();
     249             : }
     250             : 
     251        3793 : SvXMLAttributeList* SvXMLAttributeList::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
     252             : {
     253        3793 :     uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
     254        3793 :     if( xUT.is() )
     255             :     {
     256             :         return
     257             :             reinterpret_cast<SvXMLAttributeList*>(
     258             :                 sal::static_int_cast<sal_IntPtr>(
     259        1360 :                     xUT->getSomething( SvXMLAttributeList::getUnoTunnelId())));
     260             :     }
     261             :     else
     262        2433 :         return NULL;
     263             : }
     264             : 
     265             : // XUnoTunnel
     266        1259 : sal_Int64 SAL_CALL SvXMLAttributeList::getSomething( const uno::Sequence< sal_Int8 >& rId )
     267             :     throw( uno::RuntimeException, std::exception )
     268             : {
     269        3777 :     if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
     270        2518 :                                                          rId.getConstArray(), 16 ) )
     271             :     {
     272        1259 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
     273             :     }
     274           0 :     return 0;
     275             : }
     276             : 
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11