1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <mtvelements.hxx>
11 #include <document.hxx>
12 #include <cellvalue.hxx>
20 CellStoreEvent::CellStoreEvent() : mpCol(nullptr) {}
22 CellStoreEvent::CellStoreEvent(ScColumn
* pCol
) : mpCol(pCol
) {}
24 void CellStoreEvent::element_block_acquired(const mdds::mtv::base_element_block
* block
)
29 switch (mdds::mtv::get_block_type(*block
))
31 case sc::element_type_formula
:
32 ++mpCol
->mnBlkCountFormula
;
34 case sc::element_type_cellnote
:
35 ++mpCol
->mnBlkCountCellNotes
;
42 void CellStoreEvent::element_block_released(const mdds::mtv::base_element_block
* block
)
47 switch (mdds::mtv::get_block_type(*block
))
49 case sc::element_type_formula
:
50 --mpCol
->mnBlkCountFormula
;
52 case sc::element_type_cellnote
:
53 --mpCol
->mnBlkCountCellNotes
;
60 void CellStoreEvent::stop()
65 void CellStoreEvent::swap(CellStoreEvent
& other
)
67 std::swap(mpCol
, other
.mpCol
);
70 const ScColumn
* CellStoreEvent::getColumn() const
75 ColumnBlockPositionSet::ColumnBlockPositionSet(ScDocument
& rDoc
) : mrDoc(rDoc
) {}
77 ColumnBlockPosition
* ColumnBlockPositionSet::getBlockPosition(SCTAB nTab
, SCCOL nCol
)
79 std::scoped_lock
aGuard(maMtxTables
);
81 TablesType::iterator itTab
= maTables
.find(nTab
);
82 if (itTab
== maTables
.end())
84 std::pair
<TablesType::iterator
,bool> r
=
85 maTables
.emplace(nTab
, ColumnsType());
93 ColumnsType
& rCols
= itTab
->second
;
95 ColumnsType::iterator it
= rCols
.find(nCol
);
96 if (it
!= rCols
.end())
97 // Block position for this column has already been fetched.
100 std::pair
<ColumnsType::iterator
,bool> r
=
101 rCols
.emplace(nCol
, ColumnBlockPosition());
109 if (!mrDoc
.InitColumnBlockPosition(it
->second
, nTab
, nCol
))
115 void ColumnBlockPositionSet::clear()
117 std::scoped_lock
aGuard(maMtxTables
);
121 struct TableColumnBlockPositionSet::Impl
123 typedef std::unordered_map
<SCCOL
, ColumnBlockPosition
> ColumnsType
;
126 ColumnsType maColumns
;
128 Impl() : mpTab(nullptr) {}
131 TableColumnBlockPositionSet::TableColumnBlockPositionSet( ScDocument
& rDoc
, SCTAB nTab
) :
132 mpImpl(std::make_unique
<Impl
>())
134 mpImpl
->mpTab
= rDoc
.FetchTable(nTab
);
138 std::ostringstream os
;
139 os
<< "Passed table index " << nTab
<< " is invalid.";
140 throw std::invalid_argument(os
.str());
144 TableColumnBlockPositionSet::TableColumnBlockPositionSet( TableColumnBlockPositionSet
&& rOther
) noexcept
:
145 mpImpl(std::move(rOther
.mpImpl
)) {}
147 TableColumnBlockPositionSet::~TableColumnBlockPositionSet() {}
149 ColumnBlockPosition
* TableColumnBlockPositionSet::getBlockPosition( SCCOL nCol
)
151 using ColumnsType
= Impl::ColumnsType
;
153 ColumnsType::iterator it
= mpImpl
->maColumns
.find(nCol
);
155 if (it
!= mpImpl
->maColumns
.end())
156 // Block position for this column has already been fetched.
159 std::pair
<ColumnsType::iterator
,bool> r
=
160 mpImpl
->maColumns
.emplace(nCol
, ColumnBlockPosition());
168 if (!mpImpl
->mpTab
->InitColumnBlockPosition(it
->second
, nCol
))
174 void TableColumnBlockPositionSet::invalidate()
176 mpImpl
->maColumns
.clear();
179 ScRefCellValue
toRefCell( const sc::CellStoreType::const_iterator
& itPos
, size_t nOffset
)
183 case sc::element_type_numeric
:
185 return ScRefCellValue(sc::numeric_block::get_value(*itPos
->data
, nOffset
));
186 case sc::element_type_string
:
188 return ScRefCellValue(&sc::string_block::at(*itPos
->data
, nOffset
));
189 case sc::element_type_edittext
:
191 return ScRefCellValue(sc::edittext_block::get_value(*itPos
->data
, nOffset
));
192 case sc::element_type_formula
:
194 return ScRefCellValue(sc::formula_block::get_value(*itPos
->data
, nOffset
));
199 return ScRefCellValue();
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */