/src/libreoffice/sc/inc/rangelst.hxx
Line | Count | Source (jump to first uncovered line) |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include "global.hxx" |
23 | | #include "address.hxx" |
24 | | #include <ostream> |
25 | | #include <vector> |
26 | | #include <tools/ref.hxx> |
27 | | #include <sal/types.h> |
28 | | |
29 | | class ScDocument; |
30 | | |
31 | | |
32 | | class SAL_WARN_UNUSED SC_DLLPUBLIC ScRangeList final : public SvRefBase |
33 | | { |
34 | | public: |
35 | | ScRangeList(); |
36 | | ScRangeList( const ScRangeList& rList ); |
37 | | ScRangeList(ScRangeList&& rList) noexcept; |
38 | | ScRangeList( const ScRange& rRange ); |
39 | | virtual ~ScRangeList() override; |
40 | | |
41 | | ScRangeList& operator=(const ScRangeList& rList); |
42 | | ScRangeList& operator=(ScRangeList&& rList) noexcept; |
43 | | |
44 | | ScRefFlags Parse( std::u16string_view, const ScDocument&, |
45 | | formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO, |
46 | | SCTAB nDefaultTab = 0, sal_Unicode cDelimiter = 0 ); |
47 | | |
48 | | void Format( OUString&, ScRefFlags nFlags, const ScDocument&, |
49 | | formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_OOO, |
50 | | sal_Unicode cDelimiter = 0, bool bFullAddressNotation = false ) const; |
51 | | |
52 | | void Join( const ScRange&, bool bIsInList = false ); |
53 | | |
54 | | bool UpdateReference( UpdateRefMode, const ScDocument&, |
55 | | const ScRange& rWhere, |
56 | | SCCOL nDx, |
57 | | SCROW nDy, |
58 | | SCTAB nDz |
59 | | ); |
60 | | |
61 | | void InsertRow( SCTAB nTab, SCCOL nColStart, SCCOL nColEnd, SCROW nRowPos, SCSIZE nSize ); |
62 | | void InsertCol( SCTAB nTab, SCROW nRowStart, SCROW nRowEnd, SCCOL nColPos, SCSIZE nSize ); |
63 | | void InsertCol( SCTAB nTab, SCCOL nColPos ); |
64 | | |
65 | | /** For now this method assumes that nTab1 == nTab2 |
66 | | * The algorithm will be much more complicated if nTab1 != nTab2 |
67 | | */ |
68 | | bool DeleteArea( SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, |
69 | | SCROW nRow2, SCTAB nTab2 ); |
70 | | |
71 | | const ScRange* Find( const ScAddress& ) const; |
72 | | ScRange* Find( const ScAddress& ); |
73 | | bool operator==( const ScRangeList& ) const; |
74 | | bool operator!=( const ScRangeList& r ) const; |
75 | | bool Intersects( const ScRange& ) const; |
76 | | bool Contains( const ScRange& ) const; |
77 | | sal_uInt64 GetCellCount() const; |
78 | | ScAddress GetTopLeftCorner() const; |
79 | | |
80 | | ScRangeList GetIntersectedRange(const ScRange& rRange) const; |
81 | | |
82 | | void Remove(size_t nPos); |
83 | | void RemoveAll(); |
84 | | |
85 | | ScRange Combine() const; |
86 | | // Add new range, and do a partial combine up till one row back |
87 | | void AddAndPartialCombine(const ScRange&); |
88 | | |
89 | 21.4M | bool empty() const { return maRanges.empty(); } |
90 | 5.20M | size_t size() const { return maRanges.size(); } |
91 | 18.3M | ScRange& operator[](size_t idx) { return maRanges[idx]; } |
92 | 311k | const ScRange& operator[](size_t idx) const { return maRanges[idx]; } |
93 | 6.98k | ScRange& front() { return maRanges.front(); } |
94 | 0 | const ScRange& front() const { return maRanges.front(); } |
95 | 2.19M | ScRange& back() { return maRanges.back(); } |
96 | 0 | const ScRange& back() const { return maRanges.back(); } |
97 | | void push_back(const ScRange & rRange); |
98 | 55.1k | ::std::vector<ScRange>::const_iterator begin() const { return maRanges.begin(); } |
99 | 55.1k | ::std::vector<ScRange>::const_iterator end() const { return maRanges.end(); } |
100 | 5.07k | ::std::vector<ScRange>::iterator begin() { return maRanges.begin(); } |
101 | 6.23k | ::std::vector<ScRange>::iterator end() { return maRanges.end(); } |
102 | | void insert(std::vector<ScRange>::iterator aPos, std::vector<ScRange>::const_iterator aSourceBegin, std::vector<ScRange>::const_iterator aSourceEnd) |
103 | 1.16k | { maRanges.insert(aPos, aSourceBegin, aSourceEnd); } |
104 | | |
105 | | void swap( ScRangeList& r ); |
106 | | |
107 | | private: |
108 | | ::std::vector<ScRange> maRanges; |
109 | | SCROW mnMaxRowUsed; |
110 | | }; |
111 | | typedef tools::SvRef<ScRangeList> ScRangeListRef; |
112 | | |
113 | | // For use in SAL_DEBUG etc. Output format not guaranteed to be stable. |
114 | | template<typename charT, typename traits> |
115 | | inline std::basic_ostream<charT, traits> & operator <<(std::basic_ostream<charT, traits> & stream, const ScRangeList& rRangeList) |
116 | | { |
117 | | stream << "("; |
118 | | for (size_t i = 0; i < rRangeList.size(); ++i) |
119 | | { |
120 | | if (i > 0) |
121 | | stream << ","; |
122 | | stream << rRangeList[i]; |
123 | | } |
124 | | stream << ")"; |
125 | | |
126 | | return stream; |
127 | | } |
128 | | |
129 | | // RangePairList: |
130 | | // aRange[0]: actual range, |
131 | | // aRange[1]: data for that range, e.g. Rows belonging to a ColName |
132 | | class SC_DLLPUBLIC ScRangePairList final : public SvRefBase |
133 | | { |
134 | | public: |
135 | | virtual ~ScRangePairList() override; |
136 | | ScRangePairList* Clone() const; |
137 | | void Append( const ScRangePair& rRangePair ) |
138 | 135k | { |
139 | 135k | maPairs.push_back( rRangePair ); |
140 | 135k | } |
141 | | void Join( const ScRangePair&, bool bIsInList = false ); |
142 | | void UpdateReference( UpdateRefMode, const ScDocument&, |
143 | | const ScRange& rWhere, |
144 | | SCCOL nDx, SCROW nDy, SCTAB nDz ); |
145 | | void DeleteOnTab( SCTAB nTab ); |
146 | | ScRangePair* Find( const ScAddress& ); |
147 | | ScRangePair* Find( const ScRange& ); |
148 | | std::vector<const ScRangePair*> |
149 | | CreateNameSortedArray( ScDocument& ) const; |
150 | | |
151 | | void Remove(size_t nPos); |
152 | | void Remove(const ScRangePair & rAdr); |
153 | | |
154 | | size_t size() const; |
155 | | ScRangePair& operator[](size_t idx); |
156 | | const ScRangePair& operator[](size_t idx) const; |
157 | | |
158 | | private: |
159 | | ::std::vector< ScRangePair > maPairs; |
160 | | }; |
161 | | typedef tools::SvRef<ScRangePairList> ScRangePairListRef; |
162 | | |
163 | | extern "C" |
164 | | int ScRangePairList_QsortNameCompare( const void*, const void* ); |
165 | | |
166 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |