[Libreoffice-commits] .: 9 commits - sc/inc sc/source
Ivan Timofeev
ivantimofeev at kemper.freedesktop.org
Wed Mar 28 10:24:25 PDT 2012
sc/inc/chartpos.hxx | 10 +-
sc/source/core/tool/chartpos.cxx | 161 +++++++++++++++++++--------------------
2 files changed, 88 insertions(+), 83 deletions(-)
New commits:
commit 6b170f3d0aa519c6fd4e3ee92421f5a87ab511e3
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Wed Mar 28 21:06:03 2012 +0400
WaE: declaration of 'it' shadows a previous local
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 7ab9e43..78ea6e7 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -409,8 +409,7 @@ void ScChartPositioner::CreatePositionMap()
sal_uLong nInsRow = (bNoGlue ? nNoGlueRow : nRow1);
for ( nRow = nRow1; nRow <= nRow2; nRow++, nInsRow++ )
{
- RowMap::const_iterator it = pCol->find( nInsRow );
- if ( it == pCol->end() )
+ if ( pCol->find( nInsRow ) == pCol->end() )
{
pCol->insert( RowMap::value_type( nInsRow, new ScAddress( nCol, nRow, nTab ) ) );
}
commit 82e0247c7a36aedf7ecf55488360f9abeb89726a
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Wed Mar 28 21:03:17 2012 +0400
remove the wrongly placed semicolon
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 0d963f1..7ab9e43 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -565,7 +565,7 @@ ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
ppData[ nIndex ] = pPosIter->second;
++pPosIter;
}
- for ( ; nRow < nRowCount; nRow++, nIndex++ ) ;
+ for ( ; nRow < nRowCount; nRow++, nIndex++ )
ppData[ nIndex ] = NULL;
++pColIter;
commit 8affd7e908fe695c548da702cafe76a8b031fdef
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Wed Mar 28 18:54:13 2012 +0400
this iterator should point to where the insert should start to search
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index cdc27f6..0d963f1 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -399,7 +399,7 @@ void ScChartPositioner::CreatePositionMap()
if ( it == pCols->end() )
{
pCol = new RowMap;
- pCols->insert(it, ColumnMap::value_type( nInsCol, pCol ) );
+ pCols->insert( ColumnMap::value_type( nInsCol, pCol ) );
}
else
pCol = it->second;
@@ -412,7 +412,7 @@ void ScChartPositioner::CreatePositionMap()
RowMap::const_iterator it = pCol->find( nInsRow );
if ( it == pCol->end() )
{
- pCol->insert(it, RowMap::value_type( nInsRow, new ScAddress( nCol, nRow, nTab ) ) );
+ pCol->insert( RowMap::value_type( nInsRow, new ScAddress( nCol, nRow, nTab ) ) );
}
}
}
commit 8627b0a297d6a2b7461bb53da2f434c397cb2603
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Tue Mar 27 23:03:03 2012 +0400
there was Table::Insert, let's use map::insert as a replacement
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index bae4802..cdc27f6 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -475,7 +475,7 @@ void ScChartPositioner::CreatePositionMap()
{
sal_uLong nKey = it1->first;
for (ColumnMap::const_iterator it2 = ++pCols->begin(); it2 != pCols->end(); ++it2 )
- (*it2->second)[ nKey ] = NULL; // keine Daten
+ it2->second->insert( RowMap::value_type( nKey, NULL )); // keine Daten
}
}
}
commit d976045c9d0296d2418687e0049ee49f9ebeded5
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Tue Mar 27 22:34:48 2012 +0400
if/else branches contain same code
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index cd3a4c9..bae4802 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -395,28 +395,15 @@ void ScChartPositioner::CreatePositionMap()
for ( nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol )
{
RowMap* pCol = NULL;
- if ( bNoGlue || eGlue == SC_CHARTGLUE_ROWS )
- { // meistens gleiche Cols
- ColumnMap::const_iterator it = pCols->find( nInsCol );
- if ( it == pCols->end() )
- {
- pCol = new RowMap;
- pCols->insert(it, ColumnMap::value_type( nInsCol, pCol ) );
- }
- else
- pCol = it->second;
+ ColumnMap::const_iterator it = pCols->find( nInsCol );
+ if ( it == pCols->end() )
+ {
+ pCol = new RowMap;
+ pCols->insert(it, ColumnMap::value_type( nInsCol, pCol ) );
}
else
- { // meistens neue Cols
- ColumnMap::const_iterator it = pCols->find( nInsCol );
- if ( it == pCols->end() )
- {
- pCol = new RowMap;
- pCols->insert(it, ColumnMap::value_type( nInsCol, pCol ) );
- }
- else
- pCol = it->second;
- }
+ pCol = it->second;
+
// bei anderer Tabelle wurde bereits neuer ColKey erzeugt,
// die Zeilen muessen fuer's Dummy fuellen gleich sein!
sal_uLong nInsRow = (bNoGlue ? nNoGlueRow : nRow1);
commit 154d071ddbdeab99014a3a60540c02da86299850
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Tue Mar 27 22:03:28 2012 +0400
prevent potential crashes
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 9ad37a3..cd3a4c9 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -526,18 +526,22 @@ ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
++pPos1Iter;
if ( nColAdd )
{ // eigenstaendig
- for ( SCROW nRow = 0; nRow < nRowCount; nRow++ )
+ SCROW nRow = 0;
+ for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
{
ppRowHeader[ nRow ] = pPos1Iter->second;
++pPos1Iter;
}
+ for ( ; nRow < nRowCount; nRow++ )
+ ppRowHeader[ nRow ] = NULL;
}
else
{ // Kopie
SCROW nRow = 0;
for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
{
- ppRowHeader[ nRow ] = new ScAddress( *pPos1Iter->second );
+ ppRowHeader[ nRow ] = pPos1Iter->second ?
+ new ScAddress( *pPos1Iter->second ) : NULL;
++pPos1Iter;
}
for ( ; nRow < nRowCount; nRow++ )
@@ -556,15 +560,17 @@ ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
{
RowMap* pCol2 = pColIter->second;
RowMap::const_iterator pPosIter = pCol2->begin();
- if ( nRowAdd )
+ if ( pPosIter != pCol2->end() )
{
- ppColHeader[ nCol ] = pPosIter->second; // eigenstaendig
- ++pPosIter;
+ if ( nRowAdd )
+ {
+ ppColHeader[ nCol ] = pPosIter->second; // eigenstaendig
+ ++pPosIter;
+ }
+ else
+ ppColHeader[ nCol ] = pPosIter->second ?
+ new ScAddress( *pPosIter->second ) : NULL;
}
- else if ( pPosIter != pCol2->end() )
- ppColHeader[ nCol ] = new ScAddress( *pPosIter->second );
- else
- ppColHeader[ nCol ] = NULL;
SCROW nRow = 0;
for ( ; nRow < nRowCount && pPosIter != pCol2->end(); nRow++, nIndex++ )
commit 3fb86cd30c394dcbade425a516bf9bf477a5b5d0
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Tue Mar 27 21:04:50 2012 +0400
do not touch first column
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 5d96cc0..9ad37a3 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -487,7 +487,7 @@ void ScChartPositioner::CreatePositionMap()
for ( sal_uLong n = 0; n < nCount; n++, ++it1 )
{
sal_uLong nKey = it1->first;
- for (ColumnMap::const_iterator it2 = pCols->begin(); it2 != pCols->end(); ++it2 )
+ for (ColumnMap::const_iterator it2 = ++pCols->begin(); it2 != pCols->end(); ++it2 )
(*it2->second)[ nKey ] = NULL; // keine Daten
}
}
commit a3d473683887bebeae34443eeb4b0d603b6d6de6
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date: Tue Mar 27 20:04:28 2012 +0400
remove unused include
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index fc10975..5d96cc0 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -29,8 +29,6 @@
// INCLUDE ---------------------------------------------------------------
-#include <tools/table.hxx>
-
#include "chartpos.hxx"
#include "document.hxx"
#include "rechead.hxx"
commit bfa76fc1a392452250022568d0ae326c13393d6b
Author: Noel Grandin <noel at peralex.com>
Date: Wed Mar 14 14:58:48 2012 +0200
Convert tools/table.hxx to std::map in ScChartPositionMap class in SC module
Along the way, simplify the ScChartPositioner::CreatePositionMap method,
it was using a unnecessarily complicated approach to allocating new objects.
diff --git a/sc/inc/chartpos.hxx b/sc/inc/chartpos.hxx
index 4d3dccb..7d81427 100644
--- a/sc/inc/chartpos.hxx
+++ b/sc/inc/chartpos.hxx
@@ -32,10 +32,14 @@
// -----------------------------------------------------------------------
#include "rangelst.hxx"
-
+#include <map>
class ScAddress;
-class Table;
+
+// map of row number to ScAddress*
+typedef std::map<sal_uLong, ScAddress*> RowMap;
+// map of column number to RowMap*
+typedef std::map<sal_uLong, RowMap*> ColumnMap;
class ScChartPositionMap
{
@@ -51,7 +55,7 @@ class ScChartPositionMap
ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
SCCOL nColAdd, // header columns
SCROW nRowAdd, // header rows
- Table& rCols // table with col tables with address*
+ ColumnMap& rCols // table with col tables with address*
);
~ScChartPositionMap(); //! deletes all ScAddress*
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 5b7617a..fc10975 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -382,12 +382,8 @@ void ScChartPositioner::CreatePositionMap()
GlueState();
- sal_Bool bNoGlue = (eGlue == SC_CHARTGLUE_NONE);
- Table* pCols = new Table;
- Table* pNewRowTable = new Table;
- ScAddress* pNewAddress = new ScAddress;
- Table* pCol;
- ScAddress* pPos;
+ const sal_Bool bNoGlue = (eGlue == SC_CHARTGLUE_NONE);
+ ColumnMap* pCols = new ColumnMap;
SCROW nNoGlueRow = 0;
for ( size_t i = 0, nRanges = aRangeListRef->size(); i < nRanges; ++i )
{
@@ -400,34 +396,38 @@ void ScChartPositioner::CreatePositionMap()
static_cast<sal_uLong>(nCol1));
for ( nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol )
{
+ RowMap* pCol = NULL;
if ( bNoGlue || eGlue == SC_CHARTGLUE_ROWS )
{ // meistens gleiche Cols
- if ( (pCol = (Table*) pCols->Get( nInsCol ))==NULL )
+ ColumnMap::const_iterator it = pCols->find( nInsCol );
+ if ( it == pCols->end() )
{
- pCols->Insert( nInsCol, pNewRowTable );
- pCol = pNewRowTable;
- pNewRowTable = new Table;
+ pCol = new RowMap;
+ pCols->insert(it, ColumnMap::value_type( nInsCol, pCol ) );
}
+ else
+ pCol = it->second;
}
else
{ // meistens neue Cols
- if ( pCols->Insert( nInsCol, pNewRowTable ) )
+ ColumnMap::const_iterator it = pCols->find( nInsCol );
+ if ( it == pCols->end() )
{
- pCol = pNewRowTable;
- pNewRowTable = new Table;
+ pCol = new RowMap;
+ pCols->insert(it, ColumnMap::value_type( nInsCol, pCol ) );
}
else
- pCol = (Table*) pCols->Get( nInsCol );
+ pCol = it->second;
}
// bei anderer Tabelle wurde bereits neuer ColKey erzeugt,
// die Zeilen muessen fuer's Dummy fuellen gleich sein!
sal_uLong nInsRow = (bNoGlue ? nNoGlueRow : nRow1);
for ( nRow = nRow1; nRow <= nRow2; nRow++, nInsRow++ )
{
- if ( pCol->Insert( nInsRow, pNewAddress ) )
+ RowMap::const_iterator it = pCol->find( nInsRow );
+ if ( it == pCol->end() )
{
- pNewAddress->Set( nCol, nRow, nTab );
- pNewAddress = new ScAddress;
+ pCol->insert(it, RowMap::value_type( nInsRow, new ScAddress( nCol, nRow, nTab ) ) );
}
}
}
@@ -435,16 +435,15 @@ void ScChartPositioner::CreatePositionMap()
// bei NoGlue werden zusammengehoerige Tabellen als ColGlue dargestellt
nNoGlueRow += nRow2 - nRow1 + 1;
}
- delete pNewAddress;
- delete pNewRowTable;
// Anzahl der Daten
- nColCount = static_cast< SCSIZE >( pCols->Count());
- if ( (pCol = (Table*) pCols->First())!=NULL )
+ nColCount = static_cast< SCSIZE >( pCols->size());
+ if ( !pCols->empty() )
{
+ RowMap* pCol = pCols->begin()->second;
if ( bDummyUpperLeft )
- pCol->Insert( 0, (void*)0 ); // Dummy fuer Beschriftung
- nRowCount = static_cast< SCSIZE >( pCol->Count());
+ (*pCol)[ 0 ] = NULL; // Dummy fuer Beschriftung
+ nRowCount = static_cast< SCSIZE >( pCol->size());
}
else
nRowCount = 0;
@@ -455,25 +454,27 @@ void ScChartPositioner::CreatePositionMap()
if ( nColCount==0 || nRowCount==0 )
{ // einen Eintrag ohne Daten erzeugen
- if ( pCols->Count() > 0 )
- pCol = (Table*) pCols->First();
+ RowMap* pCol;
+ if ( !pCols->empty() )
+ pCol = pCols->begin()->second;
else
{
- pCol = new Table;
- pCols->Insert( 0, pCol );
+ pCol = new RowMap;
+ (*pCols)[ 0 ] = pCol;
}
nColCount = 1;
- if ( pCol->Count() > 0 )
+ if ( !pCol->empty() )
{ // kann ja eigentlich nicht sein, wenn nColCount==0 || nRowCount==0
- pPos = (ScAddress*) pCol->First();
+ ScAddress* pPos = pCol->begin()->second;
if ( pPos )
{
+ sal_uLong nCurrentKey = pCol->begin()->first;
delete pPos;
- pCol->Replace( pCol->GetCurKey(), (void*)0 );
+ (*pCol)[ nCurrentKey ] = NULL;
}
}
else
- pCol->Insert( 0, (void*)0 );
+ (*pCol)[ 0 ] = NULL;
nRowCount = 1;
nColAdd = 0;
nRowAdd = 0;
@@ -482,15 +483,14 @@ void ScChartPositioner::CreatePositionMap()
{
if ( bNoGlue )
{ // Luecken mit Dummies fuellen, erste Spalte ist Master
- Table* pFirstCol = (Table*) pCols->First();
- sal_uLong nCount = pFirstCol->Count();
- pFirstCol->First();
- for ( sal_uLong n = 0; n < nCount; n++, pFirstCol->Next() )
+ RowMap* pFirstCol = pCols->begin()->second;
+ sal_uLong nCount = pFirstCol->size();
+ RowMap::const_iterator it1 = pFirstCol->begin();
+ for ( sal_uLong n = 0; n < nCount; n++, ++it1 )
{
- sal_uLong nKey = pFirstCol->GetCurKey();
- pCols->First();
- while ( (pCol = (Table*) pCols->Next())!=NULL )
- pCol->Insert( nKey, (void*)0 ); // keine Daten
+ sal_uLong nKey = it1->first;
+ for (ColumnMap::const_iterator it2 = pCols->begin(); it2 != pCols->end(); ++it2 )
+ (*it2->second)[ nKey ] = NULL; // keine Daten
}
}
}
@@ -499,16 +499,16 @@ void ScChartPositioner::CreatePositionMap()
static_cast<SCCOL>(nColAdd), static_cast<SCROW>(nRowAdd), *pCols );
// Aufraeumen
- for ( pCol = (Table*) pCols->First(); pCol; pCol = (Table*) pCols->Next() )
+ for (ColumnMap::const_iterator it = pCols->begin(); it != pCols->end(); ++it )
{ //! nur Tables loeschen, nicht die ScAddress*
- delete pCol;
+ delete it->second;
}
delete pCols;
}
ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
- SCCOL nColAdd, SCROW nRowAdd, Table& rCols ) :
+ SCCOL nColAdd, SCROW nRowAdd, ColumnMap& rCols ) :
ppData( new ScAddress* [ nChartCols * nChartRows ] ),
ppColHeader( new ScAddress* [ nChartCols ] ),
ppRowHeader( new ScAddress* [ nChartRows ] ),
@@ -518,64 +518,75 @@ ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
{
OSL_ENSURE( nColCount && nRowCount, "ScChartPositionMap without dimension" );
- ScAddress* pPos;
- SCCOL nCol;
- SCROW nRow;
-
- Table* pCol = (Table*) rCols.First();
+ ColumnMap::const_iterator pColIter = rCols.begin();
+ RowMap* pCol1 = pColIter->second;
+ RowMap::const_iterator pPos1Iter;
// Zeilen-Header
- pPos = (ScAddress*) pCol->First();
+ pPos1Iter = pCol1->begin();
if ( nRowAdd )
- pPos = (ScAddress*) pCol->Next();
+ ++pPos1Iter;
if ( nColAdd )
{ // eigenstaendig
- for ( nRow = 0; nRow < nRowCount; nRow++ )
+ for ( SCROW nRow = 0; nRow < nRowCount; nRow++ )
{
- ppRowHeader[ nRow ] = pPos;
- pPos = (ScAddress*) pCol->Next();
+ ppRowHeader[ nRow ] = pPos1Iter->second;
+ ++pPos1Iter;
}
}
else
{ // Kopie
- for ( nRow = 0; nRow < nRowCount; nRow++ )
+ SCROW nRow = 0;
+ for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
{
- ppRowHeader[ nRow ] = ( pPos ? new ScAddress( *pPos ) : NULL );
- pPos = (ScAddress*) pCol->Next();
+ ppRowHeader[ nRow ] = new ScAddress( *pPos1Iter->second );
+ ++pPos1Iter;
}
+ for ( ; nRow < nRowCount; nRow++ )
+ ppRowHeader[ nRow ] = NULL;
}
if ( nColAdd )
- pCol = (Table*) rCols.Next();
+ {
+ ++pColIter;
+ }
// Daten spaltenweise und Spalten-Header
sal_uLong nIndex = 0;
- for ( nCol = 0; nCol < nColCount; nCol++ )
+ for ( SCCOL nCol = 0; nCol < nColCount; nCol++ )
{
- if ( pCol )
+ if ( pColIter != rCols.end() )
{
- pPos = (ScAddress*) pCol->First();
+ RowMap* pCol2 = pColIter->second;
+ RowMap::const_iterator pPosIter = pCol2->begin();
if ( nRowAdd )
{
- ppColHeader[ nCol ] = pPos; // eigenstaendig
- pPos = (ScAddress*) pCol->Next();
+ ppColHeader[ nCol ] = pPosIter->second; // eigenstaendig
+ ++pPosIter;
}
+ else if ( pPosIter != pCol2->end() )
+ ppColHeader[ nCol ] = new ScAddress( *pPosIter->second );
else
- ppColHeader[ nCol ] = ( pPos ? new ScAddress( *pPos ) : NULL );
- for ( nRow = 0; nRow < nRowCount; nRow++, nIndex++ )
+ ppColHeader[ nCol ] = NULL;
+
+ SCROW nRow = 0;
+ for ( ; nRow < nRowCount && pPosIter != pCol2->end(); nRow++, nIndex++ )
{
- ppData[ nIndex ] = pPos;
- pPos = (ScAddress*) pCol->Next();
+ ppData[ nIndex ] = pPosIter->second;
+ ++pPosIter;
}
+ for ( ; nRow < nRowCount; nRow++, nIndex++ ) ;
+ ppData[ nIndex ] = NULL;
+
+ ++pColIter;
}
else
{
ppColHeader[ nCol ] = NULL;
- for ( nRow = 0; nRow < nRowCount; nRow++, nIndex++ )
+ for ( SCROW nRow = 0; nRow < nRowCount; nRow++, nIndex++ )
{
ppData[ nIndex ] = NULL;
}
}
- pCol = (Table*) rCols.Next();
}
}
More information about the Libreoffice-commits
mailing list