simplify the SearchMode enums
there only needs to be one enum, not two Change-Id: Idb8c0c37737505cf6c28f26c0024c3c21a19fbb9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182202 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins
This commit is contained in:
+6
-14
@@ -28,6 +28,7 @@
|
||||
class ScDocument;
|
||||
struct ScLookupCacheMap;
|
||||
struct ScQueryEntry;
|
||||
enum class LookupSearchMode;
|
||||
|
||||
/** Lookup cache for one range used with interpreter functions such as VLOOKUP
|
||||
and MATCH. Caches query for a specific row and the resulting address looked
|
||||
@@ -35,7 +36,6 @@ struct ScQueryEntry;
|
||||
performed, which usually occur to obtain a different offset column of the
|
||||
same query.
|
||||
*/
|
||||
|
||||
class ScLookupCache final : public SvtListener
|
||||
{
|
||||
public:
|
||||
@@ -56,14 +56,6 @@ public:
|
||||
GREATER_EQUAL
|
||||
};
|
||||
|
||||
enum SearchMode
|
||||
{
|
||||
SEARCHFWD = 1,
|
||||
SEARCHREV = -1,
|
||||
SEARCHBASC = 2,
|
||||
SEARCHDESC = -2
|
||||
};
|
||||
|
||||
class QueryCriteria
|
||||
{
|
||||
union
|
||||
@@ -74,7 +66,7 @@ public:
|
||||
bool mbAlloc;
|
||||
bool mbString;
|
||||
QueryOp meOp;
|
||||
SearchMode meSearchMode;
|
||||
LookupSearchMode meSearchMode;
|
||||
|
||||
void deleteString()
|
||||
{
|
||||
@@ -86,12 +78,12 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
explicit QueryCriteria( const ScQueryEntry & rEntry, sal_Int8 nSearchMode );
|
||||
explicit QueryCriteria( const ScQueryEntry & rEntry, LookupSearchMode nSearchMode );
|
||||
QueryCriteria( const QueryCriteria & r );
|
||||
~QueryCriteria();
|
||||
|
||||
QueryOp getQueryOp() const { return meOp; }
|
||||
SearchMode getSearchMode() const { return meSearchMode; }
|
||||
LookupSearchMode getSearchMode() const { return meSearchMode; }
|
||||
|
||||
void setDouble( double fVal )
|
||||
{
|
||||
@@ -163,9 +155,9 @@ private:
|
||||
SCROW mnRow;
|
||||
SCTAB mnTab;
|
||||
QueryOp meOp;
|
||||
SearchMode meSearchMode;
|
||||
LookupSearchMode meSearchMode;
|
||||
|
||||
QueryKey( const ScAddress & rAddress, const QueryOp eOp, SearchMode eSearchMode ) :
|
||||
QueryKey( const ScAddress & rAddress, const QueryOp eOp, LookupSearchMode eSearchMode ) :
|
||||
mnRow( rAddress.Row()),
|
||||
mnTab( rAddress.Tab()),
|
||||
meOp( eOp),
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/* -*- 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
|
||||
|
||||
/** Mode used with interpreter functions such as VLOOKUP and MATCH. */
|
||||
enum class LookupSearchMode
|
||||
{
|
||||
Forward = 1, // Perform a search starting at the first item. This is the default.
|
||||
Reverse = -1, // Perform a reverse search starting at the last item.
|
||||
BinaryAscending
|
||||
= 2, // Perform a binary search that relies on lookup_array being sorted in ascending order.
|
||||
BinaryDescending
|
||||
= -2 // Perform a binary search that relies on lookup_array being sorted in descending order.
|
||||
};
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "queryparam.hxx"
|
||||
#include "mtvelements.hxx"
|
||||
#include "types.hxx"
|
||||
#include "lookupsearchmode.hxx"
|
||||
|
||||
struct ScComplexRefData;
|
||||
class ScSortedRangeCache;
|
||||
@@ -269,10 +270,13 @@ public:
|
||||
void AdvanceQueryParamEntryField();
|
||||
void AdvanceQueryParamEntryFieldForBinarySearch();
|
||||
|
||||
void SetSortedBinarySearchMode( sal_Int8 nSearchMode )
|
||||
void SetSortedBinarySearchMode( LookupSearchMode nSearchMode )
|
||||
{
|
||||
nSortedBinarySearch = sal::static_int_cast<sal_uInt8>(nSearchMode == 2 ?
|
||||
nSearchbAscd : (nSearchMode == -2 ? nSearchbDesc : nBinarySearchDisabled));
|
||||
nSortedBinarySearch =
|
||||
nSearchMode == LookupSearchMode::BinaryAscending
|
||||
? nSearchbAscd
|
||||
: (nSearchMode == LookupSearchMode::BinaryDescending
|
||||
? nSearchbDesc : nBinarySearchDisabled);
|
||||
}
|
||||
|
||||
void SetLookupMode( sal_uInt16 nVal )
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <queryentry.hxx>
|
||||
#include <sortparam.hxx>
|
||||
#include "parclass.hxx"
|
||||
#include <lookupsearchmode.hxx>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
@@ -57,7 +58,6 @@ class ScJumpMatrix;
|
||||
struct ScRefCellValue;
|
||||
|
||||
enum MatchMode{ exactorNA=0, exactorS=-1, exactorG=1, wildcard=2, regex=3 };
|
||||
enum SearchMode{ searchfwd=1, searchrev=-1, searchbasc=2, searchbdesc=-2 };
|
||||
enum IgnoreValues{ DEFAULT=0, BLANKS=1, ERRORS=2, ALL=3 };
|
||||
|
||||
struct VectorSearchArguments
|
||||
@@ -89,7 +89,7 @@ struct VectorSearchArguments
|
||||
svl::SharedString sSearchStr;
|
||||
bool bVLookup;
|
||||
|
||||
// search mode (only XLOOKUP has all 4 options, MATCH only uses searchfwd)
|
||||
// search mode (only XLOOKUP has all 4 options, MATCH only uses Forward)
|
||||
// optional 6th argument to set search mode
|
||||
// 1 - Perform a search starting at the first item. This is the default.
|
||||
// -1 - Perform a reverse search starting at the last item.
|
||||
@@ -98,7 +98,7 @@ struct VectorSearchArguments
|
||||
// -2 - Perform a binary search that relies on lookup_array being sorted in descending order.
|
||||
// If not sorted, invalid results will be returned.
|
||||
//
|
||||
SearchMode eSearchMode = searchfwd;
|
||||
LookupSearchMode eSearchMode = LookupSearchMode::Forward;
|
||||
|
||||
// search variables
|
||||
SCSIZE nHitIndex = 0;
|
||||
@@ -561,7 +561,7 @@ private:
|
||||
inline void TreatDoubleError( double& rVal );
|
||||
// Lookup using ScLookupCache, @returns true if found and result address
|
||||
bool LookupQueryWithCache( ScAddress & o_rResultPos, const ScQueryParam & rParam,
|
||||
const ScComplexRefData* refData, sal_Int8 nSearchMode, sal_uInt16 nOpCode ) const;
|
||||
const ScComplexRefData* refData, LookupSearchMode nSearchMode, sal_uInt16 nOpCode ) const;
|
||||
|
||||
void ScIfJump();
|
||||
void ScIfError( bool bNAonly );
|
||||
|
||||
@@ -5009,16 +5009,16 @@ void ScInterpreter::ScMatch()
|
||||
{
|
||||
case -1 :
|
||||
vsa.eMatchMode = exactorG;
|
||||
vsa.eSearchMode = searchbdesc;
|
||||
vsa.eSearchMode = LookupSearchMode::BinaryDescending;
|
||||
break;
|
||||
case 0 :
|
||||
vsa.eMatchMode = exactorNA;
|
||||
vsa.eSearchMode = searchfwd;
|
||||
vsa.eSearchMode = LookupSearchMode::Forward;
|
||||
break;
|
||||
case 1 :
|
||||
// default value
|
||||
vsa.eMatchMode = exactorS;
|
||||
vsa.eSearchMode = searchbasc;
|
||||
vsa.eSearchMode = LookupSearchMode::BinaryAscending;
|
||||
break;
|
||||
default :
|
||||
PushIllegalParameter();
|
||||
@@ -5170,7 +5170,7 @@ void ScInterpreter::ScXMatch()
|
||||
{
|
||||
sal_Int16 k = GetInt16();
|
||||
if (k >= -2 && k <= 2 && k != 0)
|
||||
vsa.eSearchMode = static_cast<SearchMode>(k);
|
||||
vsa.eSearchMode = static_cast<LookupSearchMode>(k);
|
||||
else
|
||||
{
|
||||
PushIllegalParameter();
|
||||
@@ -5178,7 +5178,7 @@ void ScInterpreter::ScXMatch()
|
||||
}
|
||||
}
|
||||
else
|
||||
vsa.eSearchMode = searchfwd;
|
||||
vsa.eSearchMode = LookupSearchMode::Forward;
|
||||
|
||||
// get match mode
|
||||
if (nParamCount >= 3)
|
||||
@@ -7826,7 +7826,7 @@ void ScInterpreter::CalculateLookup(bool bHLookup)
|
||||
else
|
||||
{
|
||||
ScAddress aResultPos( nCol1, nRow1, nTab1);
|
||||
bFound = LookupQueryWithCache( aResultPos, aParam, refData, 1 /*searchfwd*/, SC_OPCODE_V_LOOKUP );
|
||||
bFound = LookupQueryWithCache( aResultPos, aParam, refData, LookupSearchMode::Forward, SC_OPCODE_V_LOOKUP );
|
||||
nRow = aResultPos.Row();
|
||||
nCol = nSpIndex;
|
||||
}
|
||||
@@ -7925,7 +7925,7 @@ void ScInterpreter::ScXLookup()
|
||||
{
|
||||
sal_Int16 k = GetInt16();
|
||||
if ( k >= -2 && k <= 2 && k != 0 )
|
||||
vsa.eSearchMode = static_cast<SearchMode>(k);
|
||||
vsa.eSearchMode = static_cast<LookupSearchMode>(k);
|
||||
else
|
||||
{
|
||||
PushIllegalParameter();
|
||||
@@ -7933,7 +7933,7 @@ void ScInterpreter::ScXLookup()
|
||||
}
|
||||
}
|
||||
else
|
||||
vsa.eSearchMode = searchfwd;
|
||||
vsa.eSearchMode = LookupSearchMode::Forward;
|
||||
|
||||
if ( nParamCount >= 5 )
|
||||
{
|
||||
@@ -12330,7 +12330,7 @@ bool ScInterpreter::SearchMatrixForValue( VectorSearchArguments& vsa, ScQueryPar
|
||||
|
||||
switch ( vsa.eSearchMode )
|
||||
{
|
||||
case searchfwd :
|
||||
case LookupSearchMode::Forward :
|
||||
{
|
||||
switch ( vsa.eMatchMode )
|
||||
{
|
||||
@@ -12391,7 +12391,7 @@ bool ScInterpreter::SearchMatrixForValue( VectorSearchArguments& vsa, ScQueryPar
|
||||
}
|
||||
break;
|
||||
|
||||
case searchrev:
|
||||
case LookupSearchMode::Reverse:
|
||||
{
|
||||
switch ( vsa.eMatchMode )
|
||||
{
|
||||
@@ -12452,11 +12452,11 @@ bool ScInterpreter::SearchMatrixForValue( VectorSearchArguments& vsa, ScQueryPar
|
||||
}
|
||||
break;
|
||||
|
||||
case searchbasc:
|
||||
case searchbdesc:
|
||||
case LookupSearchMode::BinaryAscending:
|
||||
case LookupSearchMode::BinaryDescending:
|
||||
{
|
||||
// binary search for non-equality mode (the source data is sorted)
|
||||
bool bAscOrder = ( vsa.eSearchMode == searchbasc );
|
||||
bool bAscOrder = ( vsa.eSearchMode == LookupSearchMode::BinaryAscending );
|
||||
SCSIZE nFirst = 0;
|
||||
SCSIZE nLast = nMatCount - 1;
|
||||
for ( SCSIZE nLen = nLast - nFirst; nLen > 0; nLen = nLast - nFirst )
|
||||
@@ -12534,10 +12534,10 @@ bool ScInterpreter::SearchRangeForValue( VectorSearchArguments& vsa, ScQueryPara
|
||||
vsa.bVLookup = ( vsa.nCol1 == vsa.nCol2 );
|
||||
switch ( vsa.eSearchMode )
|
||||
{
|
||||
case searchfwd:
|
||||
case searchrev:
|
||||
case searchbasc:
|
||||
case searchbdesc:
|
||||
case LookupSearchMode::Forward:
|
||||
case LookupSearchMode::Reverse:
|
||||
case LookupSearchMode::BinaryAscending:
|
||||
case LookupSearchMode::BinaryDescending:
|
||||
{
|
||||
if (vsa.bVLookup)
|
||||
{
|
||||
@@ -12551,7 +12551,7 @@ bool ScInterpreter::SearchRangeForValue( VectorSearchArguments& vsa, ScQueryPara
|
||||
else
|
||||
{
|
||||
rParam.bByRow = false;
|
||||
bool bBinarySearch = vsa.eSearchMode == searchbasc || vsa.eSearchMode == searchbdesc;
|
||||
bool bBinarySearch = vsa.eSearchMode == LookupSearchMode::BinaryAscending || vsa.eSearchMode == LookupSearchMode::BinaryDescending;
|
||||
if (bBinarySearch && (vsa.nSearchOpCode == SC_OPCODE_X_LOOKUP || vsa.nSearchOpCode == SC_OPCODE_X_MATCH))
|
||||
{
|
||||
ScQueryCellIteratorSortedCache aCellIter(mrDoc, mrContext, rParam.nTab, rParam, false, false);
|
||||
@@ -12567,7 +12567,7 @@ bool ScInterpreter::SearchRangeForValue( VectorSearchArguments& vsa, ScQueryPara
|
||||
else
|
||||
{
|
||||
// search of columns in row
|
||||
bool bReverseSearch = (vsa.eSearchMode == searchrev);
|
||||
bool bReverseSearch = (vsa.eSearchMode == LookupSearchMode::Reverse);
|
||||
ScQueryCellIteratorDirect aCellIter(mrDoc, mrContext, vsa.nTab1, rParam, false, bReverseSearch);
|
||||
// Advance Entry.nField in Iterator if column changed
|
||||
aCellIter.SetAdvanceQueryParamEntryField(true);
|
||||
@@ -12618,7 +12618,7 @@ bool ScInterpreter::SearchVectorForValue( VectorSearchArguments& vsa )
|
||||
rParam.nTab = vsa.nTab1;
|
||||
|
||||
ScQueryEntry& rEntry = rParam.GetEntry(0);
|
||||
rEntry.nField = vsa.eSearchMode != searchrev ? vsa.nCol1 : vsa.nCol2;
|
||||
rEntry.nField = vsa.eSearchMode != LookupSearchMode::Reverse ? vsa.nCol1 : vsa.nCol2;
|
||||
rEntry.bDoQuery = true;
|
||||
switch ( vsa.eMatchMode )
|
||||
{
|
||||
@@ -12640,7 +12640,7 @@ bool ScInterpreter::SearchVectorForValue( VectorSearchArguments& vsa )
|
||||
if ( vsa.nSearchOpCode == SC_OPCODE_X_LOOKUP || vsa.nSearchOpCode == SC_OPCODE_X_MATCH )
|
||||
{
|
||||
// Wildcard/Regex search mode with binary search is not allowed
|
||||
if (vsa.eSearchMode == searchbasc || vsa.eSearchMode == searchbdesc)
|
||||
if (vsa.eSearchMode == LookupSearchMode::BinaryAscending || vsa.eSearchMode == LookupSearchMode::BinaryDescending)
|
||||
{
|
||||
PushNoValue();
|
||||
return false;
|
||||
@@ -12744,14 +12744,14 @@ bool ScInterpreter::SearchVectorForValue( VectorSearchArguments& vsa )
|
||||
|
||||
static bool lcl_LookupQuery( ScAddress & o_rResultPos, ScDocument& rDoc, ScInterpreterContext& rContext,
|
||||
const ScQueryParam & rParam, const ScQueryEntry & rEntry, const ScFormulaCell* cell,
|
||||
const ScComplexRefData* refData, sal_Int8 nSearchMode, sal_uInt16 nOpCode )
|
||||
const ScComplexRefData* refData, LookupSearchMode nSearchMode, sal_uInt16 nOpCode )
|
||||
{
|
||||
if (rEntry.eOp != SC_EQUAL)
|
||||
{
|
||||
// range lookup <= or >=
|
||||
SCCOL nCol;
|
||||
SCROW nRow;
|
||||
bool bBinarySearch = static_cast<SearchMode>(nSearchMode) == searchbasc || static_cast<SearchMode>(nSearchMode) == searchbdesc;
|
||||
bool bBinarySearch = nSearchMode == LookupSearchMode::BinaryAscending || nSearchMode == LookupSearchMode::BinaryDescending;
|
||||
if ((bBinarySearch && (nOpCode == SC_OPCODE_X_LOOKUP || nOpCode == SC_OPCODE_X_MATCH)) ||
|
||||
ScQueryCellIteratorSortedCache::CanBeUsed(rDoc, rParam, rParam.nTab, cell, refData, rContext))
|
||||
{
|
||||
@@ -12767,7 +12767,7 @@ static bool lcl_LookupQuery( ScAddress & o_rResultPos, ScDocument& rDoc, ScInter
|
||||
}
|
||||
else
|
||||
{
|
||||
bool bReverse = (static_cast<SearchMode>(nSearchMode) == searchrev);
|
||||
bool bReverse = nSearchMode == LookupSearchMode::Reverse;
|
||||
ScQueryCellIteratorDirect aCellIter(rDoc, rContext, rParam.nTab, rParam, false, bReverse);
|
||||
|
||||
aCellIter.SetSortedBinarySearchMode(nSearchMode);
|
||||
@@ -12788,7 +12788,7 @@ static bool lcl_LookupQuery( ScAddress & o_rResultPos, ScDocument& rDoc, ScInter
|
||||
bool bBinary = rParam.bByRow &&
|
||||
(bLiteral || rEntry.GetQueryItem().meType == ScQueryEntry::ByValue);
|
||||
|
||||
if( bBinary && (static_cast<SearchMode>(nSearchMode) == searchbasc || static_cast<SearchMode>(nSearchMode) == searchbdesc ||
|
||||
if( bBinary && (nSearchMode == LookupSearchMode::BinaryAscending || nSearchMode == LookupSearchMode::BinaryDescending ||
|
||||
ScQueryCellIteratorSortedCache::CanBeUsed(rDoc, rParam, rParam.nTab, cell, refData, rContext)))
|
||||
{
|
||||
ScQueryCellIteratorSortedCache aCellIter( rDoc, rContext, rParam.nTab, rParam, false, false );
|
||||
@@ -12804,7 +12804,7 @@ static bool lcl_LookupQuery( ScAddress & o_rResultPos, ScDocument& rDoc, ScInter
|
||||
else
|
||||
{
|
||||
ScQueryCellIteratorDirect aCellIter( rDoc, rContext, rParam.nTab, rParam, false,
|
||||
static_cast<SearchMode>(nSearchMode) == searchrev);
|
||||
nSearchMode == LookupSearchMode::Reverse);
|
||||
aCellIter.SetSortedBinarySearchMode(nSearchMode);
|
||||
aCellIter.SetLookupMode(nOpCode);
|
||||
if (aCellIter.GetFirst())
|
||||
@@ -12858,7 +12858,7 @@ static SCROW lcl_getPrevRowWithEmptyValueLookup( const ScLookupCache& rCache,
|
||||
|
||||
bool ScInterpreter::LookupQueryWithCache( ScAddress & o_rResultPos,
|
||||
const ScQueryParam & rParam, const ScComplexRefData* refData,
|
||||
sal_Int8 nSearchMode, sal_uInt16 nOpCode ) const
|
||||
LookupSearchMode nSearchMode, sal_uInt16 nOpCode ) const
|
||||
{
|
||||
bool bFound = false;
|
||||
const ScQueryEntry& rEntry = rParam.GetEntry(0);
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
#include <sal/log.hxx>
|
||||
|
||||
ScLookupCache::QueryCriteria::QueryCriteria( const ScQueryEntry& rEntry, sal_Int8 nSearchMode ) :
|
||||
mfVal(0.0), mbAlloc(false), mbString(false), meSearchMode(static_cast<SearchMode>(nSearchMode))
|
||||
ScLookupCache::QueryCriteria::QueryCriteria( const ScQueryEntry& rEntry, LookupSearchMode nSearchMode ) :
|
||||
mfVal(0.0), mbAlloc(false), mbString(false), meSearchMode(nSearchMode)
|
||||
{
|
||||
switch (rEntry.eOp)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user