LibreOffice Module sc (master) 1
columniterator.cxx
Go to the documentation of this file.
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
10#include <columniterator.hxx>
11#include <column.hxx>
12#include <document.hxx>
13#include <table.hxx>
14
15#include <osl/diagnose.h>
16
18 mnEnd(static_cast<size_t>(nEndRow)),
19 mnCurPos(0)
20{
21 miBlockCur = rCol.maCellTextAttrs.begin();
22 miBlockEnd = rCol.maCellTextAttrs.end();
23 init(rDoc, nStartRow, nEndRow);
24}
25
27 mnEnd(static_cast<size_t>(nEndRow)),
28 mnCurPos(0)
29{
30 auto & rCellTextAttrs = rDoc.maTabs[rStartPos.Tab()]->aCol[rStartPos.Col()].maCellTextAttrs;
31 miBlockCur = rCellTextAttrs.begin();
32 miBlockEnd = rCellTextAttrs.end();
33 init(rDoc, rStartPos.Row(), nEndRow);
34}
35
37{
38 ++miDataCur;
39 ++mnCurPos;
40
41 if (miDataCur != miDataEnd)
42 {
43 // Still in the same block. We're good.
45 return;
46 }
47
48 // Move to the next block.
50 {
52 {
53 // We don't iterator over this block.
54 mnCurPos += miBlockCur->size;
55 continue;
56 }
57
60 return;
61 }
62
63 // Reached the end.
64 assert(miBlockCur == miBlockEnd);
65}
66
68{
69 return miBlockCur != miBlockEnd;
70}
71
73{
75 return static_cast<SCROW>(mnCurPos);
76}
77
79{
81 return miDataCur->mnTextWidth;
82}
83
85{
87 miDataCur->mnTextWidth = nVal;
88}
89
90void ScColumnTextWidthIterator::init(const ScDocument& rDoc, SCROW nStartRow, SCROW nEndRow)
91{
92 if (!rDoc.ValidRow(nStartRow) || !rDoc.ValidRow(nEndRow))
94
95 size_t nStart = static_cast<size_t>(nStartRow);
96
97 // Locate the start row position.
98 size_t nBlockStart = 0, nBlockEnd = 0;
99 for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
100 {
101 nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
102 if (nBlockStart <= nStart && nStart < nBlockEnd)
103 {
104 // Initial block is found!
105 break;
106 }
107 }
108
109 if (miBlockCur == miBlockEnd)
110 // Initial block not found for whatever reason... Bail out.
111 return;
112
113 // Locate the initial row position within this block.
115 {
116 // This block stores text widths for non-empty cells.
117 size_t nOffsetInBlock = nStart - nBlockStart;
118 mnCurPos = nStart;
119 getDataIterators(nOffsetInBlock);
120 checkEndRow();
121 return;
122 }
123
124 // Current block is not of ushort type. Skip to the next block.
125 nBlockStart = nBlockEnd;
126 ++miBlockCur;
127
128 // Look for the first ushort block.
129 for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
130 {
131 nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
133 continue;
134
135 // Found!
136 mnCurPos = nBlockStart;
138 checkEndRow();
139 return;
140 }
141
142 // Not found.
143 assert(miBlockCur == miBlockEnd);
144}
145
147{
148 OSL_ENSURE(miBlockCur != miBlockEnd, "block is at end position");
149#if 0
150 // Does not compile
151 OSL_ENSURE(miBlockCur->type == sc::celltextattr_block,
152 "wrong block type - unsigned short block expected.");
153#endif
154 miDataCur = sc::celltextattr_block::begin(*miBlockCur->data);
155 miDataEnd = sc::celltextattr_block::end(*miBlockCur->data);
156
157 std::advance(miDataCur, nOffsetInBlock);
158}
159
161{
162 if (mnCurPos <= mnEnd)
163 // We're still good.
164 return;
165
166 // We're below the end position. End the iteration.
168}
169
170namespace sc {
171
173 maPos(rCells.position(nRow1)),
174 maPosEnd(rCells.position(maPos.first, nRow2)),
175 mbComplete(false)
176{
177}
178
180{
181 if ( maPos == maPosEnd)
182 mbComplete = true;
183 else
184 maPos = CellStoreType::next_position(maPos);
185}
186
188{
189 return CellStoreType::logical_position(maPos);
190}
191
193{
194 return !mbComplete;
195}
196
197mdds::mtv::element_t ColumnIterator::getType() const
198{
199 return maPos.first->type;
200}
201
203{
204 return toRefCell(maPos.first, maPos.second);
205}
206
207}
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t mnEnd
Definition: cellvalues.cxx:25
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
sc::CellTextAttrStoreType::iterator miBlockEnd
void setValue(sal_uInt16 nVal)
ScColumnTextWidthIterator(const ScColumnTextWidthIterator &)=delete
sal_uInt16 getValue() const
sc::celltextattr_block::iterator miDataCur
void getDataIterators(size_t nOffsetInBlock)
void init(const ScDocument &rDoc, SCROW nStartRow, SCROW nEndRow)
sc::CellTextAttrStoreType::iterator miBlockCur
sc::celltextattr_block::iterator miDataEnd
sc::CellTextAttrStoreType maCellTextAttrs
Definition: column.hxx:188
bool ValidRow(SCROW nRow) const
Definition: document.hxx:900
TableContainer maTabs
Definition: document.hxx:378
ColumnIterator(const CellStoreType &rCells, SCROW nRow1, SCROW nRow2)
SCROW getRow() const
CellStoreType::const_position_type maPos
CellStoreType::const_position_type maPosEnd
ScRefCellValue getCell() const
mdds::mtv::element_t getType() const
def position(n=-1)
constexpr OUStringLiteral first
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
const mdds::mtv::element_t element_type_celltextattr
Definition: mtvelements.hxx:45
mdds::mtv::soa::multi_type_vector< CellStoreTraits > CellStoreType
Cell container.
ScRefCellValue toRefCell(const sc::CellStoreType::const_iterator &itPos, size_t nOffset)
mdds::mtv::default_element_block< element_type_celltextattr, CellTextAttr > celltextattr_block
Definition: mtvelements.hxx:64
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:108
sal_Int32 SCROW
Definition: types.hxx:17