summaryrefslogtreecommitdiffstats
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-26 12:35:36 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-26 15:36:01 -0400
commit7c2dd80cbee59aadee20b59aacdf0ba437c765db (patch)
tree67a1327aa3261160840e99c3f83ca25ba3bb4601 /sc
parentAdd ScRefCellValue, which is ScCellValue without copied value. (diff)
downloadcore-7c2dd80cbee59aadee20b59aacdf0ba437c765db.tar.gz
core-7c2dd80cbee59aadee20b59aacdf0ba437c765db.zip
By using ScRefCellValue we can remove some duplicated code.
Change-Id: I75652172033e4ce00ac239e85d835c7cc9256fe2
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/chgtrack.hxx3
-rw-r--r--sc/inc/dociter.hxx12
-rw-r--r--sc/source/core/data/dociter.cxx187
-rw-r--r--sc/source/core/tool/chgtrack.cxx8
-rw-r--r--sc/source/core/tool/interpr1.cxx4
-rw-r--r--sc/source/core/tool/interpr5.cxx2
6 files changed, 59 insertions, 157 deletions
diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx
index b30cf1b1c9d2..6b06c222870a 100644
--- a/sc/inc/chgtrack.hxx
+++ b/sc/inc/chgtrack.hxx
@@ -37,7 +37,6 @@
class ScDocument;
class ScFormulaCell;
-class ScCellIterator;
enum ScChangeActionType
{
@@ -800,7 +799,7 @@ public:
rtl::OUString& rStr, ScDocument* pDoc, bool bFlag3D = false ) const;
static ScChangeActionContentCellType GetContentCellType( const ScCellValue& rCell );
- static ScChangeActionContentCellType GetContentCellType( const ScCellIterator& rIter );
+ static ScChangeActionContentCellType GetContentCellType( const ScRefCellValue& rIter );
// NewCell
bool IsMatrixOrigin() const;
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index 58d1215fad77..4f3ab2621d7c 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -24,6 +24,7 @@
#include <tools/solar.h>
#include "global.hxx"
#include "scdllapi.h"
+#include "cellvalue.hxx"
#include <memory>
@@ -45,7 +46,6 @@ struct ScQueryParam;
struct ScDBQueryParamInternal;
struct ScDBQueryParamMatrix;
class ScFormulaCell;
-struct ScCellValue;
class ScDocumentIterator // walk through all non-empty cells
{
@@ -222,13 +222,7 @@ private:
SCSIZE mnIndex;
bool mbSubTotal;
- CellType meCurType;
- OUString maCurString;
- union {
- double mfCurValue;
- const EditTextObject* mpCurEditText; // points to the original.
- ScFormulaCell* mpCurFormula; // points to the original.
- };
+ ScRefCellValue maCurCell;
void init();
bool getCurrent();
@@ -245,9 +239,11 @@ public:
const ScFormulaCell* getFormulaCell() const;
double getValue() const;
ScCellValue getCellValue() const;
+ ScRefCellValue getRefCellValue() const;
bool hasString() const;
bool hasNumeric() const;
+ bool hasEmptyData() const;
bool isEmpty() const;
bool equalsWithoutFormat( const ScAddress& rPos ) const;
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 9f7dd026499f..adb7787672d1 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -943,9 +943,7 @@ ScCellIterator::ScCellIterator( ScDocument* pDoc, const ScRange& rRange, bool bS
maStartPos(rRange.aStart),
maEndPos(rRange.aEnd),
mnIndex(0),
- mbSubTotal(bSTotal),
- meCurType(CELLTYPE_NONE),
- mfCurValue(0.0)
+ mbSubTotal(bSTotal)
{
init();
}
@@ -996,7 +994,7 @@ bool ScCellIterator::getCurrent()
maCurPos.IncTab();
if (maCurPos.Tab() > maEndPos.Tab())
{
- meCurType = CELLTYPE_NONE;
+ maCurCell.clear();
return false; // Over and out
}
}
@@ -1021,26 +1019,26 @@ bool ScCellIterator::getCurrent()
else
{
// Found it!
- meCurType = pCell->GetCellType();
- switch (meCurType)
+ maCurCell.meType = pCell->GetCellType();
+ switch (maCurCell.meType)
{
case CELLTYPE_VALUE:
- mfCurValue = static_cast<const ScValueCell*>(pCell)->GetValue();
+ maCurCell.mfValue = static_cast<const ScValueCell*>(pCell)->GetValue();
break;
case CELLTYPE_STRING:
- maCurString = static_cast<const ScStringCell*>(pCell)->GetString();
+ maCurCell.mpString = static_cast<const ScStringCell*>(pCell)->GetStringPtr();
break;
case CELLTYPE_EDIT:
- mpCurEditText = static_cast<const ScEditCell*>(pCell)->GetData();
+ maCurCell.mpEditText = static_cast<const ScEditCell*>(pCell)->GetData();
break;
case CELLTYPE_FORMULA:
- mpCurFormula = static_cast<ScFormulaCell*>(pCell);
+ maCurCell.mpFormula = static_cast<ScFormulaCell*>(pCell);
break;
default:
- meCurType = CELLTYPE_NONE;
+ maCurCell.meType = CELLTYPE_NONE;
}
- if (meCurType != CELLTYPE_NONE)
+ if (maCurCell.meType != CELLTYPE_NONE)
return true;
maCurPos.IncRow();
@@ -1057,21 +1055,21 @@ bool ScCellIterator::getCurrent()
CellType ScCellIterator::getType() const
{
- return meCurType;
+ return maCurCell.meType;
}
OUString ScCellIterator::getString()
{
- switch (meCurType)
+ switch (maCurCell.meType)
{
case CELLTYPE_STRING:
- return maCurString;
+ return *maCurCell.mpString;
case CELLTYPE_EDIT:
- if (mpCurEditText)
- return ScEditUtil::GetString(*mpCurEditText);
+ if (maCurCell.mpEditText)
+ return ScEditUtil::GetString(*maCurCell.mpEditText);
break;
case CELLTYPE_FORMULA:
- return mpCurFormula->GetString();
+ return maCurCell.mpFormula->GetString();
default:
;
}
@@ -1080,27 +1078,27 @@ OUString ScCellIterator::getString()
const EditTextObject* ScCellIterator::getEditText() const
{
- return mpCurEditText;
+ return maCurCell.mpEditText;
}
ScFormulaCell* ScCellIterator::getFormulaCell()
{
- return mpCurFormula;
+ return maCurCell.mpFormula;
}
const ScFormulaCell* ScCellIterator::getFormulaCell() const
{
- return mpCurFormula;
+ return maCurCell.mpFormula;
}
double ScCellIterator::getValue() const
{
- switch (meCurType)
+ switch (maCurCell.meType)
{
case CELLTYPE_VALUE:
- return mfCurValue;
+ return maCurCell.mfValue;
case CELLTYPE_FORMULA:
- return mpCurFormula->GetValue();
+ return maCurCell.mpFormula->GetValue();
default:
;
}
@@ -1110,21 +1108,21 @@ double ScCellIterator::getValue() const
ScCellValue ScCellIterator::getCellValue() const
{
ScCellValue aRet;
- aRet.meType = meCurType;
+ aRet.meType = maCurCell.meType;
- switch (meCurType)
+ switch (maCurCell.meType)
{
case CELLTYPE_STRING:
- aRet.mpString = new OUString(maCurString);
+ aRet.mpString = new OUString(*maCurCell.mpString);
break;
case CELLTYPE_EDIT:
- aRet.mpEditText = mpCurEditText->Clone();
+ aRet.mpEditText = maCurCell.mpEditText->Clone();
break;
case CELLTYPE_VALUE:
- aRet.mfValue = mfCurValue;
+ aRet.mfValue = maCurCell.mfValue;
break;
case CELLTYPE_FORMULA:
- aRet.mpFormula = mpCurFormula->Clone();
+ aRet.mpFormula = maCurCell.mpFormula->Clone();
break;
default:
;
@@ -1133,133 +1131,42 @@ ScCellValue ScCellIterator::getCellValue() const
return aRet;
}
-bool ScCellIterator::hasString() const
+ScRefCellValue ScCellIterator::getRefCellValue() const
{
- switch (meCurType)
- {
- case CELLTYPE_STRING:
- case CELLTYPE_EDIT:
- return true;
- case CELLTYPE_FORMULA:
- return !mpCurFormula->IsValue();
- default:
- ;
- }
+ return maCurCell;
+}
- return false;
+bool ScCellIterator::hasString() const
+{
+ return maCurCell.hasString();
}
bool ScCellIterator::hasNumeric() const
{
- switch (meCurType)
- {
- case CELLTYPE_VALUE:
- return true;
- case CELLTYPE_FORMULA:
- return mpCurFormula->IsValue();
- default:
- ;
- }
-
- return false;
+ return maCurCell.hasNumeric();
}
-bool ScCellIterator::isEmpty() const
+bool ScCellIterator::hasEmptyData() const
{
- switch (meCurType)
- {
- case CELLTYPE_NOTE:
- case CELLTYPE_NONE:
- return true;
- case CELLTYPE_FORMULA:
- return mpCurFormula->IsEmpty();
- default:
- ;
- }
- return false;
-}
+ if (maCurCell.isEmpty())
+ return true;
-namespace {
+ if (maCurCell.meType == CELLTYPE_FORMULA)
+ return maCurCell.mpFormula->IsEmpty();
-CellType adjustCellType( CellType eOrig )
-{
- switch (eOrig)
- {
- case CELLTYPE_NOTE:
- return CELLTYPE_NONE;
- case CELLTYPE_EDIT:
- return CELLTYPE_STRING;
- default:
- ;
- }
- return eOrig;
+ return false;
}
+bool ScCellIterator::isEmpty() const
+{
+ return maCurCell.isEmpty();
}
bool ScCellIterator::equalsWithoutFormat( const ScAddress& rPos ) const
{
- // Fetch the other cell first.
- if (!mpDoc->TableExists(rPos.Tab()))
- return false;
-
- ScTable& rTab = *mpDoc->maTabs[rPos.Tab()];
- if (!ValidColRow(rPos.Col(), rPos.Row()))
- return false;
-
- ScColumn& rCol = rTab.aCol[rPos.Col()];
- SCSIZE nIndex;
- if (!rCol.Search(rPos.Row(), nIndex))
- return false;
-
- ScBaseCell* pCell2 = rCol.maItems[nIndex].pCell;
-
- CellType eType1 = adjustCellType(meCurType);
- CellType eType2 = adjustCellType(pCell2->GetCellType());
- if (eType1 != eType2)
- return false;
-
- switch (eType1)
- {
- case CELLTYPE_NONE:
- // Both are empty.
- return true;
- case CELLTYPE_VALUE:
- return mfCurValue == static_cast<ScValueCell*>(pCell2)->GetValue();
- case CELLTYPE_STRING:
- {
- OUString aStr1;
- if (meCurType == CELLTYPE_STRING)
- aStr1 = maCurString;
- else if (meCurType == CELLTYPE_EDIT)
- aStr1 = ScEditUtil::GetString(*mpCurEditText);
-
- OUString aStr2 = pCell2->GetStringData();
- return aStr1 == aStr2;
- }
- case CELLTYPE_FORMULA:
- {
- ScTokenArray* pCode1 = mpCurFormula->GetCode();
- ScTokenArray* pCode2 = static_cast<ScFormulaCell*>(pCell2)->GetCode();
-
- if (pCode1->GetLen() != pCode2->GetLen())
- return false;
-
- sal_uInt16 n = pCode1->GetLen();
- formula::FormulaToken** ppToken1 = pCode1->GetArray();
- formula::FormulaToken** ppToken2 = pCode2->GetArray();
- for (sal_uInt16 i = 0; i < n; ++i)
- {
- if (!ppToken1[i]->TextEqual(*(ppToken2[i])))
- return false;
- }
-
- return true;
- }
- default:
- ;
- }
- return false;
+ ScRefCellValue aOther;
+ aOther.assign(*mpDoc, rPos);
+ return maCurCell.equalsWithoutFormat(aOther);
}
bool ScCellIterator::first()
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index b1b683c6d250..b5ce9c917cdb 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -1750,9 +1750,9 @@ ScChangeActionContentCellType ScChangeActionContent::GetContentCellType( const S
}
}
-ScChangeActionContentCellType ScChangeActionContent::GetContentCellType( const ScCellIterator& rIter )
+ScChangeActionContentCellType ScChangeActionContent::GetContentCellType( const ScRefCellValue& rCell )
{
- switch (rIter.getType())
+ switch (rCell.meType)
{
case CELLTYPE_VALUE:
case CELLTYPE_STRING:
@@ -1760,7 +1760,7 @@ ScChangeActionContentCellType ScChangeActionContent::GetContentCellType( const S
return SC_CACCT_NORMAL;
case CELLTYPE_FORMULA:
{
- const ScFormulaCell* pCell = rIter.getFormulaCell();
+ const ScFormulaCell* pCell = rCell.mpFormula;
switch (pCell->GetMatrixFlag())
{
case MM_NONE :
@@ -2676,7 +2676,7 @@ void ScChangeTrack::LookUpContents( const ScRange& rOrgRange,
ScCellIterator aIter( pRefDoc, rOrgRange );
for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
{
- if (!ScChangeActionContent::GetContentCellType(aIter))
+ if (!ScChangeActionContent::GetContentCellType(aIter.getRefCellValue()))
continue;
aBigPos.Set( aIter.GetPos().Col() + nDx, aIter.GetPos().Row() + nDy,
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 1b598cff89e9..574612c0b95a 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -4156,7 +4156,7 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, bool bTextAsZero )
ScCellIterator aIter( pDok, aRange, glSubTotal );
for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
{
- if (!aIter.isEmpty())
+ if (!aIter.hasEmptyData())
++nCount;
}
@@ -5372,7 +5372,7 @@ void ScInterpreter::ScCountEmptyCells()
ScCellIterator aIter( pDok, aRange, glSubTotal);
for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
{
- if (!aIter.isEmpty())
+ if (!aIter.hasEmptyData())
++nCount;
}
}
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 857449008d74..a9a432c3ea0e 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -428,7 +428,7 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken
{
nThisRow = aCellIter.GetPos().Row();
- if (aCellIter.isEmpty())
+ if (aCellIter.hasEmptyData())
{
aBucket.flush(*pMat, static_cast<SCSIZE>(nCol-nCol1));
continue;