LCOV - code coverage report
Current view: top level - xmloff/source/forms - attriblistmerge.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 54 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 9 0.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             : #include "attriblistmerge.hxx"
      21             : 
      22             : #include <osl/diagnose.h>
      23             : 
      24             : namespace xmloff
      25             : {
      26             : 
      27             :     using namespace ::com::sun::star::uno;
      28             :     using namespace ::com::sun::star;
      29             : 
      30             :     //= OAttribListMerger
      31           0 :     void OAttribListMerger::addList(const Reference< xml::sax::XAttributeList >& _rxList)
      32             :     {
      33             :         OSL_ENSURE(_rxList.is(), "OAttribListMerger::addList: invalid list!");
      34           0 :         if (_rxList.is())
      35           0 :             m_aLists.push_back(_rxList);
      36           0 :     }
      37             : 
      38           0 :     bool OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
      39             :     {
      40           0 :         sal_Int16 nLeftOver = _nGlobalIndex;
      41           0 :         AttributeListArray::const_iterator aLookupSublist = m_aLists.begin();
      42             : 
      43           0 :         for ( ; (aLookupSublist != m_aLists.end()) && (nLeftOver >= (*aLookupSublist)->getLength());
      44             :                 ++aLookupSublist
      45             :             )
      46           0 :             nLeftOver = nLeftOver - (*aLookupSublist)->getLength();
      47             : 
      48           0 :         if (aLookupSublist == m_aLists.end())
      49             :         {
      50             :             OSL_FAIL("OAttribListMerger::seekToIndex: invalid index!");
      51           0 :             return false;
      52             :         }
      53           0 :         _rSubList = *aLookupSublist;
      54           0 :         _rLocalIndex = nLeftOver;
      55           0 :         return true;
      56             :     }
      57             : 
      58           0 :     bool OAttribListMerger::seekToName(const OUString& _rName, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
      59             :     {
      60           0 :         for (   AttributeListArray::const_iterator aLookupSublist = m_aLists.begin();
      61           0 :                 aLookupSublist != m_aLists.end();
      62             :                 ++aLookupSublist
      63             :             )
      64           0 :             for (sal_Int16 i=0; i<(*aLookupSublist)->getLength(); ++i)
      65           0 :                 if ((*aLookupSublist)->getNameByIndex(i) == _rName)
      66             :                 {
      67           0 :                     _rSubList = *aLookupSublist;
      68           0 :                     _rLocalIndex = i;
      69           0 :                     return true;
      70             :                 }
      71             : 
      72             :         OSL_FAIL("OAttribListMerger::seekToName: did not find the name!");
      73           0 :         return false;
      74             :     }
      75             : 
      76           0 :     sal_Int16 SAL_CALL OAttribListMerger::getLength(  ) throw(RuntimeException, std::exception)
      77             :     {
      78           0 :         sal_Int16 nCount = 0;
      79           0 :         for (   AttributeListArray::const_iterator aAccumulate = m_aLists.begin();
      80           0 :                 aAccumulate != m_aLists.end();
      81             :                 ++aAccumulate
      82             :             )
      83           0 :             nCount = nCount + (*aAccumulate)->getLength();
      84           0 :         return nCount;
      85             :     }
      86             : 
      87           0 :     OUString SAL_CALL OAttribListMerger::getNameByIndex( sal_Int16 i ) throw(RuntimeException, std::exception)
      88             :     {
      89           0 :         Reference< xml::sax::XAttributeList > xSubList;
      90             :         sal_Int16 nLocalIndex;
      91             : 
      92           0 :         if (!seekToIndex(i, xSubList, nLocalIndex))
      93           0 :             return OUString();
      94             : 
      95           0 :         return xSubList->getNameByIndex(nLocalIndex);
      96             :     }
      97             : 
      98           0 :     OUString SAL_CALL OAttribListMerger::getTypeByIndex( sal_Int16 i ) throw(RuntimeException, std::exception)
      99             :     {
     100           0 :         Reference< xml::sax::XAttributeList > xSubList;
     101             :         sal_Int16 nLocalIndex;
     102             : 
     103           0 :         if (!seekToIndex(i, xSubList, nLocalIndex))
     104           0 :             return OUString();
     105             : 
     106           0 :         return xSubList->getTypeByIndex(nLocalIndex);
     107             :     }
     108             : 
     109           0 :     OUString SAL_CALL OAttribListMerger::getTypeByName( const OUString& _rName ) throw(RuntimeException, std::exception)
     110             :     {
     111           0 :         Reference< xml::sax::XAttributeList > xSubList;
     112             :         sal_Int16 nLocalIndex;
     113             : 
     114           0 :         if (!seekToName(_rName, xSubList, nLocalIndex))
     115           0 :             return OUString();
     116             : 
     117             :         // though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
     118             :         // assuming that this is faster
     119           0 :         return xSubList->getTypeByIndex(nLocalIndex);
     120             :     }
     121             : 
     122           0 :     OUString SAL_CALL OAttribListMerger::getValueByIndex( sal_Int16 i ) throw(RuntimeException, std::exception)
     123             :     {
     124           0 :         Reference< xml::sax::XAttributeList > xSubList;
     125             :         sal_Int16 nLocalIndex;
     126             : 
     127           0 :         if (!seekToIndex(i, xSubList, nLocalIndex))
     128           0 :             return OUString();
     129             : 
     130           0 :         return xSubList->getValueByIndex(nLocalIndex);
     131             :     }
     132             : 
     133           0 :     OUString SAL_CALL OAttribListMerger::getValueByName( const OUString& _rName ) throw(RuntimeException, std::exception)
     134             :     {
     135           0 :         Reference< xml::sax::XAttributeList > xSubList;
     136             :         sal_Int16 nLocalIndex;
     137             : 
     138           0 :         if (!seekToName(_rName, xSubList, nLocalIndex))
     139           0 :             return OUString();
     140             : 
     141             :         // though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
     142             :         // assuming that this is faster
     143           0 :         return xSubList->getValueByIndex(nLocalIndex);
     144             :     }
     145             : 
     146             : }   // namespace xmloff
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11