Branch libreoffice-24-8-3
[LibreOffice.git] / sc / inc / queryevaluator.hxx
blob6d3012141db8fc8040806374adb64803bca6fa71
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <memory>
23 #include <vector>
24 #include <unordered_map>
26 #include "queryentry.hxx"
28 class ScDocument;
29 class ScTable;
30 struct ScQueryParam;
31 class CollatorWrapper;
32 struct ScRefCellValue;
33 struct ScInterpreterContext;
35 namespace sc
37 class TableColumnBlockPositionSet;
39 namespace svl
41 class SharedStringPool;
43 namespace utl
45 class TransliterationWrapper;
48 class ScQueryEvaluator
50 ScDocument& mrDoc;
51 svl::SharedStringPool& mrStrPool;
52 const ScTable& mrTab;
53 const ScQueryParam& mrParam;
54 bool* mpTestEqualCondition;
55 utl::TransliterationWrapper* mpTransliteration;
56 CollatorWrapper* mpCollator;
57 const bool mbMatchWholeCell;
58 const bool mbCaseSensitive;
59 ScInterpreterContext* mpContext;
61 const SCSIZE mnEntryCount;
62 bool* mpPasst;
63 bool* mpTest;
64 static constexpr SCSIZE nFixedBools = 32;
65 bool maBool[nFixedBools];
66 bool maTest[nFixedBools];
67 std::unique_ptr<bool[]> mpBoolDynamic;
68 std::unique_ptr<bool[]> mpTestDynamic;
70 std::unordered_map<FormulaError, svl::SharedString> mCachedSharedErrorStrings;
71 // The "outside" index in these two is the index of ScQueryEntry in ScQueryParam.
72 std::vector<std::vector<double>> mCachedSortedItemValues;
73 std::vector<std::vector<const rtl_uString*>> mCachedSortedItemStrings;
75 static bool isPartialTextMatchOp(ScQueryOp eOp);
76 static bool isTextMatchOp(ScQueryOp eOp);
77 static bool isMatchWholeCellHelper(bool docMatchWholeCell, ScQueryOp eOp);
78 bool isMatchWholeCell(ScQueryOp eOp) const;
79 void setupTransliteratorIfNeeded();
80 void setupCollatorIfNeeded();
82 bool isRealWildOrRegExp(const ScQueryEntry& rEntry) const;
83 bool isTestWildOrRegExp(const ScQueryEntry& rEntry) const;
84 static bool isQueryByValueForCell(const ScRefCellValue& rCell);
86 sal_uInt32 getNumFmt(SCCOL nCol, SCROW nRow);
88 std::pair<bool, bool> compareByValue(const ScRefCellValue& rCell, SCCOL nCol, SCROW nRow,
89 const ScQueryEntry& rEntry,
90 const ScQueryEntry::Item& rItem);
92 bool isFastCompareByString(const ScQueryEntry& rEntry) const;
93 template <bool bFast = false>
94 std::pair<bool, bool>
95 compareByString(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem,
96 const svl::SharedString* pValueSource1, const OUString* pValueSource2);
97 std::pair<bool, bool> compareByTextColor(SCCOL nCol, SCROW nRow,
98 const ScQueryEntry::Item& rItem);
99 std::pair<bool, bool> compareByBackgroundColor(SCCOL nCol, SCROW nRow,
100 const ScQueryEntry::Item& rItem);
102 static std::pair<bool, bool> compareByRangeLookup(const ScRefCellValue& rCell,
103 const ScQueryEntry& rEntry,
104 const ScQueryEntry::Item& rItem);
106 std::pair<bool, bool> processEntry(SCROW nRow, SCCOL nCol, ScRefCellValue& aCell,
107 const ScQueryEntry& rEntry, size_t nEntryIndex);
109 public:
110 ScQueryEvaluator(ScDocument& rDoc, const ScTable& rTab, const ScQueryParam& rParam,
111 ScInterpreterContext* pContext = nullptr, bool* pTestEqualCondition = nullptr,
112 bool bNewSearchFunction = false);
114 bool ValidQuery(SCROW nRow, const ScRefCellValue* pCell = nullptr,
115 sc::TableColumnBlockPositionSet* pBlockPos = nullptr);
117 static bool isQueryByValue(ScQueryOp eOp, ScQueryEntry::QueryType eType,
118 const ScRefCellValue& rCell);
119 static bool isQueryByString(ScQueryOp eOp, ScQueryEntry::QueryType eType,
120 const ScRefCellValue& rCell);
121 OUString getCellString(const ScRefCellValue& rCell, SCROW nRow, SCCOL nCol,
122 const svl::SharedString** sharedString);
123 static bool isMatchWholeCell(const ScDocument& rDoc, ScQueryOp eOp);
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */