Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/mtvelements.hxx
Line
Count
Source
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
#pragma once
11
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"
20
21
#if DEBUG_COLUMN_STORAGE
22
#ifdef NDEBUG
23
#undef NDEBUG
24
#endif
25
#define MDDS_MULTI_TYPE_VECTOR_DEBUG 1
26
#endif
27
28
#include <mdds/multi_type_vector/macro.hpp>
29
#include <mdds/multi_type_vector/soa/main.hpp>
30
#include <mdds/multi_type_vector/block_funcs.hpp>
31
32
#include <unordered_map>
33
#include <memory>
34
#include <mutex>
35
36
class ScDocument;
37
class ScColumn;
38
struct ScRefCellValue;
39
40
namespace sc {
41
42
/// Custom element type IDs for multi_type_vector.
43
44
const mdds::mtv::element_t element_type_broadcaster = mdds::mtv::element_type_user_start;
45
const mdds::mtv::element_t element_type_celltextattr = mdds::mtv::element_type_user_start + 1;
46
47
const mdds::mtv::element_t element_type_string = mdds::mtv::element_type_user_start + 2;
48
const mdds::mtv::element_t element_type_edittext = mdds::mtv::element_type_user_start + 3;
49
const mdds::mtv::element_t element_type_formula = mdds::mtv::element_type_user_start + 4;
50
51
const mdds::mtv::element_t element_type_cellnote = mdds::mtv::element_type_user_start + 5;
52
const mdds::mtv::element_t element_type_sparkline = mdds::mtv::element_type_user_start + 6;
53
54
/// Mapped standard element types (for convenience).
55
const mdds::mtv::element_t element_type_numeric = mdds::mtv::element_type_double;
56
const mdds::mtv::element_t element_type_empty = mdds::mtv::element_type_empty;
57
const mdds::mtv::element_t element_type_uint16 = mdds::mtv::element_type_uint16;
58
59
/// Custom element blocks.
60
61
typedef mdds::mtv::noncopyable_managed_element_block<element_type_sparkline, sc::SparklineCell> sparkline_block;
62
typedef mdds::mtv::noncopyable_managed_element_block<element_type_cellnote, ScPostIt> cellnote_block;
63
typedef mdds::mtv::noncopyable_managed_element_block<element_type_broadcaster, SvtBroadcaster> broadcaster_block;
64
typedef mdds::mtv::default_element_block<element_type_celltextattr, CellTextAttr> celltextattr_block;
65
typedef mdds::mtv::default_element_block<element_type_string, svl::SharedString> string_block;
66
typedef mdds::mtv::noncopyable_managed_element_block<element_type_edittext, EditTextObject> edittext_block;
67
typedef mdds::mtv::noncopyable_managed_element_block<element_type_formula, ScFormulaCell> formula_block;
68
69
/// Mapped standard element blocks (for convenience).
70
typedef mdds::mtv::double_element_block numeric_block;
71
typedef mdds::mtv::uint16_element_block uint16_block;
72
73
} // end sc namespace
74
75
/// CAUTION! The following defines must be in the same namespace as the respective type.
76
/// For example sc types like sc::CellTextAttr, ScFormulaCell in global namespace.
77
namespace sc {
78
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr, element_type_celltextattr, CellTextAttr(), celltextattr_block)
79
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SparklineCell, sc::element_type_sparkline, nullptr, sc::sparkline_block)
80
}
81
82
/// These need to be in global namespace just like their respective types are.
83
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScPostIt, sc::element_type_cellnote, nullptr, sc::cellnote_block)
84
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SvtBroadcaster, sc::element_type_broadcaster, nullptr, sc::broadcaster_block)
85
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(ScFormulaCell, sc::element_type_formula, nullptr, sc::formula_block)
86
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(EditTextObject, sc::element_type_edittext, nullptr, sc::edittext_block)
87
88
namespace svl {
89
MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(SharedString, sc::element_type_string, SharedString(), sc::string_block)
90
}
91
92
namespace sc {
93
94
class CellStoreEvent
95
{
96
    ScColumn* mpCol;
97
public:
98
    CellStoreEvent();
99
    CellStoreEvent(ScColumn* pCol);
100
101
    void element_block_acquired(const mdds::mtv::base_element_block* block);
102
    void element_block_released(const mdds::mtv::base_element_block* block);
103
104
    /** Stop processing events. */
105
    void stop();
106
107
    void swap(CellStoreEvent& other);
108
109
    const ScColumn* getColumn() const;
110
};
111
112
struct SparklineTraits : public mdds::mtv::default_traits
113
{
114
    using block_funcs = mdds::mtv::element_block_funcs<sc::sparkline_block>;
115
};
116
117
struct CellNoteTraits : public mdds::mtv::default_traits
118
{
119
    using event_func = CellStoreEvent;
120
    using block_funcs = mdds::mtv::element_block_funcs<sc::cellnote_block>;
121
};
122
123
struct BroadcasterTraits : public mdds::mtv::default_traits
124
{
125
    using block_funcs = mdds::mtv::element_block_funcs<sc::broadcaster_block>;
126
};
127
128
struct CellTextAttrTraits : public mdds::mtv::default_traits
129
{
130
    using block_funcs = mdds::mtv::element_block_funcs<sc::celltextattr_block>;
131
};
132
133
struct CellStoreTraits : public mdds::mtv::default_traits
134
{
135
    using event_func = CellStoreEvent;
136
    using block_funcs = mdds::mtv::element_block_funcs<
137
        numeric_block, sc::string_block, sc::edittext_block, sc::formula_block>;
138
};
139
140
/// Sparkline container
141
typedef mdds::mtv::soa::multi_type_vector<SparklineTraits> SparklineStoreType;
142
143
/// Cell note container
144
typedef mdds::mtv::soa::multi_type_vector<CellNoteTraits> CellNoteStoreType;
145
146
/// Broadcaster storage container
147
typedef mdds::mtv::soa::multi_type_vector<BroadcasterTraits> BroadcasterStoreType;
148
149
/// Cell text attribute container.
150
typedef mdds::mtv::soa::multi_type_vector<CellTextAttrTraits> CellTextAttrStoreType;
151
152
/// Cell container
153
typedef mdds::mtv::soa::multi_type_vector<CellStoreTraits> CellStoreType;
154
155
/**
156
 * Store position data for column array storage.
157
 */
158
struct ColumnBlockPosition
159
{
160
    CellNoteStoreType::iterator miCellNotePos;
161
    SparklineStoreType::iterator miSparklinePos;
162
    BroadcasterStoreType::iterator miBroadcasterPos;
163
    CellTextAttrStoreType::iterator miCellTextAttrPos;
164
    CellStoreType::iterator miCellPos;
165
166
4.72M
    ColumnBlockPosition(): miCellPos() {}
167
};
168
169
struct ColumnBlockConstPosition
170
{
171
    CellNoteStoreType::const_iterator miCellNotePos;
172
    SparklineStoreType::const_iterator miSparklinePos;
173
    CellTextAttrStoreType::const_iterator miCellTextAttrPos;
174
    CellStoreType::const_iterator miCellPos;
175
176
10.9k
    ColumnBlockConstPosition(): miCellPos() {}
177
};
178
179
class ColumnBlockPositionSet
180
{
181
    typedef std::unordered_map<SCCOL, ColumnBlockPosition> ColumnsType;
182
    typedef std::unordered_map<SCTAB, ColumnsType> TablesType;
183
184
    ScDocument& mrDoc;
185
    TablesType maTables;
186
    std::mutex maMtxTables;
187
188
public:
189
    ColumnBlockPositionSet(ScDocument& rDoc);
190
191
    ColumnBlockPosition* getBlockPosition(SCTAB nTab, SCCOL nCol);
192
193
    void clear();
194
};
195
196
/**
197
 * Set of column block positions only for one table.
198
 */
199
class TableColumnBlockPositionSet
200
{
201
    struct Impl;
202
    std::unique_ptr<Impl> mpImpl;
203
204
public:
205
    TableColumnBlockPositionSet( ScDocument& rDoc, SCTAB nTab );
206
    TableColumnBlockPositionSet(TableColumnBlockPositionSet&& rOther) noexcept;
207
    ~TableColumnBlockPositionSet();
208
209
    ColumnBlockPosition* getBlockPosition( SCCOL nCol );
210
    void invalidate(); // discards cached positions
211
};
212
213
ScRefCellValue toRefCell( const sc::CellStoreType::const_iterator& itPos, size_t nOffset );
214
215
}
216
217
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */