LibreOffice Module sc (master) 1
mtvelements.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 <mtvelements.hxx>
11#include <document.hxx>
12#include <cellvalue.hxx>
13#include <column.hxx>
14#include <table.hxx>
15
16#include <sstream>
17
18namespace sc {
19
20CellStoreEvent::CellStoreEvent() : mpCol(nullptr) {}
21
23
24void CellStoreEvent::element_block_acquired(const mdds::mtv::base_element_block* block)
25{
26 if (!mpCol)
27 return;
28
29 switch (mdds::mtv::get_block_type(*block))
30 {
33 break;
34 default:
35 ;
36 }
37}
38
39void CellStoreEvent::element_block_released(const mdds::mtv::base_element_block* block)
40{
41 if (!mpCol)
42 return;
43
44 switch (mdds::mtv::get_block_type(*block))
45 {
48 break;
49 default:
50 ;
51 }
52}
53
55{
56 mpCol = nullptr;
57}
58
60{
61 std::swap(mpCol, other.mpCol);
62}
63
65{
66 return mpCol;
67}
68
70
72{
73 std::scoped_lock aGuard(maMtxTables);
74
75 TablesType::iterator itTab = maTables.find(nTab);
76 if (itTab == maTables.end())
77 {
78 std::pair<TablesType::iterator,bool> r =
79 maTables.emplace(nTab, ColumnsType());
80 if (!r.second)
81 // insertion failed.
82 return nullptr;
83
84 itTab = r.first;
85 }
86
87 ColumnsType& rCols = itTab->second;
88
89 ColumnsType::iterator it = rCols.find(nCol);
90 if (it != rCols.end())
91 // Block position for this column has already been fetched.
92 return &it->second;
93
94 std::pair<ColumnsType::iterator,bool> r =
95 rCols.emplace(nCol, ColumnBlockPosition());
96
97 if (!r.second)
98 // insertion failed.
99 return nullptr;
100
101 it = r.first;
102
103 if (!mrDoc.InitColumnBlockPosition(it->second, nTab, nCol))
104 return nullptr;
105
106 return &it->second;
107}
108
110{
111 std::scoped_lock aGuard(maMtxTables);
112 maTables.clear();
113}
114
116{
117 typedef std::unordered_map<SCCOL, ColumnBlockPosition> ColumnsType;
118
121
122 Impl() : mpTab(nullptr) {}
123};
124
126 mpImpl(std::make_unique<Impl>())
127{
128 mpImpl->mpTab = rDoc.FetchTable(nTab);
129
130 if (!mpImpl->mpTab)
131 {
132 std::ostringstream os;
133 os << "Passed table index " << nTab << " is invalid.";
134 throw std::invalid_argument(os.str());
135 }
136}
137
139 mpImpl(std::move(rOther.mpImpl)) {}
140
142
144{
145 using ColumnsType = Impl::ColumnsType;
146
147 ColumnsType::iterator it = mpImpl->maColumns.find(nCol);
148
149 if (it != mpImpl->maColumns.end())
150 // Block position for this column has already been fetched.
151 return &it->second;
152
153 std::pair<ColumnsType::iterator,bool> r =
154 mpImpl->maColumns.emplace(nCol, ColumnBlockPosition());
155
156 if (!r.second)
157 // insertion failed.
158 return nullptr;
159
160 it = r.first;
161
162 if (!mpImpl->mpTab->InitColumnBlockPosition(it->second, nCol))
163 return nullptr;
164
165 return &it->second;
166}
167
169{
170 mpImpl->maColumns.clear();
171}
172
173ScRefCellValue toRefCell( const sc::CellStoreType::const_iterator& itPos, size_t nOffset )
174{
175 switch (itPos->type)
176 {
178 // Numeric cell
179 return ScRefCellValue(sc::numeric_block::get_value(*itPos->data, nOffset));
181 // String cell
182 return ScRefCellValue(&sc::string_block::at(*itPos->data, nOffset));
184 // Edit cell
185 return ScRefCellValue(sc::edittext_block::get_value(*itPos->data, nOffset));
187 // Formula cell
188 return ScRefCellValue(sc::formula_block::get_value(*itPos->data, nOffset));
189 default:
190 ;
191 }
192
193 return ScRefCellValue();
194}
195
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t mnBlkCountFormula
Definition: column.hxx:201
ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2544
SC_DLLPUBLIC bool InitColumnBlockPosition(sc::ColumnBlockPosition &rBlockPos, SCTAB nTab, SCCOL nCol)
Definition: document.cxx:2662
const ScColumn * getColumn() const
Definition: mtvelements.cxx:64
void element_block_released(const mdds::mtv::base_element_block *block)
Definition: mtvelements.cxx:39
void swap(CellStoreEvent &other)
Definition: mtvelements.cxx:59
void stop()
Stop processing events.
Definition: mtvelements.cxx:54
void element_block_acquired(const mdds::mtv::base_element_block *block)
Definition: mtvelements.cxx:24
ColumnBlockPosition * getBlockPosition(SCTAB nTab, SCCOL nCol)
Definition: mtvelements.cxx:71
std::unordered_map< SCCOL, ColumnBlockPosition > ColumnsType
ColumnBlockPositionSet(ScDocument &rDoc)
Definition: mtvelements.cxx:69
Set of column block positions only for one table.
ColumnBlockPosition * getBlockPosition(SCCOL nCol)
std::unique_ptr< Impl > mpImpl
TableColumnBlockPositionSet(ScDocument &rDoc, SCTAB nTab)
CAUTION! The following defines must be in the same namespace as the respective type.
const mdds::mtv::element_t element_type_edittext
Definition: mtvelements.hxx:49
const mdds::mtv::element_t element_type_formula
Definition: mtvelements.hxx:50
ScRefCellValue toRefCell(const sc::CellStoreType::const_iterator &itPos, size_t nOffset)
const mdds::mtv::element_t element_type_numeric
Mapped standard element types (for convenience).
Definition: mtvelements.hxx:56
const mdds::mtv::element_t element_type_string
Definition: mtvelements.hxx:48
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:108
Store position data for column array storage.
std::unordered_map< SCCOL, ColumnBlockPosition > ColumnsType
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21