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

Generated by: LCOV version 1.10