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

Generated by: LCOV version 1.10