LCOV - code coverage report
Current view: top level - xmloff/source/core - attrlist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 89 106 84.0 %
Date: 2012-08-25 Functions: 26 31 83.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 45 92 48.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <string.h>
      31                 :            : #include <vector>
      32                 :            : #include <osl/mutex.hxx>
      33                 :            : #include <xmloff/xmltoken.hxx>
      34                 :            : #include <comphelper/servicehelper.hxx>
      35                 :            : 
      36                 :            : #include <xmloff/attrlist.hxx>
      37                 :            : 
      38                 :            : using ::rtl::OUString;
      39                 :            : 
      40                 :            : using namespace ::osl;
      41                 :            : using namespace ::com::sun::star;
      42                 :            : using namespace ::xmloff::token;
      43                 :            : 
      44                 :     392995 : struct SvXMLTagAttribute_Impl
      45                 :            : {
      46                 :            :     SvXMLTagAttribute_Impl(){}
      47                 :     190655 :     SvXMLTagAttribute_Impl( const OUString &rName,
      48                 :            :                          const OUString &rValue )
      49                 :            :         : sName(rName),
      50                 :     190655 :         sValue(rValue)
      51                 :            :     {
      52                 :     190655 :     }
      53                 :            : 
      54                 :     201462 :     SvXMLTagAttribute_Impl( const SvXMLTagAttribute_Impl& r ) :
      55                 :            :         sName(r.sName),
      56                 :     201462 :         sValue(r.sValue)
      57                 :            :     {
      58                 :     201462 :     }
      59                 :            : 
      60                 :            :     OUString sName;
      61                 :            :     OUString sValue;
      62                 :            : };
      63                 :            : 
      64                 :       7630 : struct SvXMLAttributeList_Impl
      65                 :            : {
      66                 :       7059 :     SvXMLAttributeList_Impl()
      67                 :       7059 :     {
      68                 :            :         // performance improvement during adding
      69         [ +  - ]:       7059 :         vecAttribute.reserve(20);
      70                 :       7059 :     }
      71                 :            : 
      72                 :          0 :     SvXMLAttributeList_Impl( const SvXMLAttributeList_Impl& r ) :
      73                 :          0 :             vecAttribute( r.vecAttribute )
      74                 :            :     {
      75                 :          0 :     }
      76                 :            : 
      77                 :            :     ::std::vector<struct SvXMLTagAttribute_Impl> vecAttribute;
      78                 :            :     typedef ::std::vector<struct SvXMLTagAttribute_Impl>::size_type size_type;
      79                 :            : };
      80                 :            : 
      81                 :            : 
      82                 :            : 
      83                 :     114127 : sal_Int16 SAL_CALL SvXMLAttributeList::getLength(void) throw( ::com::sun::star::uno::RuntimeException )
      84                 :            : {
      85                 :     114127 :     return sal::static_int_cast< sal_Int16 >(m_pImpl->vecAttribute.size());
      86                 :            : }
      87                 :            : 
      88                 :            : 
      89                 :          0 : SvXMLAttributeList::SvXMLAttributeList( const SvXMLAttributeList &r ) :
      90                 :            :     cppu::WeakImplHelper3<com::sun::star::xml::sax::XAttributeList, com::sun::star::util::XCloneable, com::sun::star::lang::XUnoTunnel>(r),
      91 [ #  # ][ #  # ]:          0 :     m_pImpl( new SvXMLAttributeList_Impl( *r.m_pImpl ) )
      92                 :            : {
      93                 :          0 : }
      94                 :            : 
      95                 :       3384 : SvXMLAttributeList::SvXMLAttributeList( const uno::Reference<
      96                 :            :         xml::sax::XAttributeList> & rAttrList )
      97         [ +  - ]:       3384 :     : sType( GetXMLToken(XML_CDATA) )
      98                 :            : {
      99 [ +  - ][ +  - ]:       3384 :     m_pImpl = new SvXMLAttributeList_Impl;
     100                 :            : 
     101                 :            :     SvXMLAttributeList* pImpl =
     102                 :       3384 :         SvXMLAttributeList::getImplementation( rAttrList );
     103                 :            : 
     104         [ +  + ]:       3384 :     if( pImpl )
     105         [ +  - ]:        571 :         *m_pImpl = *(pImpl->m_pImpl);
     106                 :            :     else
     107         [ +  - ]:       2813 :         AppendAttributeList( rAttrList );
     108                 :       3384 : }
     109                 :            : 
     110                 :     216674 : OUString SAL_CALL SvXMLAttributeList::getNameByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException )
     111                 :            : {
     112         [ +  - ]:     216674 :     return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sName : OUString();
     113                 :            : }
     114                 :            : 
     115                 :            : 
     116                 :       2008 : OUString SAL_CALL SvXMLAttributeList::getTypeByIndex(sal_Int16) throw( ::com::sun::star::uno::RuntimeException )
     117                 :            : {
     118                 :       2008 :     return sType;
     119                 :            : }
     120                 :            : 
     121                 :     190703 : OUString SAL_CALL  SvXMLAttributeList::getValueByIndex(sal_Int16 i) throw( ::com::sun::star::uno::RuntimeException )
     122                 :            : {
     123         [ +  - ]:     190703 :     return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sValue : OUString();
     124                 :            : }
     125                 :            : 
     126                 :          0 : OUString SAL_CALL SvXMLAttributeList::getTypeByName( const OUString& ) throw( ::com::sun::star::uno::RuntimeException )
     127                 :            : {
     128                 :          0 :     return sType;
     129                 :            : }
     130                 :            : 
     131                 :         97 : OUString SAL_CALL SvXMLAttributeList::getValueByName(const OUString& sName) throw( ::com::sun::star::uno::RuntimeException )
     132                 :            : {
     133                 :         97 :     ::std::vector<struct SvXMLTagAttribute_Impl>::iterator ii = m_pImpl->vecAttribute.begin();
     134                 :            : 
     135 [ +  - ][ +  + ]:       1027 :     for( ; ii != m_pImpl->vecAttribute.end() ; ++ii ) {
     136         [ +  + ]:       1005 :         if( (*ii).sName == sName ) {
     137                 :         75 :             return (*ii).sValue;
     138                 :            :         }
     139                 :            :     }
     140                 :         97 :     return OUString();
     141                 :            : }
     142                 :            : 
     143                 :            : 
     144                 :          0 : uno::Reference< ::com::sun::star::util::XCloneable >  SvXMLAttributeList::createClone() throw( ::com::sun::star::uno::RuntimeException )
     145                 :            : {
     146 [ #  # ][ #  # ]:          0 :     uno::Reference< ::com::sun::star::util::XCloneable >  r = new SvXMLAttributeList( *this );
                 [ #  # ]
     147                 :          0 :     return r;
     148                 :            : }
     149                 :            : 
     150                 :            : 
     151                 :       3675 : SvXMLAttributeList::SvXMLAttributeList()
     152         [ +  - ]:       3675 :     : sType( GetXMLToken(XML_CDATA) )
     153                 :            : {
     154 [ +  - ][ +  - ]:       3675 :     m_pImpl = new SvXMLAttributeList_Impl;
     155                 :       3675 : }
     156                 :            : 
     157                 :            : 
     158                 :            : 
     159                 :       7059 : SvXMLAttributeList::~SvXMLAttributeList()
     160                 :            : {
     161         [ +  - ]:       7059 :     delete m_pImpl;
     162         [ -  + ]:      14118 : }
     163                 :            : 
     164                 :            : 
     165                 :     174529 : void SvXMLAttributeList::AddAttribute(  const OUString &sName ,
     166                 :            :                                         const OUString &sValue )
     167                 :            : {
     168         [ +  - ]:     174529 :     m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl( sName , sValue ) );
     169                 :     174529 : }
     170                 :            : 
     171                 :     101542 : void SvXMLAttributeList::Clear()
     172                 :            : {
     173                 :     101542 :     m_pImpl->vecAttribute.clear();
     174                 :            : 
     175                 :            :     OSL_ASSERT( ! getLength() );
     176                 :     101542 : }
     177                 :            : 
     178                 :         56 : void SvXMLAttributeList::RemoveAttribute( const OUString sName )
     179                 :            : {
     180                 :         56 :     ::std::vector<struct SvXMLTagAttribute_Impl>::iterator ii = m_pImpl->vecAttribute.begin();
     181                 :            : 
     182 [ +  - ][ +  + ]:        896 :     for( ; ii != m_pImpl->vecAttribute.end() ; ++ii ) {
     183         [ +  + ]:        874 :         if( (*ii).sName == sName ) {
     184         [ +  - ]:         34 :             m_pImpl->vecAttribute.erase( ii );
     185                 :         34 :             break;
     186                 :            :         }
     187                 :            :     }
     188                 :         56 : }
     189                 :            : 
     190                 :       2977 : void SvXMLAttributeList::AppendAttributeList( const uno::Reference< ::com::sun::star::xml::sax::XAttributeList >  &r )
     191                 :            : {
     192                 :            :     OSL_ASSERT( r.is() );
     193                 :            : 
     194                 :       2977 :     sal_Int16 nMax = r->getLength();
     195                 :            :     SvXMLAttributeList_Impl::size_type nTotalSize =
     196                 :       2977 :         m_pImpl->vecAttribute.size() + nMax;
     197                 :       2977 :     m_pImpl->vecAttribute.reserve( nTotalSize );
     198                 :            : 
     199         [ +  + ]:      19103 :     for( sal_Int16 i = 0 ; i < nMax ; ++i ) {
     200                 :            :         m_pImpl->vecAttribute.push_back( SvXMLTagAttribute_Impl(
     201         [ +  - ]:      16126 :             r->getNameByIndex( i ) ,
     202 [ +  - ][ +  - ]:      32252 :             r->getValueByIndex( i )));
     203                 :            :     }
     204                 :            : 
     205                 :            :     OSL_ASSERT( nTotalSize == (SvXMLAttributeList_Impl::size_type)getLength());
     206                 :       2977 : }
     207                 :            : 
     208                 :       3747 : void SvXMLAttributeList::SetValueByIndex( sal_Int16 i,
     209                 :            :         const ::rtl::OUString& rValue )
     210                 :            : {
     211         [ +  - ]:       3747 :     if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
     212                 :       3747 :             < m_pImpl->vecAttribute.size() )
     213                 :            :     {
     214                 :       3747 :         m_pImpl->vecAttribute[i].sValue = rValue;
     215                 :            :     }
     216                 :       3747 : }
     217                 :            : 
     218                 :        180 : void SvXMLAttributeList::RemoveAttributeByIndex( sal_Int16 i )
     219                 :            : {
     220         [ +  - ]:        180 :     if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
     221                 :        180 :             < m_pImpl->vecAttribute.size() )
     222 [ +  - ][ +  - ]:        180 :         m_pImpl->vecAttribute.erase( m_pImpl->vecAttribute.begin() + i );
     223                 :        180 : }
     224                 :            : 
     225                 :        617 : void SvXMLAttributeList::RenameAttributeByIndex( sal_Int16 i,
     226                 :            :                                                  const OUString& rNewName )
     227                 :            : {
     228         [ +  - ]:        617 :     if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
     229                 :        617 :             < m_pImpl->vecAttribute.size() )
     230                 :            :     {
     231                 :        617 :         m_pImpl->vecAttribute[i].sName = rNewName;
     232                 :            :     }
     233                 :        617 : }
     234                 :            : 
     235                 :          0 : sal_Int16 SvXMLAttributeList::GetIndexByName( const OUString& rName ) const
     236                 :            : {
     237                 :            :     ::std::vector<struct SvXMLTagAttribute_Impl>::iterator ii =
     238                 :          0 :         m_pImpl->vecAttribute.begin();
     239                 :            : 
     240 [ #  # ][ #  # ]:          0 :     for( sal_Int16 nIndex=0; ii!=m_pImpl->vecAttribute.end(); ++ii, ++nIndex )
     241                 :            :     {
     242         [ #  # ]:          0 :         if( (*ii).sName == rName )
     243                 :            :         {
     244                 :          0 :             return nIndex;
     245                 :            :         }
     246                 :            :     }
     247                 :          0 :     return -1;
     248                 :            : }
     249                 :            : 
     250                 :            : namespace
     251                 :            : {
     252                 :            :     class theSvXMLAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLAttributeListUnoTunnelId> {};
     253                 :            : }
     254                 :            : 
     255                 :            : // XUnoTunnel & co
     256                 :       1312 : const uno::Sequence< sal_Int8 > & SvXMLAttributeList::getUnoTunnelId() throw()
     257                 :            : {
     258                 :       1312 :     return theSvXMLAttributeListUnoTunnelId::get().getSeq();
     259                 :            : }
     260                 :            : 
     261                 :       3384 : SvXMLAttributeList* SvXMLAttributeList::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
     262                 :            : {
     263         [ +  - ]:       3384 :     uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
     264         [ +  + ]:       3384 :     if( xUT.is() )
     265                 :            :     {
     266                 :            :         return
     267                 :            :             reinterpret_cast<SvXMLAttributeList*>(
     268                 :            :                 sal::static_int_cast<sal_IntPtr>(
     269 [ +  - ][ +  - ]:        741 :                     xUT->getSomething( SvXMLAttributeList::getUnoTunnelId())));
     270                 :            :     }
     271                 :            :     else
     272                 :       3384 :         return NULL;
     273                 :            : }
     274                 :            : 
     275                 :            : // XUnoTunnel
     276                 :        571 : sal_Int64 SAL_CALL SvXMLAttributeList::getSomething( const uno::Sequence< sal_Int8 >& rId )
     277                 :            :     throw( uno::RuntimeException )
     278                 :            : {
     279   [ +  -  +  - ]:       1142 :     if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
                 [ +  - ]
     280                 :        571 :                                                          rId.getConstArray(), 16 ) )
     281                 :            :     {
     282                 :        571 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
     283                 :            :     }
     284                 :        571 :     return 0;
     285                 :            : }
     286                 :            : 
     287                 :            : 
     288                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10