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

Generated by: LCOV version 1.10