LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / inc / mtvelements.hxx
blob72f65d2b72ffa57d0f2991ad63fb972aa3894436
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 "formulacell.hxx"
13 #include <svl/broadcast.hxx>
14 #include <svl/sharedstring.hxx>
15 #include <editeng/editobj.hxx>
16 #include "calcmacros.hxx"
17 #include "postit.hxx"
18 #include "SparklineCell.hxx"
19 #include "celltextattr.hxx"
21 #if DEBUG_COLUMN_STORAGE
22 #ifdef NDEBUG
23 #undef NDEBUG
24 #endif
25 #define MDDS_MULTI_TYPE_VECTOR_DEBUG 1
26 #endif
28 #include <mdds/multi_type_vector/macro.hpp>
29 #include <mdds/multi_type_vector/soa/main.hpp>
30 #include <mdds/multi_type_vector/custom_func1.hpp>
31 #include <mdds/multi_type_vector/custom_func3.hpp>
33 #include <unordered_map>
34 #include <memory>
35 #include <mutex>
37 class ScDocument;
38 class ScColumn;
39 struct ScRefCellValue;
41 namespace sc {
43 /// Custom element type IDs for multi_type_vector.
45 const mdds::mtv::element_t element_type_broadcaster = mdds::mtv::element_type_user_start;
46 const mdds::mtv::element_t element_type_celltextattr = mdds::mtv::element_type_user_start + 1;
48 const mdds::mtv::element_t element_type_string = mdds::mtv::element_type_user_start + 2;
49 const mdds::mtv::element_t element_type_edittext = mdds::mtv::element_type_user_start + 3;
50 const mdds::mtv::element_t element_type_formula = mdds::mtv::element_type_user_start + 4;
52 const mdds::mtv::element_t element_type_cellnote = mdds::mtv::element_type_user_start + 5;
53 const mdds::mtv::element_t element_type_sparkline = mdds::mtv::element_type_user_start + 6;
55 /// Mapped standard element types (for convenience).
56 const mdds::mtv::element_t element_type_numeric = mdds::mtv::element_type_double;
57 const mdds::mtv::element_t element_type_empty = mdds::mtv::element_type_empty;
58 const mdds::mtv::element_t element_type_uint16 = mdds::mtv::element_type_uint16;
60 /// Custom element blocks.
62 typedef mdds::mtv::noncopyable_managed_element_block<element_type_sparkline, sc::SparklineCell> sparkline_block;
63 typedef mdds::mtv::noncopyable_managed_element_block<element_type_cellnote, ScPostIt> cellnote_block;
64 typedef mdds::mtv::noncopyable_managed_element_block<element_type_broadcaster, SvtBroadcaster> broadcaster_block;
65 typedef mdds::mtv::default_element_block<element_type_celltextattr, CellTextAttr> celltextattr_block;
66 typedef mdds::mtv::default_element_block<element_type_string, svl::SharedString> string_block;
67 typedef mdds::mtv::noncopyable_managed_element_block<element_type_edittext, EditTextObject> edittext_block;
68 typedef mdds::mtv::noncopyable_managed_element_block<element_type_formula, ScFormulaCell> formula_block;
70 /// Mapped standard element blocks (for convenience).
71 typedef mdds::mtv::double_element_block numeric_block;
72 typedef mdds::mtv::uint16_element_block uint16_block;
74 } // end sc namespace
76 /// CAUTION! The following defines must be in the same namespace as the respective type.
77 /// For example sc types like sc::CellTextAttr, ScFormulaCell in global namespace.
78 namespace sc {
79 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr, element_type_celltextattr, CellTextAttr(), celltextattr_block)
80 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SparklineCell, sc::element_type_sparkline, nullptr, sc::sparkline_block)
83 /// These need to be in global namespace just like their respective types are.
84 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScPostIt, sc::element_type_cellnote, nullptr, sc::cellnote_block)
85 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SvtBroadcaster, sc::element_type_broadcaster, nullptr, sc::broadcaster_block)
86 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScFormulaCell, sc::element_type_formula, nullptr, sc::formula_block)
87 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(EditTextObject, sc::element_type_edittext, nullptr, sc::edittext_block)
89 namespace svl {
90 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(SharedString, sc::element_type_string, SharedString(), sc::string_block)
93 namespace sc {
95 class CellStoreEvent
97 ScColumn* mpCol;
98 public:
99 CellStoreEvent();
100 CellStoreEvent(ScColumn* pCol);
102 void element_block_acquired(const mdds::mtv::base_element_block* block);
103 void element_block_released(const mdds::mtv::base_element_block* block);
105 /** Stop processing events. */
106 void stop();
108 void swap(CellStoreEvent& other);
110 const ScColumn* getColumn() const;
113 struct CellStoreTrait
115 using event_func = CellStoreEvent;
116 static constexpr mdds::mtv::lu_factor_t loop_unrolling = mdds::mtv::lu_factor_t::lu16;
119 /// Sparkline container
120 typedef mdds::mtv::custom_block_func1<sc::sparkline_block> CSparklineFunction;
121 typedef mdds::mtv::soa::multi_type_vector<CSparklineFunction> SparklineStoreType;
123 /// Cell note container
124 typedef mdds::mtv::custom_block_func1<sc::cellnote_block> CNoteFunc;
125 typedef mdds::mtv::soa::multi_type_vector<CNoteFunc> CellNoteStoreType;
127 /// Broadcaster storage container
128 typedef mdds::mtv::custom_block_func1<sc::broadcaster_block> BCBlkFunc;
129 typedef mdds::mtv::soa::multi_type_vector<BCBlkFunc> BroadcasterStoreType;
131 /// Cell text attribute container.
132 typedef mdds::mtv::custom_block_func1<sc::celltextattr_block> CTAttrFunc;
133 typedef mdds::mtv::soa::multi_type_vector<CTAttrFunc> CellTextAttrStoreType;
135 /// Cell container
136 typedef mdds::mtv::custom_block_func3<sc::string_block, sc::edittext_block, sc::formula_block> CellFunc;
137 typedef mdds::mtv::soa::multi_type_vector<CellFunc, CellStoreTrait> CellStoreType;
140 * Store position data for column array storage.
142 struct ColumnBlockPosition
144 CellNoteStoreType::iterator miCellNotePos;
145 SparklineStoreType::iterator miSparklinePos;
146 BroadcasterStoreType::iterator miBroadcasterPos;
147 CellTextAttrStoreType::iterator miCellTextAttrPos;
148 CellStoreType::iterator miCellPos;
150 ColumnBlockPosition(): miCellPos() {}
153 struct ColumnBlockConstPosition
155 CellNoteStoreType::const_iterator miCellNotePos;
156 SparklineStoreType::const_iterator miSparklinePos;
157 CellTextAttrStoreType::const_iterator miCellTextAttrPos;
158 CellStoreType::const_iterator miCellPos;
160 ColumnBlockConstPosition(): miCellPos() {}
163 class ColumnBlockPositionSet
165 typedef std::unordered_map<SCCOL, ColumnBlockPosition> ColumnsType;
166 typedef std::unordered_map<SCTAB, ColumnsType> TablesType;
168 ScDocument& mrDoc;
169 TablesType maTables;
170 std::mutex maMtxTables;
172 public:
173 ColumnBlockPositionSet(ScDocument& rDoc);
175 ColumnBlockPosition* getBlockPosition(SCTAB nTab, SCCOL nCol);
177 void clear();
181 * Set of column block positions only for one table.
183 class TableColumnBlockPositionSet
185 struct Impl;
186 std::unique_ptr<Impl> mpImpl;
188 public:
189 TableColumnBlockPositionSet( ScDocument& rDoc, SCTAB nTab );
190 TableColumnBlockPositionSet(TableColumnBlockPositionSet&& rOther) noexcept;
191 ~TableColumnBlockPositionSet();
193 ColumnBlockPosition* getBlockPosition( SCCOL nCol );
194 void invalidate(); // discards cached positions
197 ScRefCellValue toRefCell( const sc::CellStoreType::const_iterator& itPos, size_t nOffset );
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */