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

Generated by: LCOV version 1.11