bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / forms / attriblistmerge.cxx
blob275c6232d59d2ff45826fa00254bdc0b10e08f41
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "attriblistmerge.hxx"
22 #include <osl/diagnose.h>
24 namespace xmloff
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star;
30 //= OAttribListMerger
31 void OAttribListMerger::addList(const Reference< xml::sax::XAttributeList >& _rxList)
33 OSL_ENSURE(_rxList.is(), "OAttribListMerger::addList: invalid list!");
34 if (_rxList.is())
35 m_aLists.push_back(_rxList);
38 bool OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
40 sal_Int16 nLeftOver = _nGlobalIndex;
41 AttributeListArray::const_iterator aLookupSublist = m_aLists.begin();
43 for ( ; (aLookupSublist != m_aLists.end()) && (nLeftOver >= (*aLookupSublist)->getLength());
44 ++aLookupSublist
46 nLeftOver = nLeftOver - (*aLookupSublist)->getLength();
48 if (aLookupSublist == m_aLists.end())
50 OSL_FAIL("OAttribListMerger::seekToIndex: invalid index!");
51 return false;
53 _rSubList = *aLookupSublist;
54 _rLocalIndex = nLeftOver;
55 return true;
58 bool OAttribListMerger::seekToName(const OUString& _rName, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
60 for ( AttributeListArray::const_iterator aLookupSublist = m_aLists.begin();
61 aLookupSublist != m_aLists.end();
62 ++aLookupSublist
64 for (sal_Int16 i=0; i<(*aLookupSublist)->getLength(); ++i)
65 if ((*aLookupSublist)->getNameByIndex(i) == _rName)
67 _rSubList = *aLookupSublist;
68 _rLocalIndex = i;
69 return true;
72 OSL_FAIL("OAttribListMerger::seekToName: did not find the name!");
73 return false;
76 sal_Int16 SAL_CALL OAttribListMerger::getLength( ) throw(RuntimeException, std::exception)
78 sal_Int16 nCount = 0;
79 for ( AttributeListArray::const_iterator aAccumulate = m_aLists.begin();
80 aAccumulate != m_aLists.end();
81 ++aAccumulate
83 nCount = nCount + (*aAccumulate)->getLength();
84 return nCount;
87 OUString SAL_CALL OAttribListMerger::getNameByIndex( sal_Int16 i ) throw(RuntimeException, std::exception)
89 Reference< xml::sax::XAttributeList > xSubList;
90 sal_Int16 nLocalIndex;
92 if (!seekToIndex(i, xSubList, nLocalIndex))
93 return OUString();
95 return xSubList->getNameByIndex(nLocalIndex);
98 OUString SAL_CALL OAttribListMerger::getTypeByIndex( sal_Int16 i ) throw(RuntimeException, std::exception)
100 Reference< xml::sax::XAttributeList > xSubList;
101 sal_Int16 nLocalIndex;
103 if (!seekToIndex(i, xSubList, nLocalIndex))
104 return OUString();
106 return xSubList->getTypeByIndex(nLocalIndex);
109 OUString SAL_CALL OAttribListMerger::getTypeByName( const OUString& _rName ) throw(RuntimeException, std::exception)
111 Reference< xml::sax::XAttributeList > xSubList;
112 sal_Int16 nLocalIndex;
114 if (!seekToName(_rName, xSubList, nLocalIndex))
115 return OUString();
117 // though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
118 // assuming that this is faster
119 return xSubList->getTypeByIndex(nLocalIndex);
122 OUString SAL_CALL OAttribListMerger::getValueByIndex( sal_Int16 i ) throw(RuntimeException, std::exception)
124 Reference< xml::sax::XAttributeList > xSubList;
125 sal_Int16 nLocalIndex;
127 if (!seekToIndex(i, xSubList, nLocalIndex))
128 return OUString();
130 return xSubList->getValueByIndex(nLocalIndex);
133 OUString SAL_CALL OAttribListMerger::getValueByName( const OUString& _rName ) throw(RuntimeException, std::exception)
135 Reference< xml::sax::XAttributeList > xSubList;
136 sal_Int16 nLocalIndex;
138 if (!seekToName(_rName, xSubList, nLocalIndex))
139 return OUString();
141 // though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
142 // assuming that this is faster
143 return xSubList->getValueByIndex(nLocalIndex);
146 } // namespace xmloff
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */