diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-04-22 12:08:57 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-04-22 18:16:05 +0200 |
commit | 4af9403cf718207620376b63242f6d0dd047406a (patch) | |
tree | e5c297f7b2570e213d6ece5af8195e692779e54b /sc/inc | |
parent | a09cf7e76a6d90a50a373d04d717897b7f717d54 (diff) |
move query-related iterators to a new separate file
dociter.cxx/hxx are already quite big as it is, and the query
iterators are more about queries than about iterating the document.
Change-Id: I49e3a5636e4f366efb8b4968f54567d2716ade35
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133323
Tested-by: Luboš Luňák <l.lunak@collabora.com>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc/inc')
-rw-r--r-- | sc/inc/dociter.hxx | 143 | ||||
-rw-r--r-- | sc/inc/queryiter.hxx | 171 |
2 files changed, 171 insertions, 143 deletions
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx index 99ceb1e99972..90fbd614b8bd 100644 --- a/sc/inc/dociter.hxx +++ b/sc/inc/dociter.hxx @@ -248,149 +248,6 @@ public: bool next(); }; -class ScQueryCellIterator // walk through all non-empty cells in an area -{ - enum StopOnMismatchBits - { - nStopOnMismatchDisabled = 0x00, - nStopOnMismatchEnabled = 0x01, - nStopOnMismatchOccurred = 0x02, - nStopOnMismatchExecuted = nStopOnMismatchEnabled | nStopOnMismatchOccurred - }; - - enum TestEqualConditionBits - { - nTestEqualConditionDisabled = 0x00, - nTestEqualConditionEnabled = 0x01, - nTestEqualConditionMatched = 0x02, - nTestEqualConditionFulfilled = nTestEqualConditionEnabled | nTestEqualConditionMatched - }; - - typedef sc::CellStoreType::const_position_type PositionType; - PositionType maCurPos; - - ScQueryParam maParam; - ScDocument& rDoc; - const ScInterpreterContext& mrContext; - SCTAB nTab; - SCCOL nCol; - SCROW nRow; - sal_uInt8 nStopOnMismatch; - sal_uInt8 nTestEqualCondition; - bool bAdvanceQuery; - bool bIgnoreMismatchOnLeadingStrings; - - /** Initialize position for new column. */ - void InitPos(); - void IncPos(); - void IncBlock(); - bool GetThis(); - - /* Only works if no regular expression is involved, only - searches for rows in one column, and only the first - query entry is considered with simple conditions - SC_LESS_EQUAL (sorted ascending) or SC_GREATER_EQUAL - (sorted descending). Check these things before - invocation! Delivers a starting point, continue with - GetThis() and GetNext() afterwards. Introduced for - FindEqualOrSortedLastInRange() - */ - bool BinarySearch(); - -public: - ScQueryCellIterator(ScDocument& rDocument, const ScInterpreterContext& rContext, SCTAB nTable, - const ScQueryParam& aParam, bool bMod); - // when !bMod, the QueryParam has to be filled - // (bIsString) - bool GetFirst(); - bool GetNext(); - SCCOL GetCol() const { return nCol; } - SCROW GetRow() const { return nRow; } - - // increments all Entry.nField, if column - // changes, for ScInterpreter ScHLookup() - void SetAdvanceQueryParamEntryField( bool bVal ) - { bAdvanceQuery = bVal; } - void AdvanceQueryParamEntryField(); - - /** If set, iterator stops on first non-matching cell - content. May be used in SC_LESS_EQUAL queries where a - cell range is assumed to be sorted; stops on first - value being greater than the queried value and - GetFirst()/GetNext() return NULL. StoppedOnMismatch() - returns true then. - However, the iterator's conditions are not set to end - all queries, GetCol() and GetRow() return values for - the non-matching cell, further GetNext() calls may be - executed. */ - void SetStopOnMismatch( bool bVal ) - { - nStopOnMismatch = sal::static_int_cast<sal_uInt8>(bVal ? nStopOnMismatchEnabled : - nStopOnMismatchDisabled); - } - bool StoppedOnMismatch() const - { return nStopOnMismatch == nStopOnMismatchExecuted; } - - /** If set, an additional test for SC_EQUAL condition is - executed in ScTable::ValidQuery() if SC_LESS_EQUAL or - SC_GREATER_EQUAL conditions are to be tested. May be - used where a cell range is assumed to be sorted to stop - if an equal match is found. */ - void SetTestEqualCondition( bool bVal ) - { - nTestEqualCondition = sal::static_int_cast<sal_uInt8>(bVal ? - nTestEqualConditionEnabled : - nTestEqualConditionDisabled); - } - bool IsEqualConditionFulfilled() const - { return nTestEqualCondition == nTestEqualConditionFulfilled; } - - /** In a range assumed to be sorted find either the last of - a sequence of equal entries or the last being less than - (or greater than) the queried value. Used by the - interpreter for [HV]?LOOKUP() and MATCH(). Column and - row position of the found entry are returned, otherwise - invalid. - - The search does not stop when encountering a string and does not - assume that no values follow anymore. - If querying for a string a mismatch on the first - entry, e.g. column header, is ignored. - - @ATTENTION! StopOnMismatch, TestEqualCondition and - the internal IgnoreMismatchOnLeadingStrings and query - params are in an undefined state upon return! The - iterator is not usable anymore except for obtaining the - number format! - */ - bool FindEqualOrSortedLastInRange( SCCOL& nFoundCol, SCROW& nFoundRow ); -}; - -// Used by ScInterpreter::ScCountIf. -// Walk through all non-empty cells in an area. -class ScCountIfCellIterator -{ - typedef sc::CellStoreType::const_position_type PositionType; - PositionType maCurPos; - ScQueryParam maParam; - ScDocument& rDoc; - const ScInterpreterContext& mrContext; - SCTAB nTab; - SCCOL nCol; - SCROW nRow; - - /** Initialize position for new column. */ - void InitPos(); - void IncPos(); - void IncBlock(); - void AdvanceQueryParamEntryField(); - -public: - ScCountIfCellIterator(ScDocument& rDocument, const ScInterpreterContext& rContext, SCTAB nTable, - const ScQueryParam& aParam); - int GetCount(); -}; - class ScDocAttrIterator // all attribute areas { private: diff --git a/sc/inc/queryiter.hxx b/sc/inc/queryiter.hxx new file mode 100644 index 000000000000..70b8daaf4153 --- /dev/null +++ b/sc/inc/queryiter.hxx @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "address.hxx" +#include "global.hxx" +#include "scdllapi.h" +#include "queryparam.hxx" +#include "mtvelements.hxx" + +class ScQueryCellIterator // walk through all non-empty cells in an area +{ + enum StopOnMismatchBits + { + nStopOnMismatchDisabled = 0x00, + nStopOnMismatchEnabled = 0x01, + nStopOnMismatchOccurred = 0x02, + nStopOnMismatchExecuted = nStopOnMismatchEnabled | nStopOnMismatchOccurred + }; + + enum TestEqualConditionBits + { + nTestEqualConditionDisabled = 0x00, + nTestEqualConditionEnabled = 0x01, + nTestEqualConditionMatched = 0x02, + nTestEqualConditionFulfilled = nTestEqualConditionEnabled | nTestEqualConditionMatched + }; + + typedef sc::CellStoreType::const_position_type PositionType; + PositionType maCurPos; + + ScQueryParam maParam; + ScDocument& rDoc; + const ScInterpreterContext& mrContext; + SCTAB nTab; + SCCOL nCol; + SCROW nRow; + sal_uInt8 nStopOnMismatch; + sal_uInt8 nTestEqualCondition; + bool bAdvanceQuery; + bool bIgnoreMismatchOnLeadingStrings; + + /** Initialize position for new column. */ + void InitPos(); + void IncPos(); + void IncBlock(); + bool GetThis(); + + /* Only works if no regular expression is involved, only + searches for rows in one column, and only the first + query entry is considered with simple conditions + SC_LESS_EQUAL (sorted ascending) or SC_GREATER_EQUAL + (sorted descending). Check these things before + invocation! Delivers a starting point, continue with + GetThis() and GetNext() afterwards. Introduced for + FindEqualOrSortedLastInRange() + */ + bool BinarySearch(); + +public: + ScQueryCellIterator(ScDocument& rDocument, const ScInterpreterContext& rContext, SCTAB nTable, + const ScQueryParam& aParam, bool bMod); + // when !bMod, the QueryParam has to be filled + // (bIsString) + bool GetFirst(); + bool GetNext(); + SCCOL GetCol() const { return nCol; } + SCROW GetRow() const { return nRow; } + + // increments all Entry.nField, if column + // changes, for ScInterpreter ScHLookup() + void SetAdvanceQueryParamEntryField( bool bVal ) + { bAdvanceQuery = bVal; } + void AdvanceQueryParamEntryField(); + + /** If set, iterator stops on first non-matching cell + content. May be used in SC_LESS_EQUAL queries where a + cell range is assumed to be sorted; stops on first + value being greater than the queried value and + GetFirst()/GetNext() return NULL. StoppedOnMismatch() + returns true then. + However, the iterator's conditions are not set to end + all queries, GetCol() and GetRow() return values for + the non-matching cell, further GetNext() calls may be + executed. */ + void SetStopOnMismatch( bool bVal ) + { + nStopOnMismatch = sal::static_int_cast<sal_uInt8>(bVal ? nStopOnMismatchEnabled : + nStopOnMismatchDisabled); + } + bool StoppedOnMismatch() const + { return nStopOnMismatch == nStopOnMismatchExecuted; } + + /** If set, an additional test for SC_EQUAL condition is + executed in ScTable::ValidQuery() if SC_LESS_EQUAL or + SC_GREATER_EQUAL conditions are to be tested. May be + used where a cell range is assumed to be sorted to stop + if an equal match is found. */ + void SetTestEqualCondition( bool bVal ) + { + nTestEqualCondition = sal::static_int_cast<sal_uInt8>(bVal ? + nTestEqualConditionEnabled : + nTestEqualConditionDisabled); + } + bool IsEqualConditionFulfilled() const + { return nTestEqualCondition == nTestEqualConditionFulfilled; } + + /** In a range assumed to be sorted find either the last of + a sequence of equal entries or the last being less than + (or greater than) the queried value. Used by the + interpreter for [HV]?LOOKUP() and MATCH(). Column and + row position of the found entry are returned, otherwise + invalid. + + The search does not stop when encountering a string and does not + assume that no values follow anymore. + If querying for a string a mismatch on the first + entry, e.g. column header, is ignored. + + @ATTENTION! StopOnMismatch, TestEqualCondition and + the internal IgnoreMismatchOnLeadingStrings and query + params are in an undefined state upon return! The + iterator is not usable anymore except for obtaining the + number format! + */ + bool FindEqualOrSortedLastInRange( SCCOL& nFoundCol, SCROW& nFoundRow ); +}; + +// Used by ScInterpreter::ScCountIf. +// Walk through all non-empty cells in an area. +class ScCountIfCellIterator +{ + typedef sc::CellStoreType::const_position_type PositionType; + PositionType maCurPos; + ScQueryParam maParam; + ScDocument& rDoc; + const ScInterpreterContext& mrContext; + SCTAB nTab; + SCCOL nCol; + SCROW nRow; + + /** Initialize position for new column. */ + void InitPos(); + void IncPos(); + void IncBlock(); + void AdvanceQueryParamEntryField(); + +public: + ScCountIfCellIterator(ScDocument& rDocument, const ScInterpreterContext& rContext, SCTAB nTable, + const ScQueryParam& aParam); + int GetCount(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |