Bump version to 6.4-15
[LibreOffice.git] / sc / inc / columnspanset.hxx
blob99a99ee935c0bba7f612a11ffc1c2b028f978ce0
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 #ifndef INCLUDED_SC_INC_COLUMNSPANSET_HXX
11 #define INCLUDED_SC_INC_COLUMNSPANSET_HXX
13 #include "address.hxx"
15 #include <vector>
16 #include <mdds/flat_segment_tree.hpp>
18 class ScDocument;
19 class ScColumn;
20 class ScMarkData;
21 class ScRangeList;
23 namespace sc {
25 struct ColumnBlockConstPosition;
26 class SingleColumnSpanSet;
28 struct RowSpan
30 SCROW const mnRow1;
31 SCROW const mnRow2;
33 RowSpan(SCROW nRow1, SCROW nRow2);
36 struct SC_DLLPUBLIC ColRowSpan
38 SCCOLROW mnStart;
39 SCCOLROW mnEnd;
41 ColRowSpan(SCCOLROW nStart, SCCOLROW nEnd);
44 /**
45 * Structure that stores segments of boolean flags per column, and perform
46 * custom action on those segments.
48 class ColumnSpanSet
50 public:
51 typedef mdds::flat_segment_tree<SCROW, bool> ColumnSpansType;
53 private:
54 struct ColumnType
56 ColumnSpansType maSpans;
57 ColumnSpansType::const_iterator miPos;
59 ColumnType(SCROW nStart, SCROW nEnd, bool bInit);
62 typedef std::vector<std::unique_ptr<ColumnType>> TableType;
64 std::vector<std::unique_ptr<TableType>> maTables;
65 bool const mbInit;
67 ColumnType& getColumn(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol);
69 public:
70 class Action
72 public:
73 virtual ~Action() = 0;
74 virtual void startColumn(SCTAB nTab, SCCOL nCol);
75 virtual void execute(const ScAddress& rPos, SCROW nLength, bool bVal) = 0;
78 class ColumnAction
80 public:
81 virtual ~ColumnAction() = 0;
82 virtual void startColumn(ScColumn* pCol) = 0;
83 virtual void execute(SCROW nRow1, SCROW nRow2, bool bVal) = 0;
84 virtual void executeSum(SCROW, SCROW, bool, double& ) { return; } ;
87 ColumnSpanSet(bool bInit);
88 ColumnSpanSet(const ColumnSpanSet&) = delete;
89 const ColumnSpanSet& operator=(const ColumnSpanSet&) = delete;
90 ~ColumnSpanSet();
92 void set(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol, SCROW nRow, bool bVal);
93 void set(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2, bool bVal);
94 void set(const ScDocument& rDoc, const ScRange& rRange, bool bVal);
96 void set(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol, const SingleColumnSpanSet& rSingleSet, bool bVal );
98 /**
99 * Scan specified range in a specified sheet and mark all non-empty cells
100 * with specified boolean value.
102 void scan(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bVal);
104 void executeAction(Action& ac) const;
105 void executeColumnAction(ScDocument& rDoc, ColumnAction& ac) const;
109 * Keep track of spans in a single column only.
111 class SingleColumnSpanSet
113 public:
114 typedef mdds::flat_segment_tree<SCROW, bool> ColumnSpansType;
116 typedef std::vector<RowSpan> SpansType;
118 SingleColumnSpanSet();
121 * Scan an entire column and tag all non-empty cell positions.
123 void scan(const ScColumn& rColumn);
126 * Scan a column between specified range, and tag all non-empty cell
127 * positions.
129 void scan(const ScColumn& rColumn, SCROW nStart, SCROW nEnd);
131 void scan(
132 ColumnBlockConstPosition& rBlockPos, const ScColumn& rColumn, SCROW nStart, SCROW nEnd);
135 * Scan all marked data and tag all marked segments in specified column.
137 void scan(const ScMarkData& rMark, SCTAB nTab, SCCOL nCol);
139 void scan(const ScRangeList& rRanges, SCTAB nTab, SCCOL nCol);
141 void set(SCROW nRow1, SCROW nRow2, bool bVal);
143 void getRows(std::vector<SCROW> &rRows) const;
145 void getSpans(SpansType& rSpans) const;
147 void swap( SingleColumnSpanSet& r );
149 /** Whether there isn't any row tagged. */
150 bool empty() const;
152 private:
153 ColumnSpansType maSpans;
157 * Optimized ColumnSpanSet version that operates on a single ScRange.
159 class RangeColumnSpanSet
161 public:
162 RangeColumnSpanSet( const ScRange& spanRange )
163 : range( spanRange ) {}
164 void executeColumnAction(ScDocument& rDoc, sc::ColumnSpanSet::ColumnAction& ac) const;
165 void executeColumnAction(ScDocument& rDoc, sc::ColumnSpanSet::ColumnAction& ac, double& fMem) const;
166 private:
167 ScRange range;
173 #endif
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */