LCOV - code coverage report
Current view: top level - sax/source/expatwrap - attrlistimpl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 46 58 79.3 %
Date: 2014-04-11 Functions: 18 21 85.7 %
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             : #include "attrlistimpl.hxx"
      21             : 
      22             : #include <vector>
      23             : 
      24             : #include <cppuhelper/weak.hxx>
      25             : 
      26             : using namespace ::std;
      27             : using namespace ::rtl;
      28             : using namespace ::cppu;
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::util;
      31             : using namespace ::com::sun::star::xml::sax;
      32             : 
      33             : 
      34             : namespace sax_expatwrap {
      35     1528113 : struct TagAttribute
      36             : {
      37      501749 :     TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
      38      501749 :     {
      39      501749 :         this->sName     = aName;
      40      501749 :         this->sType     = aType;
      41      501749 :         this->sValue    = aValue;
      42      501749 :     }
      43             : 
      44             :     OUString sName;
      45             :     OUString sType;
      46             :     OUString sValue;
      47             : };
      48             : 
      49       15191 : struct AttributeList_impl
      50             : {
      51       14939 :     AttributeList_impl()
      52       14939 :     {
      53             :         // performance improvement during adding
      54       14939 :         vecAttribute.reserve(20);
      55       14939 :     }
      56             :     vector<struct TagAttribute> vecAttribute;
      57             : };
      58             : 
      59             : 
      60             : 
      61      360190 : sal_Int16 AttributeList::getLength(void) throw (RuntimeException, std::exception)
      62             : {
      63      360190 :     return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
      64             : }
      65             : 
      66             : 
      67         252 : AttributeList::AttributeList( const AttributeList &r ) :
      68         252 :     cppu::WeakImplHelper2<XAttributeList, XCloneable>()
      69             : {
      70         252 :     m_pImpl = new AttributeList_impl;
      71         252 :     *m_pImpl = *(r.m_pImpl);
      72         252 : }
      73             : 
      74      696017 : OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
      75             : {
      76      696017 :     if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
      77      696017 :         return m_pImpl->vecAttribute[i].sName;
      78             :     }
      79           0 :     return OUString();
      80             : }
      81             : 
      82             : 
      83           0 : OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
      84             : {
      85           0 :     if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
      86           0 :         return m_pImpl->vecAttribute[i].sType;
      87             :     }
      88           0 :     return OUString();
      89             : }
      90             : 
      91      441615 : OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
      92             : {
      93      441615 :     if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
      94      441615 :         return m_pImpl->vecAttribute[i].sValue;
      95             :     }
      96           0 :     return OUString();
      97             : 
      98             : }
      99             : 
     100           0 : OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException, std::exception)
     101             : {
     102           0 :     vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
     103             : 
     104           0 :     for (; ii != m_pImpl->vecAttribute.end(); ++ii )
     105             :     {
     106           0 :         if( (*ii).sName == sName )
     107             :         {
     108           0 :             return (*ii).sType;
     109             :         }
     110             :     }
     111           0 :     return OUString();
     112             : }
     113             : 
     114      124521 : OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException, std::exception)
     115             : {
     116      124521 :     vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
     117             : 
     118      255416 :     for (; ii != m_pImpl->vecAttribute.end(); ++ii)
     119             :     {
     120      239344 :         if( (*ii).sName == sName )
     121             :         {
     122      108449 :             return (*ii).sValue;
     123             :         }
     124             :     }
     125       16072 :     return OUString();
     126             : }
     127             : 
     128             : 
     129         252 : Reference< XCloneable > AttributeList::createClone() throw (RuntimeException, std::exception)
     130             : {
     131         252 :     AttributeList *p = new AttributeList( *this );
     132         252 :     return Reference< XCloneable > ( (XCloneable * ) p );
     133             : }
     134             : 
     135             : 
     136             : 
     137       14687 : AttributeList::AttributeList()
     138             : {
     139       14687 :     m_pImpl = new AttributeList_impl;
     140       14687 : }
     141             : 
     142             : 
     143             : 
     144       44817 : AttributeList::~AttributeList()
     145             : {
     146       14939 :     delete m_pImpl;
     147       29878 : }
     148             : 
     149             : 
     150      501749 : void AttributeList::addAttribute(   const OUString &sName ,
     151             :                                         const OUString &sType ,
     152             :                                         const OUString &sValue )
     153             : {
     154      501749 :     m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
     155      501749 : }
     156             : 
     157      260841 : void AttributeList::clear()
     158             : {
     159      260841 :     m_pImpl->vecAttribute.clear();
     160      260841 : }
     161             : 
     162             : }
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10