Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / cellvalues.hxx
blob352a152ec8919942c14a8133c502327735f24438
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/.
8 */
10 #pragma once
12 #include "address.hxx"
13 #include <memory>
14 #include <vector>
16 class ScColumn;
17 class ScFormulaCell;
18 class EditTextObject;
20 namespace svl
22 class SharedString;
25 namespace sc
27 struct CellValuesImpl;
29 struct CellValueSpan
31 SCROW mnRow1;
32 SCROW mnRow2;
34 CellValueSpan(SCROW nRow1, SCROW nRow2);
37 /**
38 * Think of this as a mini-ScColumn like storage that only stores cell
39 * values in a column.
41 class CellValues
43 std::unique_ptr<CellValuesImpl> mpImpl;
45 CellValues(const CellValues&) = delete;
46 CellValues& operator=(const CellValues&) = delete;
48 public:
49 CellValues();
50 ~CellValues();
52 /**
53 * Transfer values from specified column. The transferred segment in the
54 * source column becomes empty after this call.
56 * @param rCol source column to transfer values from.
57 * @param nRow top row position in the source column.
58 * @param nLen length of the segment to transfer.
60 void transferFrom(ScColumn& rCol, SCROW nRow, size_t nLen);
62 void copyTo(ScColumn& rCol, SCROW nRow) const;
63 void swapNonEmpty(ScColumn& rCol);
65 void assign(const std::vector<double>& rVals);
66 void assign(const std::vector<ScFormulaCell*>& rVals);
68 size_t size() const;
70 void reset(size_t nSize);
71 void setValue(size_t nRow, double fVal);
72 void setValue(size_t nRow, const svl::SharedString& rStr);
73 /// Takes ownership of pEditText.
74 void setValue(size_t nRow, std::unique_ptr<EditTextObject> pEditText);
76 void swap(CellValues& r);
78 std::vector<CellValueSpan> getNonEmptySpans() const;
80 private:
81 void copyCellsTo(ScColumn& rCol, SCROW nRow) const;
82 void copyCellTextAttrsTo(ScColumn& rCol, SCROW nRow) const;
85 /**
86 * Stores cell values for multiple tables.
88 class TableValues
90 struct Impl;
92 std::unique_ptr<Impl> mpImpl;
94 TableValues(const TableValues&) = delete;
95 TableValues& operator=(const TableValues&) = delete;
97 public:
98 TableValues();
99 TableValues(const ScRange& rRange);
100 ~TableValues();
102 const ScRange& getRange() const;
105 * Swap the entire column.
107 void swap(SCTAB nTab, SCCOL nCol, CellValues& rColValue);
110 * Swap non-empty blocks with the column storage.
112 void swapNonEmpty(SCTAB nTab, SCCOL nCol, ScColumn& rCol);
114 std::vector<CellValueSpan> getNonEmptySpans(SCTAB nTab, SCCOL nCol) const;
116 void swap(TableValues& rOther);
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */