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.
44  checkEndRow();
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 
59  checkEndRow();
60  return;
61  }
62 
63  // Reached the end.
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 
90 void 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;
137  getDataIterators(0);
138  checkEndRow();
139  return;
140  }
141 
142  // Not found.
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 
170 namespace sc {
171 
172 ColumnIterator::ColumnIterator( const CellStoreType& rCells, SCROW nRow1, SCROW nRow2 ) :
173  maPos(rCells.position(nRow1)),
174  maPosEnd(rCells.position(maPos.first, nRow2)),
175  mbComplete(false)
176 {
177 }
178 
180 
182 {
183  if ( maPos == maPosEnd)
184  mbComplete = true;
185  else
186  maPos = CellStoreType::next_position(maPos);
187 }
188 
190 {
191  return CellStoreType::logical_position(maPos);
192 }
193 
195 {
196  return !mbComplete;
197 }
198 
199 mdds::mtv::element_t ColumnIterator::getType() const
200 {
201  return maPos.first->type;
202 }
203 
205 {
206  return toRefCell(maPos.first, maPos.second);
207 }
208 
209 }
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sc::CellTextAttrStoreType::iterator miBlockEnd
bool hasCell() const
SCROW Row() const
Definition: address.hxx:262
size_t mnEnd
Definition: cellvalues.cxx:24
void setValue(sal_uInt16 nVal)
const mdds::mtv::element_t element_type_celltextattr
Definition: mtvelements.hxx:46
sc::celltextattr_block::iterator miDataCur
SCROW getRow() const
ScRefCellValue getCell() const
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
sc::celltextattr_block::iterator miDataEnd
mdds::multi_type_vector< CellFunc, CellStoreEvent > CellStoreType
def position
sc::CellTextAttrStoreType::iterator miBlockCur
mdds::mtv::element_t getType() const
void init(const ScDocument &rDoc, SCROW nStartRow, SCROW nEndRow)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
TableContainer maTabs
Definition: document.hxx:386
sal_uInt16 getValue() const
SCTAB Tab() const
Definition: address.hxx:271
mdds::mtv::default_element_block< element_type_celltextattr, CellTextAttr > celltextattr_block
Definition: mtvelements.hxx:63
sc::CellTextAttrStoreType maCellTextAttrs
Definition: column.hxx:118
ColumnIterator(const CellStoreType &rCells, SCROW nRow1, SCROW nRow2)
SCCOL Col() const
Definition: address.hxx:267
sal_Int32 SCROW
Definition: types.hxx:18
bool ValidRow(SCROW nRow) const
Definition: document.hxx:879
CellStoreType::const_position_type maPosEnd
CellStoreType::const_position_type maPos
void getDataIterators(size_t nOffsetInBlock)
ScRefCellValue toRefCell(const sc::CellStoreType::const_iterator &itPos, size_t nOffset)
ScColumnTextWidthIterator(const ScColumnTextWidthIterator &)=delete
const char first[]