LibreOffice Module sc (master)  1
Go to the documentation of this file.
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
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 .
18  */
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;
35 namespace sc
36 {
37 class TableColumnBlockPositionSet;
38 }
39 namespace svl
40 {
41 class SharedStringPool;
42 }
43 namespace utl
44 {
45 class TransliterationWrapper;
46 }
49 {
52  const ScTable& mrTab;
57  const bool mbMatchWholeCell;
58  const bool mbCaseSensitive;
62  bool* mpPasst;
63  bool* mpTest;
64  static constexpr SCSIZE nFixedBools = 32;
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(const ScQueryEntry& rEntry);
76  static bool isTextMatchOp(const ScQueryEntry& rEntry);
77  static bool isMatchWholeCellHelper(bool docMatchWholeCell, const ScQueryEntry& rEntry);
78  bool isMatchWholeCell(const ScQueryEntry& rEntry) const;
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  const ScInterpreterContext* pContext = nullptr,
112  bool* pTestEqualCondition = nullptr);
114  bool ValidQuery(SCROW nRow, const ScRefCellValue* pCell = nullptr,
115  sc::TableColumnBlockPositionSet* pBlockPos = nullptr);
117  static bool isQueryByValue(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem,
118  const ScRefCellValue& rCell);
119  static bool isQueryByString(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem,
120  const ScRefCellValue& rCell);
121  OUString getCellString(const ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry,
122  const svl::SharedString** sharedString);
123  static bool isMatchWholeCell(const ScDocument& rDoc, const ScQueryEntry& rEntry);
124 };
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< FormulaError, svl::SharedString > mCachedSharedErrorStrings
const bool mbCaseSensitive
std::pair< bool, bool > compareByString(const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem, const svl::SharedString *pValueSource1, const OUString *pValueSource2)
const ScTable & mrTab
bool isMatchWholeCell(const ScQueryEntry &rEntry) const
std::unique_ptr< bool[]> mpBoolDynamic
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
static constexpr SCSIZE nFixedBools
bool isTestWildOrRegExp(const ScQueryEntry &rEntry) const
std::pair< bool, bool > compareByValue(const ScRefCellValue &rCell, SCCOL nCol, SCROW nRow, const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem)
const SCSIZE mnEntryCount
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
const bool mbMatchWholeCell
static bool isQueryByValue(const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem, const ScRefCellValue &rCell)
static bool isQueryByValueForCell(const ScRefCellValue &rCell)
sal_uInt32 getNumFmt(SCCOL nCol, SCROW nRow)
std::pair< bool, bool > compareByTextColor(SCCOL nCol, SCROW nRow, const ScQueryEntry::Item &rItem)
CollatorWrapper * mpCollator
void setupCollatorIfNeeded()
static bool isMatchWholeCellHelper(bool docMatchWholeCell, const ScQueryEntry &rEntry)
ScDocument & mrDoc
static bool isQueryByString(const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem, const ScRefCellValue &rCell)
Set of column block positions only for one table.
sal_Int16 SCCOL
Definition: types.hxx:21
CAUTION! The following defines must be in the same namespace as the respective type.
const ScQueryParam & mrParam
std::unique_ptr< bool[]> mpTestDynamic
std::pair< bool, bool > compareByBackgroundColor(SCCOL nCol, SCROW nRow, const ScQueryEntry::Item &rItem)
static bool isPartialTextMatchOp(const ScQueryEntry &rEntry)
void setupTransliteratorIfNeeded()
svl::SharedStringPool & mrStrPool
bool isFastCompareByString(const ScQueryEntry &rEntry) const
bool ValidQuery(SCROW nRow, const ScRefCellValue *pCell=nullptr, sc::TableColumnBlockPositionSet *pBlockPos=nullptr)
sal_Int32 SCROW
Definition: types.hxx:17
static bool isTextMatchOp(const ScQueryEntry &rEntry)
bool isRealWildOrRegExp(const ScQueryEntry &rEntry) const
std::pair< bool, bool > processEntry(SCROW nRow, SCCOL nCol, ScRefCellValue &aCell, const ScQueryEntry &rEntry, size_t nEntryIndex)
std::vector< std::vector< double > > mCachedSortedItemValues
const ScInterpreterContext * mpContext
static std::pair< bool, bool > compareByRangeLookup(const ScRefCellValue &rCell, const ScQueryEntry &rEntry, const ScQueryEntry::Item &rItem)
bool maBool[nFixedBools]
OUString getCellString(const ScRefCellValue &rCell, SCROW nRow, const ScQueryEntry &rEntry, const svl::SharedString **sharedString)
std::vector< std::vector< const rtl_uString * > > mCachedSortedItemStrings
These need to be in global namespace just like their respective types are.
bool maTest[nFixedBools]
ScQueryEvaluator(ScDocument &rDoc, const ScTable &rTab, const ScQueryParam &rParam, const ScInterpreterContext *pContext=nullptr, bool *pTestEqualCondition=nullptr)
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:33
utl::TransliterationWrapper * mpTransliteration