[Libreoffice-commits] core.git: sc/inc sc/source
Jochen Nitschke
j.nitschke+logerrit at ok.de
Fri Jul 22 07:05:14 UTC 2016
sc/inc/column.hxx | 3 +-
sc/inc/formulacell.hxx | 2 -
sc/inc/types.hxx | 21 +++++++++++------
sc/source/core/data/column.cxx | 40 +++++++++++++++------------------
sc/source/core/data/formulacell.cxx | 34 +++++++++-------------------
sc/source/core/data/table2.cxx | 43 +++++++++++++++++-------------------
6 files changed, 68 insertions(+), 75 deletions(-)
New commits:
commit c6c8c2a8b132b1555be3efb7181bac9a074bc208
Author: Jochen Nitschke <j.nitschke+logerrit at ok.de>
Date: Thu Jul 21 15:05:01 2016 +0200
sc: convert MatrixEdge... to typed_flags
remove some unhelpful or obvious comments
replace numeric values in last loop of ScTable::HasBlockMatrixFragment
Change-Id: If7115b504689ce31b5caadbcae8ce2f5466e5b2a
Reviewed-on: https://gerrit.libreoffice.org/27378
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 4c2ebca..a73f7c4 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -66,6 +66,7 @@ class RowHeightContext;
class CompileFormulaContext;
struct SetFormulaDirtyContext;
class RefMovedHint;
+enum class MatrixEdge;
}
@@ -236,7 +237,7 @@ public:
void FindUsed( SCROW nStartRow, SCROW nEndRow, mdds::flat_segment_tree<SCROW, bool>& rUsed ) const;
SCSIZE VisibleCount( SCROW nStartRow, SCROW nEndRow ) const;
- sal_uInt16 GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const;
+ sc::MatrixEdge GetBlockMatrixEdges(SCROW nRow1, SCROW nRow2, sc::MatrixEdge nMask ) const;
bool HasSelectionMatrixFragment(const ScMarkData& rMark) const;
bool GetFirstVisibleAttr( SCROW& rFirstRow ) const;
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 28c6d09..987704f 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -295,7 +295,7 @@ public:
const ScMatrix* GetMatrix();
bool GetMatrixOrigin( ScAddress& rPos ) const;
void GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows );
- sal_uInt16 GetMatrixEdge( ScAddress& rOrgPos ) const;
+ sc::MatrixEdge GetMatrixEdge( ScAddress& rOrgPos ) const;
sal_uInt16 GetErrCode(); // interpret first if necessary
sal_uInt16 GetRawError(); // don't interpret, just return code or result error
bool GetErrorOrValue( sal_uInt16& rErr, double& rVal );
diff --git a/sc/inc/types.hxx b/sc/inc/types.hxx
index ed944b0..5fc451b 100644
--- a/sc/inc/types.hxx
+++ b/sc/inc/types.hxx
@@ -13,6 +13,7 @@
#include <sal/types.h>
#include <boost/intrusive_ptr.hpp>
+#include <o3tl/typed_flags_set.hxx>
class ScMatrix;
@@ -60,13 +61,15 @@ enum ScFormulaVectorState
namespace sc {
-const sal_uInt16 MatrixEdgeNothing = 0;
-const sal_uInt16 MatrixEdgeInside = 1;
-const sal_uInt16 MatrixEdgeBottom = 2;
-const sal_uInt16 MatrixEdgeLeft = 4;
-const sal_uInt16 MatrixEdgeTop = 8;
-const sal_uInt16 MatrixEdgeRight = 16;
-const sal_uInt16 MatrixEdgeOpen = 32;
+enum class MatrixEdge{
+ Nothing = 0,
+ Inside = 1,
+ Bottom = 2,
+ Left = 4,
+ Top = 8,
+ Right = 16,
+ Open = 32
+}; // typed_flags, template outside of sc namespace
enum GroupCalcState
{
@@ -121,6 +124,10 @@ enum StartListeningType
}
+namespace o3tl{
+ template<> struct typed_flags<sc::MatrixEdge> : o3tl::is_typed_flags<sc::MatrixEdge, 63> {};
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 00664c6..3bc430a 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -115,12 +115,12 @@ SCsROW ScColumn::GetNextUnprotected( SCROW nRow, bool bUp ) const
return pAttrArray->GetNextUnprotected(nRow, bUp);
}
-sal_uInt16 ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sal_uInt16 nMask ) const
+sc::MatrixEdge ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sc::MatrixEdge nMask ) const
{
using namespace sc;
if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow1 > nRow2)
- return 0;
+ return MatrixEdge::Nothing;
ScAddress aOrigin(ScAddress::INITIALIZE_INVALID);
@@ -128,17 +128,17 @@ sal_uInt16 ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sal_uInt16 n
{
std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(nRow1);
if (aPos.first->type != sc::element_type_formula)
- return 0;
+ return MatrixEdge::Nothing;
const ScFormulaCell* pCell = sc::formula_block::at(*aPos.first->data, aPos.second);
if (!pCell->GetMatrixFlag())
- return 0;
+ return MatrixEdge::Nothing;
return pCell->GetMatrixEdge(aOrigin);
}
bool bOpen = false;
- sal_uInt16 nEdges = 0;
+ MatrixEdge nEdges = MatrixEdge::Nothing;
std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(nRow1);
sc::CellStoreType::const_iterator it = aPos.first;
@@ -165,29 +165,27 @@ sal_uInt16 ScColumn::GetBlockMatrixEdges( SCROW nRow1, SCROW nRow2, sal_uInt16 n
continue;
nEdges = pCell->GetMatrixEdge(aOrigin);
- if (!nEdges)
+ if (nEdges == MatrixEdge::Nothing)
continue;
- if (nEdges & MatrixEdgeTop)
+ if (nEdges & MatrixEdge::Top)
bOpen = true; // top edge opens, keep on looking
else if (!bOpen)
- return nEdges | MatrixEdgeOpen; // there's something that wasn't opened
- else if (nEdges & MatrixEdgeInside)
+ return nEdges | MatrixEdge::Open; // there's something that wasn't opened
+ else if (nEdges & MatrixEdge::Inside)
return nEdges; // inside
- // (nMask & 16 and (4 and not 16)) or
- // (nMask & 4 and (16 and not 4))
- if (((nMask & MatrixEdgeRight) && (nEdges & MatrixEdgeLeft) && !(nEdges & MatrixEdgeRight)) ||
- ((nMask & MatrixEdgeLeft) && (nEdges & MatrixEdgeRight) && !(nEdges & MatrixEdgeLeft)))
+ if (((nMask & MatrixEdge::Right) && (nEdges & MatrixEdge::Left) && !(nEdges & MatrixEdge::Right)) ||
+ ((nMask & MatrixEdge::Left) && (nEdges & MatrixEdge::Right) && !(nEdges & MatrixEdge::Left)))
return nEdges; // only left/right edge
- if (nEdges & MatrixEdgeBottom)
+ if (nEdges & MatrixEdge::Bottom)
bOpen = false; // bottom edge closes
}
nRow += nEnd;
}
if (bOpen)
- nEdges |= MatrixEdgeOpen; // not closed, matrix continues
+ nEdges |= MatrixEdge::Open; // not closed, matrix continues
return nEdges;
}
@@ -241,24 +239,24 @@ bool ScColumn::HasSelectionMatrixFragment(const ScMarkData& rMark) const
// cell is not a part of a matrix.
continue;
- sal_uInt16 nEdges = pCell->GetMatrixEdge(aOrigin);
- if (!nEdges)
+ MatrixEdge nEdges = pCell->GetMatrixEdge(aOrigin);
+ if (nEdges == MatrixEdge::Nothing)
continue;
bool bFound = false;
- if (nEdges & MatrixEdgeTop)
+ if (nEdges & MatrixEdge::Top)
bOpen = true; // top edge opens, keep on looking
else if (!bOpen)
return true; // there's something that wasn't opened
- else if (nEdges & MatrixEdgeInside)
+ else if (nEdges & MatrixEdge::Inside)
bFound = true; // inside, all selected?
- if ((((nEdges & MatrixEdgeLeft) | MatrixEdgeRight) ^ ((nEdges & MatrixEdgeRight) | MatrixEdgeLeft)))
+ if ((((nEdges & MatrixEdge::Left) | MatrixEdge::Right) ^ ((nEdges & MatrixEdge::Right) | MatrixEdge::Left)))
// either left or right, but not both.
bFound = true; // only left/right edge, all selected?
- if (nEdges & MatrixEdgeBottom)
+ if (nEdges & MatrixEdge::Bottom)
bOpen = false; // bottom edge closes
if (bFound)
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 4d3936b..407cd47 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2664,19 +2664,7 @@ bool ScFormulaCell::GetMatrixOrigin( ScAddress& rPos ) const
return false;
}
-/*
- Edge-Values:
-
- 8
- 4 16
- 2
-
- inside: 1
- outside: 0
- (reserved: open: 32)
- */
-
-sal_uInt16 ScFormulaCell::GetMatrixEdge( ScAddress& rOrgPos ) const
+sc::MatrixEdge ScFormulaCell::GetMatrixEdge( ScAddress& rOrgPos ) const
{
switch ( cMatrixFlag )
{
@@ -2687,7 +2675,7 @@ sal_uInt16 ScFormulaCell::GetMatrixEdge( ScAddress& rOrgPos ) const
static SCROW nR;
ScAddress aOrg;
if ( !GetMatrixOrigin( aOrg ) )
- return 0; // bad luck..
+ return sc::MatrixEdge::Nothing;
if ( aOrg != rOrgPos )
{ // First time or a different matrix than last time.
rOrgPos = aOrg;
@@ -2752,25 +2740,25 @@ sal_uInt16 ScFormulaCell::GetMatrixEdge( ScAddress& rOrgPos ) const
aMsg.append(OUStringToOString(aTmp, RTL_TEXTENCODING_ASCII_US));
OSL_FAIL(aMsg.getStr());
#endif
- return 0; // bad luck ...
+ return sc::MatrixEdge::Nothing;
}
}
// here we are, healthy and clean, somewhere in between
SCsCOL dC = aPos.Col() - aOrg.Col();
SCsROW dR = aPos.Row() - aOrg.Row();
- sal_uInt16 nEdges = 0;
+ sc::MatrixEdge nEdges = sc::MatrixEdge::Nothing;
if ( dC >= 0 && dR >= 0 && dC < nC && dR < nR )
{
if ( dC == 0 )
- nEdges |= sc::MatrixEdgeLeft; // left edge
+ nEdges |= sc::MatrixEdge::Left;
if ( dC+1 == nC )
- nEdges |= sc::MatrixEdgeRight; // right edge
+ nEdges |= sc::MatrixEdge::Right;
if ( dR == 0 )
- nEdges |= sc::MatrixEdgeTop; // top edge
+ nEdges |= sc::MatrixEdge::Top;
if ( dR+1 == nR )
- nEdges |= sc::MatrixEdgeBottom; // bottom edge
- if ( !nEdges )
- nEdges = sc::MatrixEdgeInside; // inside
+ nEdges |= sc::MatrixEdge::Bottom;
+ if ( nEdges == sc::MatrixEdge::Nothing )
+ nEdges = sc::MatrixEdge::Inside;
}
#if OSL_DEBUG_LEVEL > 0
else
@@ -2795,7 +2783,7 @@ sal_uInt16 ScFormulaCell::GetMatrixEdge( ScAddress& rOrgPos ) const
return nEdges;
}
default:
- return 0;
+ return sc::MatrixEdge::Nothing;
}
}
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 682ce08..788ce13 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -2113,78 +2113,77 @@ bool ScTable::HasBlockMatrixFragment( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCR
{
using namespace sc;
- sal_uInt16 nEdges = 0;
+ MatrixEdge nEdges = MatrixEdge::Nothing;
if ( nCol1 == nCol2 )
{ // left and right column
- const sal_uInt16 n = MatrixEdgeLeft | MatrixEdgeRight;
+ const MatrixEdge n = MatrixEdge::Left | MatrixEdge::Right;
nEdges = aCol[nCol1].GetBlockMatrixEdges( nRow1, nRow2, n );
- // not (4 and 16) or 1 or 32
- if (nEdges && (((nEdges & n) != n) || (nEdges & (MatrixEdgeInside|MatrixEdgeOpen))))
+ if ((nEdges != MatrixEdge::Nothing) && (((nEdges & n)!=n) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
return true; // left or right edge is missing or open
}
else
{ // left column
- nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdgeLeft);
- // not 4 or 1 or 32
- if (nEdges && (((nEdges & MatrixEdgeLeft) != MatrixEdgeLeft) || (nEdges & (MatrixEdgeInside|MatrixEdgeOpen))))
+ nEdges = aCol[nCol1].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Left);
+ if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Left)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
return true; // left edge missing or open
// right column
- nEdges = aCol[nCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdgeRight);
- // not 16 or 1 or 32
- if (nEdges && (((nEdges & MatrixEdgeRight) != MatrixEdgeRight) || (nEdges & (MatrixEdgeInside|MatrixEdgeOpen))))
+ nEdges = aCol[nCol2].GetBlockMatrixEdges(nRow1, nRow2, MatrixEdge::Right);
+ if ((nEdges != MatrixEdge::Nothing) && ((!(nEdges & MatrixEdge::Right)) || (nEdges & (MatrixEdge::Inside|MatrixEdge::Open))))
return true; // right edge is missing or open
}
if ( nRow1 == nRow2 )
{ // Row on top and on bottom
bool bOpen = false;
- const sal_uInt16 n = MatrixEdgeBottom | MatrixEdgeTop;
+ const MatrixEdge n = MatrixEdge::Bottom | MatrixEdge::Top;
for ( SCCOL i=nCol1; i<=nCol2; i++)
{
nEdges = aCol[i].GetBlockMatrixEdges( nRow1, nRow1, n );
- if ( nEdges )
+ if (nEdges != MatrixEdge::Nothing)
{
if ( (nEdges & n) != n )
return true; // Top or bottom edge missing
- if (nEdges & MatrixEdgeLeft)
+ if (nEdges & MatrixEdge::Left)
bOpen = true; // left edge open, continue
else if ( !bOpen )
return true; // Something exist that has not been opened
- if (nEdges & MatrixEdgeRight)
+ if (nEdges & MatrixEdge::Right)
bOpen = false; // Close right edge
}
}
if ( bOpen )
- return true; // continue
+ return true;
}
else
{
- sal_uInt16 j, n;
+ int j;
+ MatrixEdge n;
SCROW nR;
- // first rop row, then bottom row
- for ( j=0, nR=nRow1, n=8; j<2; j++, nR=nRow2, n=2 )
+ // first top row, then bottom row
+ for ( j=0, n = MatrixEdge::Top, nR=nRow1; j<2;
+ j++, n = MatrixEdge::Bottom, nR=nRow2)
{
bool bOpen = false;
for ( SCCOL i=nCol1; i<=nCol2; i++)
{
nEdges = aCol[i].GetBlockMatrixEdges( nR, nR, n );
- if ( nEdges )
+ if ( nEdges != MatrixEdge::Nothing)
{
// in top row no top edge respectively
// in bottom row no bottom edge
if ( (nEdges & n) != n )
return true;
- if (nEdges & MatrixEdgeLeft)
+ if (nEdges & MatrixEdge::Left)
bOpen = true; // open left edge, continue
else if ( !bOpen )
return true; // Something exist that has not been opened
- if (nEdges & MatrixEdgeRight)
+ if (nEdges & MatrixEdge::Right)
bOpen = false; // Close right edge
}
}
if ( bOpen )
- return true; // continue
+ return true;
}
}
return false;
More information about the Libreoffice-commits
mailing list