use insert function instead of for loop
[LibreOffice.git] / sc / source / filter / excel / frmbase.cxx
blob73ef59dadc72b3e073aa3d28770fd9543a4c92a4
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 <formel.hxx>
22 #include <osl/diagnose.h>
24 ScRangeListTabs::ScRangeListTabs( const XclImpRoot& rRoot )
25 : XclImpRoot( rRoot )
29 ScRangeListTabs::~ScRangeListTabs()
33 void ScRangeListTabs::Append( const ScAddress& aSRD, SCTAB nTab )
35 ScAddress a = aSRD;
36 ScDocument& rDoc = GetRoot().GetDoc();
38 if (a.Tab() > MAXTAB)
39 a.SetTab(MAXTAB);
41 if (a.Col() > rDoc.MaxCol())
42 a.SetCol(rDoc.MaxCol());
44 if (a.Row() > rDoc.MaxRow())
45 a.SetRow(rDoc.MaxRow());
47 if( nTab == SCTAB_MAX)
48 return;
49 if( nTab < 0)
50 nTab = a.Tab();
52 if (nTab < 0 || MAXTAB < nTab)
53 return;
55 TabRangeType::iterator itr = m_TabRanges.find(nTab);
56 if (itr == m_TabRanges.end())
58 // No entry for this table yet. Insert a new one.
59 std::pair<TabRangeType::iterator, bool> r =
60 m_TabRanges.insert(std::make_pair(nTab, RangeListType()));
62 if (!r.second)
63 // Insertion failed.
64 return;
66 itr = r.first;
68 itr->second.push_back(ScRange(a.Col(),a.Row(),a.Tab()));
71 void ScRangeListTabs::Append( const ScRange& aCRD, SCTAB nTab )
73 ScRange a = aCRD;
74 ScDocument& rDoc = GetRoot().GetDoc();
76 // ignore 3D ranges
77 if (a.aStart.Tab() != a.aEnd.Tab())
78 return;
80 if (a.aStart.Tab() > MAXTAB)
81 a.aStart.SetTab(MAXTAB);
82 else if (a.aStart.Tab() < 0)
83 a.aStart.SetTab(0);
85 if (a.aStart.Col() > rDoc.MaxCol())
86 a.aStart.SetCol(rDoc.MaxCol());
87 else if (a.aStart.Col() < 0)
88 a.aStart.SetCol(0);
90 if (a.aStart.Row() > rDoc.MaxRow())
91 a.aStart.SetRow(rDoc.MaxRow());
92 else if (a.aStart.Row() < 0)
93 a.aStart.SetRow(0);
95 if (a.aEnd.Col() > rDoc.MaxCol())
96 a.aEnd.SetCol(rDoc.MaxCol());
97 else if (a.aEnd.Col() < 0)
98 a.aEnd.SetCol(0);
100 if (a.aEnd.Row() > rDoc.MaxRow())
101 a.aEnd.SetRow(rDoc.MaxRow());
102 else if (a.aEnd.Row() < 0)
103 a.aEnd.SetRow(0);
105 if( nTab == SCTAB_MAX)
106 return;
108 if( nTab < -1)
109 nTab = a.aStart.Tab();
111 if (nTab < 0 || MAXTAB < nTab)
112 return;
114 TabRangeType::iterator itr = m_TabRanges.find(nTab);
115 if (itr == m_TabRanges.end())
117 // No entry for this table yet. Insert a new one.
118 std::pair<TabRangeType::iterator, bool> r =
119 m_TabRanges.insert(std::make_pair(nTab, RangeListType()));
121 if (!r.second)
122 // Insertion failed.
123 return;
125 itr = r.first;
127 itr->second.push_back(a);
130 const ScRange* ScRangeListTabs::First( SCTAB n )
132 OSL_ENSURE( ValidTab(n), "-ScRangeListTabs::First(): Good bye!" );
134 TabRangeType::iterator itr = m_TabRanges.find(n);
135 if (itr == m_TabRanges.end())
136 // No range list exists for this table.
137 return nullptr;
139 const RangeListType& rList = itr->second;
140 maItrCur = rList.begin();
141 maItrCurEnd = rList.end();
142 return rList.empty() ? nullptr : &(*maItrCur);
145 const ScRange* ScRangeListTabs::Next ()
147 ++maItrCur;
148 if (maItrCur == maItrCurEnd)
149 return nullptr;
151 return &(*maItrCur);
154 ConverterBase::ConverterBase( svl::SharedStringPool& rSPool ) :
155 aPool(rSPool),
156 aEingPos( 0, 0, 0 )
160 ConverterBase::~ConverterBase()
164 void ConverterBase::Reset()
166 aPool.Reset();
167 aStack.Reset();
170 ExcelConverterBase::ExcelConverterBase( svl::SharedStringPool& rSPool ) :
171 ConverterBase(rSPool)
175 ExcelConverterBase::~ExcelConverterBase()
179 void ExcelConverterBase::Reset( const ScAddress& rEingPos )
181 ConverterBase::Reset();
182 aEingPos = rEingPos;
185 void ExcelConverterBase::Reset()
187 ConverterBase::Reset();
188 aEingPos.Set( 0, 0, 0 );
191 LotusConverterBase::LotusConverterBase( SvStream &rStr, svl::SharedStringPool& rSPool ) :
192 ConverterBase(rSPool),
193 aIn( rStr ),
194 nBytesLeft( 0 )
198 LotusConverterBase::~LotusConverterBase()
202 void LotusConverterBase::Reset( const ScAddress& rEingPos )
204 ConverterBase::Reset();
205 nBytesLeft = 0;
206 aEingPos = rEingPos;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */