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

Generated by: LCOV version 1.10