LCOV - code coverage report
Current view: top level - hwpfilter/source - attributes.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 60 43.3 %
Date: 2015-06-13 12:38:46 Functions: 11 20 55.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 <assert.h>
      22             : #include <vector>
      23             : #include "attributes.hxx"
      24             : 
      25        1486 : struct TagAttribute
      26             : {
      27         306 :     TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue )
      28         306 :     {
      29         306 :         sName     = rName;
      30         306 :         sType     = rType;
      31         306 :         sValue    = rValue;
      32         306 :     }
      33             : 
      34             :     OUString sName;
      35             :     OUString sType;
      36             :     OUString sValue;
      37             : };
      38             : 
      39          86 : struct AttributeListImpl_impl
      40             : {
      41          86 :     AttributeListImpl_impl()
      42          86 :     {
      43             : // performance improvement during adding
      44          86 :         vecAttribute.reserve(20);
      45          86 :     }
      46             :     std::vector<struct TagAttribute> vecAttribute;
      47             : };
      48             : 
      49           0 : sal_Int16 SAL_CALL AttributeListImpl::getLength() throw (RuntimeException, std::exception)
      50             : {
      51           0 :     return (sal_Int16)m_pImpl->vecAttribute.size();
      52             : }
      53             : 
      54             : 
      55           0 : AttributeListImpl::AttributeListImpl( const AttributeListImpl &r ) :
      56           0 : cppu::WeakImplHelper1<com::sun::star::xml::sax::XAttributeList>( r )
      57             : {
      58           0 :     m_pImpl = new AttributeListImpl_impl;
      59           0 :     *m_pImpl = *(r.m_pImpl);
      60           0 : }
      61             : 
      62             : 
      63           0 : OUString AttributeListImpl::getNameByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
      64             : {
      65           0 :     sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
      66           0 :     if( i >= 0 &&  i2 < m_pImpl->vecAttribute.size() )
      67             :     {
      68           0 :         return m_pImpl->vecAttribute[i].sName;
      69             :     }
      70           0 :     return OUString();
      71             : }
      72             : 
      73             : 
      74           0 : OUString AttributeListImpl::getTypeByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
      75             : {
      76           0 :     sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
      77           0 :     if( i >= 0 &&  i2 < m_pImpl->vecAttribute.size() )
      78             :     {
      79           0 :         return m_pImpl->vecAttribute[i].sType;
      80             :     }
      81           0 :     return OUString();
      82             : }
      83             : 
      84             : 
      85           0 : OUString AttributeListImpl::getValueByIndex(sal_Int16 i) throw (RuntimeException, std::exception)
      86             : {
      87           0 :     sal_uInt32 i2 = sal::static_int_cast<sal_Int16>(i);
      88           0 :     if( i >= 0 &&  i2 < m_pImpl->vecAttribute.size() )
      89             :     {
      90           0 :         return m_pImpl->vecAttribute[i].sValue;
      91             :     }
      92           0 :     return OUString();
      93             : 
      94             : }
      95             : 
      96             : 
      97           0 : OUString AttributeListImpl::getTypeByName( const OUString& sName ) throw (RuntimeException, std::exception)
      98             : {
      99           0 :     std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
     100             : 
     101           0 :     for (; ii != m_pImpl->vecAttribute.end(); ++ii)
     102             :     {
     103           0 :         if( (*ii).sName == sName )
     104             :         {
     105           0 :             return (*ii).sType;
     106             :         }
     107             :     }
     108           0 :     return OUString();
     109             : }
     110             : 
     111             : 
     112           0 : OUString AttributeListImpl::getValueByName(const OUString& sName) throw (RuntimeException, std::exception)
     113             : {
     114           0 :     std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
     115             : 
     116           0 :     for (; ii != m_pImpl->vecAttribute.end(); ++ii)
     117             :     {
     118           0 :         if( (*ii).sName == sName )
     119             :         {
     120           0 :             return (*ii).sValue;
     121             :         }
     122             :     }
     123           0 :     return OUString();
     124             : }
     125             : 
     126             : 
     127          86 : AttributeListImpl::AttributeListImpl()
     128             : {
     129          86 :     m_pImpl = new AttributeListImpl_impl;
     130          86 : }
     131             : 
     132             : 
     133         258 : AttributeListImpl::~AttributeListImpl()
     134             : {
     135          86 :     delete m_pImpl;
     136         172 : }
     137             : 
     138             : 
     139         306 : void AttributeListImpl::addAttribute(   const OUString &sName ,
     140             : const OUString &sType ,
     141             : const OUString &sValue )
     142             : {
     143         306 :     m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
     144         306 : }
     145             : 
     146             : 
     147          91 : void AttributeListImpl::clear()
     148             : {
     149          91 :     std::vector<struct TagAttribute> dummy;
     150          91 :     m_pImpl->vecAttribute.swap( dummy );
     151             : 
     152          91 :     assert( ! getLength() );
     153          91 : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11