LCOV - code coverage report
Current view: top level - hwpfilter/source - attributes.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 26 60 43.3 %
Date: 2014-11-03 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        2972 : struct TagAttribute
      26             : {
      27         612 :     TagAttribute( const OUString &rName, const OUString &rType , const OUString &rValue )
      28         612 :     {
      29         612 :         sName     = rName;
      30         612 :         sType     = rType;
      31         612 :         sValue    = rValue;
      32         612 :     }
      33             : 
      34             :     OUString sName;
      35             :     OUString sType;
      36             :     OUString sValue;
      37             : };
      38             : 
      39           2 : struct AttributeListImpl_impl
      40             : {
      41           2 :     AttributeListImpl_impl()
      42           2 :     {
      43             : // performance improvement during adding
      44           2 :         vecAttribute.reserve(20);
      45           2 :     }
      46             :     std::vector<struct TagAttribute> vecAttribute;
      47             : };
      48             : 
      49           0 : sal_Int16 SAL_CALL AttributeListImpl::getLength(void) 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           2 : AttributeListImpl::AttributeListImpl()
     128             : {
     129           2 :     m_pImpl = new AttributeListImpl_impl;
     130           2 : }
     131             : 
     132             : 
     133           6 : AttributeListImpl::~AttributeListImpl()
     134             : {
     135           2 :     delete m_pImpl;
     136           4 : }
     137             : 
     138             : 
     139         612 : void AttributeListImpl::addAttribute(   const OUString &sName ,
     140             : const OUString &sType ,
     141             : const OUString &sValue )
     142             : {
     143         612 :     m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
     144         612 : }
     145             : 
     146             : 
     147         182 : void AttributeListImpl::clear()
     148             : {
     149         182 :     std::vector<struct TagAttribute> dummy;
     150         182 :     m_pImpl->vecAttribute.swap( dummy );
     151             : 
     152         182 :     assert( ! getLength() );
     153         182 : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10