Kaydet (Commit) 4db12f8a authored tarafından Kohei Yoshida's avatar Kohei Yoshida

More on reducing header dependency.

üst 892a9ff6
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
class ScDocument; class ScDocument;
class ScBaseCell; class ScBaseCell;
...@@ -48,6 +49,9 @@ class ScAttrArray; ...@@ -48,6 +49,9 @@ class ScAttrArray;
class ScAttrIterator; class ScAttrIterator;
class ScRange; class ScRange;
class ScFlatBoolRowSegments; class ScFlatBoolRowSegments;
struct ScQueryParam;
struct ScDBQueryParamInternal;
struct ScDBQueryParamMatrix;
class ScDocumentIterator // walk through all non-empty cells class ScDocumentIterator // walk through all non-empty cells
{ {
...@@ -265,7 +269,7 @@ class ScQueryCellIterator // walk through all non-empty cells in an ar ...@@ -265,7 +269,7 @@ class ScQueryCellIterator // walk through all non-empty cells in an ar
}; };
private: private:
ScQueryParam aParam; boost::scoped_ptr<ScQueryParam> mpParam;
ScDocument* pDoc; ScDocument* pDoc;
const ScAttrArray* pAttrArray; const ScAttrArray* pAttrArray;
sal_uLong nNumFormat; sal_uLong nNumFormat;
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "cellform.hxx" #include "cellform.hxx"
#include "segmenttree.hxx" #include "segmenttree.hxx"
#include "progress.hxx" #include "progress.hxx"
#include "queryparam.hxx"
#include "queryentry.hxx" #include "queryentry.hxx"
#include "globstr.hrc" #include "globstr.hrc"
#include "tools/fract.hxx" #include "tools/fract.hxx"
...@@ -1085,7 +1086,7 @@ ScBaseCell* ScCellIterator::GetNext() ...@@ -1085,7 +1086,7 @@ ScBaseCell* ScCellIterator::GetNext()
ScQueryCellIterator::ScQueryCellIterator(ScDocument* pDocument, SCTAB nTable, ScQueryCellIterator::ScQueryCellIterator(ScDocument* pDocument, SCTAB nTable,
const ScQueryParam& rParam, sal_Bool bMod ) : const ScQueryParam& rParam, sal_Bool bMod ) :
aParam (rParam), mpParam(new ScQueryParam(rParam)),
pDoc( pDocument ), pDoc( pDocument ),
nTab( nTable), nTab( nTable),
nStopOnMismatch( nStopOnMismatchDisabled ), nStopOnMismatch( nStopOnMismatchDisabled ),
...@@ -1093,16 +1094,16 @@ ScQueryCellIterator::ScQueryCellIterator(ScDocument* pDocument, SCTAB nTable, ...@@ -1093,16 +1094,16 @@ ScQueryCellIterator::ScQueryCellIterator(ScDocument* pDocument, SCTAB nTable,
bAdvanceQuery( false ), bAdvanceQuery( false ),
bIgnoreMismatchOnLeadingStrings( false ) bIgnoreMismatchOnLeadingStrings( false )
{ {
nCol = aParam.nCol1; nCol = mpParam->nCol1;
nRow = aParam.nRow1; nRow = mpParam->nRow1;
nColRow = 0; // wird bei GetFirst initialisiert nColRow = 0; // wird bei GetFirst initialisiert
SCSIZE i; SCSIZE i;
if (bMod) // sonst schon eingetragen if (bMod) // sonst schon eingetragen
{ {
SCSIZE nCount = aParam.GetEntryCount(); SCSIZE nCount = mpParam->GetEntryCount();
for (i = 0; (i < nCount) && (aParam.GetEntry(i).bDoQuery); ++i) for (i = 0; (i < nCount) && (mpParam->GetEntry(i).bDoQuery); ++i)
{ {
ScQueryEntry& rEntry = aParam.GetEntry(i); ScQueryEntry& rEntry = mpParam->GetEntry(i);
ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
sal_uInt32 nIndex = 0; sal_uInt32 nIndex = 0;
bool bNumber = pDoc->GetFormatTable()->IsNumberFormat( bool bNumber = pDoc->GetFormatTable()->IsNumberFormat(
...@@ -1120,26 +1121,26 @@ ScBaseCell* ScQueryCellIterator::GetThis() ...@@ -1120,26 +1121,26 @@ ScBaseCell* ScQueryCellIterator::GetThis()
if (nTab >= pDoc->GetTableCount()) if (nTab >= pDoc->GetTableCount())
OSL_FAIL("try to access index out of bounds, FIX IT"); OSL_FAIL("try to access index out of bounds, FIX IT");
ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol]; ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol];
const ScQueryEntry& rEntry = aParam.GetEntry(0); const ScQueryEntry& rEntry = mpParam->GetEntry(0);
const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); const ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
SCCOLROW nFirstQueryField = rEntry.nField; SCCOLROW nFirstQueryField = rEntry.nField;
bool bAllStringIgnore = bIgnoreMismatchOnLeadingStrings && bool bAllStringIgnore = bIgnoreMismatchOnLeadingStrings &&
rItem.meType != ScQueryEntry::ByString; rItem.meType != ScQueryEntry::ByString;
bool bFirstStringIgnore = bIgnoreMismatchOnLeadingStrings && bool bFirstStringIgnore = bIgnoreMismatchOnLeadingStrings &&
!aParam.bHasHeader && rItem.meType == ScQueryEntry::ByString && !mpParam->bHasHeader && rItem.meType == ScQueryEntry::ByString &&
((aParam.bByRow && nRow == aParam.nRow1) || ((mpParam->bByRow && nRow == mpParam->nRow1) ||
(!aParam.bByRow && nCol == aParam.nCol1)); (!mpParam->bByRow && nCol == mpParam->nCol1));
for ( ;; ) for ( ;; )
{ {
if ( nRow > aParam.nRow2 ) if ( nRow > mpParam->nRow2 )
{ {
nRow = aParam.nRow1; nRow = mpParam->nRow1;
if (aParam.bHasHeader && aParam.bByRow) if (mpParam->bHasHeader && mpParam->bByRow)
nRow++; nRow++;
do do
{ {
if ( ++nCol > aParam.nCol2 ) if ( ++nCol > mpParam->nCol2 )
return NULL; // Ende und Aus return NULL; // Ende und Aus
if ( bAdvanceQuery ) if ( bAdvanceQuery )
{ {
...@@ -1150,15 +1151,15 @@ ScBaseCell* ScQueryCellIterator::GetThis() ...@@ -1150,15 +1151,15 @@ ScBaseCell* ScQueryCellIterator::GetThis()
} while ( pCol->nCount == 0 ); } while ( pCol->nCount == 0 );
pCol->Search( nRow, nColRow ); pCol->Search( nRow, nColRow );
bFirstStringIgnore = bIgnoreMismatchOnLeadingStrings && bFirstStringIgnore = bIgnoreMismatchOnLeadingStrings &&
!aParam.bHasHeader && rItem.meType == ScQueryEntry::ByString && !mpParam->bHasHeader && rItem.meType == ScQueryEntry::ByString &&
aParam.bByRow; mpParam->bByRow;
} }
while ( nColRow < pCol->nCount && pCol->pItems[nColRow].nRow < nRow ) while ( nColRow < pCol->nCount && pCol->pItems[nColRow].nRow < nRow )
nColRow++; nColRow++;
if ( nColRow < pCol->nCount && if ( nColRow < pCol->nCount &&
(nRow = pCol->pItems[nColRow].nRow) <= aParam.nRow2 ) (nRow = pCol->pItems[nColRow].nRow) <= mpParam->nRow2 )
{ {
ScBaseCell* pCell = pCol->pItems[nColRow].pCell; ScBaseCell* pCell = pCol->pItems[nColRow].pCell;
if ( pCell->GetCellType() == CELLTYPE_NOTE ) if ( pCell->GetCellType() == CELLTYPE_NOTE )
...@@ -1168,7 +1169,7 @@ ScBaseCell* ScQueryCellIterator::GetThis() ...@@ -1168,7 +1169,7 @@ ScBaseCell* ScQueryCellIterator::GetThis()
else else
{ {
bool bTestEqualCondition; bool bTestEqualCondition;
if ( (pDoc->maTabs[nTab])->ValidQuery( nRow, aParam, if ( (pDoc->maTabs[nTab])->ValidQuery( nRow, *mpParam,
(nCol == static_cast<SCCOL>(nFirstQueryField) ? pCell : NULL), (nCol == static_cast<SCCOL>(nFirstQueryField) ? pCell : NULL),
(nTestEqualCondition ? &bTestEqualCondition : NULL) ) ) (nTestEqualCondition ? &bTestEqualCondition : NULL) ) )
{ {
...@@ -1211,7 +1212,7 @@ ScBaseCell* ScQueryCellIterator::GetThis() ...@@ -1211,7 +1212,7 @@ ScBaseCell* ScQueryCellIterator::GetThis()
} }
} }
else else
nRow = aParam.nRow2 + 1; // Naechste Spalte nRow = mpParam->nRow2 + 1; // Naechste Spalte
bFirstStringIgnore = false; bFirstStringIgnore = false;
} }
} }
...@@ -1220,9 +1221,9 @@ ScBaseCell* ScQueryCellIterator::GetFirst() ...@@ -1220,9 +1221,9 @@ ScBaseCell* ScQueryCellIterator::GetFirst()
{ {
if (nTab >= pDoc->GetTableCount()) if (nTab >= pDoc->GetTableCount())
OSL_FAIL("try to access index out of bounds, FIX IT"); OSL_FAIL("try to access index out of bounds, FIX IT");
nCol = aParam.nCol1; nCol = mpParam->nCol1;
nRow = aParam.nRow1; nRow = mpParam->nRow1;
if (aParam.bHasHeader) if (mpParam->bHasHeader)
nRow++; nRow++;
ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol]; ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol];
pCol->Search( nRow, nColRow ); pCol->Search( nRow, nColRow );
...@@ -1241,10 +1242,10 @@ ScBaseCell* ScQueryCellIterator::GetNext() ...@@ -1241,10 +1242,10 @@ ScBaseCell* ScQueryCellIterator::GetNext()
void ScQueryCellIterator::AdvanceQueryParamEntryField() void ScQueryCellIterator::AdvanceQueryParamEntryField()
{ {
SCSIZE nEntries = aParam.GetEntryCount(); SCSIZE nEntries = mpParam->GetEntryCount();
for ( SCSIZE j = 0; j < nEntries; j++ ) for ( SCSIZE j = 0; j < nEntries; j++ )
{ {
ScQueryEntry& rEntry = aParam.GetEntry( j ); ScQueryEntry& rEntry = mpParam->GetEntry( j );
if ( rEntry.bDoQuery ) if ( rEntry.bDoQuery )
{ {
if ( rEntry.nField < MAXCOL ) if ( rEntry.nField < MAXCOL )
...@@ -1269,9 +1270,9 @@ sal_Bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol, ...@@ -1269,9 +1270,9 @@ sal_Bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
SetStopOnMismatch( sal_True ); // assume sorted keys SetStopOnMismatch( sal_True ); // assume sorted keys
SetTestEqualCondition( sal_True ); SetTestEqualCondition( sal_True );
bIgnoreMismatchOnLeadingStrings = bIgnoreMismatchOnLeadingStringsP; bIgnoreMismatchOnLeadingStrings = bIgnoreMismatchOnLeadingStringsP;
bool bRegExp = aParam.bRegExp && aParam.GetEntry(0).GetQueryItem().meType == ScQueryEntry::ByString; bool bRegExp = mpParam->bRegExp && mpParam->GetEntry(0).GetQueryItem().meType == ScQueryEntry::ByString;
bool bBinary = !bRegExp && aParam.bByRow && (aParam.GetEntry(0).eOp == bool bBinary = !bRegExp && mpParam->bByRow && (mpParam->GetEntry(0).eOp ==
SC_LESS_EQUAL || aParam.GetEntry(0).eOp == SC_GREATER_EQUAL); SC_LESS_EQUAL || mpParam->GetEntry(0).eOp == SC_GREATER_EQUAL);
if (bBinary ? (BinarySearch() ? GetThis() : 0) : GetFirst()) if (bBinary ? (BinarySearch() ? GetThis() : 0) : GetFirst())
{ {
// First equal entry or last smaller than (greater than) entry. // First equal entry or last smaller than (greater than) entry.
...@@ -1297,10 +1298,10 @@ sal_Bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol, ...@@ -1297,10 +1298,10 @@ sal_Bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
if ( IsEqualConditionFulfilled() ) if ( IsEqualConditionFulfilled() )
{ {
// Position on last equal entry. // Position on last equal entry.
SCSIZE nEntries = aParam.GetEntryCount(); SCSIZE nEntries = mpParam->GetEntryCount();
for ( SCSIZE j = 0; j < nEntries; j++ ) for ( SCSIZE j = 0; j < nEntries; j++ )
{ {
ScQueryEntry& rEntry = aParam.GetEntry( j ); ScQueryEntry& rEntry = mpParam->GetEntry( j );
if ( rEntry.bDoQuery ) if ( rEntry.bDoQuery )
{ {
switch ( rEntry.eOp ) switch ( rEntry.eOp )
...@@ -1333,15 +1334,15 @@ sal_Bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol, ...@@ -1333,15 +1334,15 @@ sal_Bool ScQueryCellIterator::FindEqualOrSortedLastInRange( SCCOL& nFoundCol,
nColRow = nColRowSave; nColRow = nColRowSave;
return sal_True; return sal_True;
} }
if ( (bSearchForEqualAfterMismatch || aParam.bRegExp) && if ( (bSearchForEqualAfterMismatch || mpParam->bRegExp) &&
StoppedOnMismatch() ) StoppedOnMismatch() )
{ {
// Assume found entry to be the last value less than respectively // Assume found entry to be the last value less than respectively
// greater than the query. But keep on searching for an equal match. // greater than the query. But keep on searching for an equal match.
SCSIZE nEntries = aParam.GetEntryCount(); SCSIZE nEntries = mpParam->GetEntryCount();
for ( SCSIZE j = 0; j < nEntries; j++ ) for ( SCSIZE j = 0; j < nEntries; j++ )
{ {
ScQueryEntry& rEntry = aParam.GetEntry( j ); ScQueryEntry& rEntry = mpParam->GetEntry( j );
if ( rEntry.bDoQuery ) if ( rEntry.bDoQuery )
{ {
switch ( rEntry.eOp ) switch ( rEntry.eOp )
...@@ -1387,26 +1388,26 @@ ScBaseCell* ScQueryCellIterator::BinarySearch() ...@@ -1387,26 +1388,26 @@ ScBaseCell* ScQueryCellIterator::BinarySearch()
{ {
if (nTab >= pDoc->GetTableCount()) if (nTab >= pDoc->GetTableCount())
OSL_FAIL("try to access index out of bounds, FIX IT"); OSL_FAIL("try to access index out of bounds, FIX IT");
nCol = aParam.nCol1; nCol = mpParam->nCol1;
ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol]; ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol];
if (!pCol->nCount) if (!pCol->nCount)
return 0; return 0;
ScBaseCell* pCell; ScBaseCell* pCell;
SCSIZE nHi, nLo; SCSIZE nHi, nLo;
CollatorWrapper* pCollator = (aParam.bCaseSens ? ScGlobal::GetCaseCollator() : CollatorWrapper* pCollator = (mpParam->bCaseSens ? ScGlobal::GetCaseCollator() :
ScGlobal::GetCollator()); ScGlobal::GetCollator());
SvNumberFormatter& rFormatter = *(pDoc->GetFormatTable()); SvNumberFormatter& rFormatter = *(pDoc->GetFormatTable());
const ScQueryEntry& rEntry = aParam.GetEntry(0); const ScQueryEntry& rEntry = mpParam->GetEntry(0);
const ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); const ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
bool bLessEqual = rEntry.eOp == SC_LESS_EQUAL; bool bLessEqual = rEntry.eOp == SC_LESS_EQUAL;
bool bByString = rItem.meType == ScQueryEntry::ByString; bool bByString = rItem.meType == ScQueryEntry::ByString;
bool bAllStringIgnore = bIgnoreMismatchOnLeadingStrings && !bByString; bool bAllStringIgnore = bIgnoreMismatchOnLeadingStrings && !bByString;
bool bFirstStringIgnore = bIgnoreMismatchOnLeadingStrings && bool bFirstStringIgnore = bIgnoreMismatchOnLeadingStrings &&
!aParam.bHasHeader && bByString; !mpParam->bHasHeader && bByString;
nRow = aParam.nRow1; nRow = mpParam->nRow1;
if (aParam.bHasHeader) if (mpParam->bHasHeader)
nRow++; nRow++;
const ColEntry* pItems = pCol->pItems; const ColEntry* pItems = pCol->pItems;
if (pCol->Search( nRow, nLo ) && bFirstStringIgnore && if (pCol->Search( nRow, nLo ) && bFirstStringIgnore &&
...@@ -1422,7 +1423,7 @@ ScBaseCell* ScQueryCellIterator::BinarySearch() ...@@ -1422,7 +1423,7 @@ ScBaseCell* ScQueryCellIterator::BinarySearch()
(rEntry.eOp == SC_EQUAL && nTmp != 0)) (rEntry.eOp == SC_EQUAL && nTmp != 0))
++nLo; ++nLo;
} }
if (!pCol->Search( aParam.nRow2, nHi ) && nHi>0) if (!pCol->Search( mpParam->nRow2, nHi ) && nHi>0)
--nHi; --nHi;
while (bAllStringIgnore && nLo <= nHi && nLo < pCol->nCount && while (bAllStringIgnore && nLo <= nHi && nLo < pCol->nCount &&
pItems[nLo].pCell->HasStringData()) pItems[nLo].pCell->HasStringData())
...@@ -1638,7 +1639,7 @@ ScBaseCell* ScQueryCellIterator::BinarySearch() ...@@ -1638,7 +1639,7 @@ ScBaseCell* ScQueryCellIterator::BinarySearch()
// --nLo with nLastInRange == nLo-1. Both conditions combined yield: // --nLo with nLastInRange == nLo-1. Both conditions combined yield:
nLo = nLastInRange; nLo = nLastInRange;
} }
if (nLo < pCol->nCount && pCol->pItems[nLo].nRow <= aParam.nRow2) if (nLo < pCol->nCount && pCol->pItems[nLo].nRow <= mpParam->nRow2)
{ {
nRow = pItems[nLo].nRow; nRow = pItems[nLo].nRow;
pCell = pItems[nLo].pCell; pCell = pItems[nLo].pCell;
...@@ -1646,7 +1647,7 @@ ScBaseCell* ScQueryCellIterator::BinarySearch() ...@@ -1646,7 +1647,7 @@ ScBaseCell* ScQueryCellIterator::BinarySearch()
} }
else else
{ {
nRow = aParam.nRow2 + 1; nRow = mpParam->nRow2 + 1;
pCell = 0; pCell = 0;
nColRow = pCol->nCount - 1; nColRow = pCol->nCount - 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment