[Libreoffice-commits] .: 5 commits - sc/source

Fridrich Strba fridrich at kemper.freedesktop.org
Wed Mar 21 22:56:45 PDT 2012


 sc/source/ui/unoobj/chart2uno.cxx |  112 ++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 63 deletions(-)

New commits:
commit db3786ee3aa0d8911042c9bbcea02cf36d96dfa1
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Mar 16 14:56:53 2012 +0200

    Convert tools/table.hxx to std::map in Chart2PositionMap class

diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 0c86655..469eb1d 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -47,7 +47,6 @@
 #include "formula/opcode.hxx"
 
 #include <sfx2/objsh.hxx>
-#include <tools/table.hxx>
 #include <vcl/svapp.hxx>
 
 #include <com/sun/star/beans/UnknownPropertyException.hpp>
@@ -249,12 +248,14 @@ vector<ScTokenRef>* TokenTable::getAllRanges() const
 }
 
 // ============================================================================
+typedef std::map<int, ScToken*> ScTokenPtrMap;
+typedef std::map<int, ScTokenPtrMap*> ChartTokenMap;
 
 class Chart2PositionMap
 {
 public:
     Chart2PositionMap(SCCOL nColCount, SCROW nRowCount,
-                      bool bFillRowHeader, bool bFillColumnHeader, Table& rCols,
+                      bool bFillRowHeader, bool bFillColumnHeader, ChartTokenMap& rCols,
                       ScDocument* pDoc );
     ~Chart2PositionMap();
 
@@ -282,7 +283,7 @@ private:
 };
 
 Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
-                                     bool bFillRowHeader, bool bFillColumnHeader, Table& rCols, ScDocument* pDoc)
+                                     bool bFillRowHeader, bool bFillColumnHeader, ChartTokenMap& rCols, ScDocument* pDoc)
 {
     // if bFillRowHeader is true, at least the first column serves as a row header.
     //  If more than one column is pure text all the first pure text columns are used as header.
@@ -299,16 +300,18 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
         SCROW nSmallestValueRowIndex = nAllRowCount;
         bool bFoundValues = false;
         bool bFoundAnything = false;
-        Table* pCol = static_cast<Table*>(rCols.First());
+        ChartTokenMap::iterator aColIter = rCols.begin();
         for (SCCOL nCol = 0; !bFoundValues && nCol < nAllColCount; ++nCol)
         {
-            if (pCol && nCol>=nHeaderColCount)
+            if (aColIter != rCols.end() && nCol>=nHeaderColCount)
             {
-                ScToken* pToken = static_cast<ScToken*>(pCol->First());
+                ScTokenPtrMap* pCol = aColIter->second;
+                ScTokenPtrMap::iterator tokenIter = pCol->begin();
                 for (SCROW nRow = 0; !bFoundValues && nRow < nSmallestValueRowIndex; ++nRow)
                 {
-                    if (pToken && nRow>=nHeaderRowCount)
+                    if (tokenIter != pCol->end() && nRow>=nHeaderRowCount)
                     {
+                        ScToken* pToken = tokenIter->second;
                         ScRange aRange;
                         bool bExternal = false;
                         StackVar eType = pToken->GetType();
@@ -331,12 +334,14 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
                                 bFoundAnything = true;
                         }
                     }
-                    pToken = static_cast<ScToken*>(pCol->Next());
+                    if (tokenIter != pCol->end() )
+                        ++tokenIter;
                 }
                 if(!bFoundValues && nHeaderColCount>0)
                     nHeaderColCount++;
             }
-            pCol = static_cast<Table*>(rCols.Next());
+            if (aColIter != rCols.end())
+                ++aColIter;
         }
         if( bFoundAnything )
         {
@@ -360,15 +365,16 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
     maRowHeaders.init(nHeaderColCount,mnDataRowCount);
     maData.init(mnDataColCount,mnDataRowCount);
 
-    Table* pCol = static_cast<Table*>(rCols.First());
-    FormulaToken* pToken = NULL;
+    ChartTokenMap::iterator aColIter = rCols.begin();
     for (SCCOL nCol = 0; nCol < nAllColCount; ++nCol)
     {
-        if (pCol)
+        if (aColIter != rCols.end())
         {
-            pToken = static_cast<FormulaToken*>(pCol->First());
+            ScTokenPtrMap* pCol = aColIter->second;
+            ScTokenPtrMap::iterator tokenIter = pCol->begin();
             for (SCROW nRow = 0; nRow < nAllRowCount; ++nRow)
             {
+                FormulaToken* pToken = static_cast<FormulaToken*>(tokenIter->second);
                 if( nCol < nHeaderColCount )
                 {
                     if( nRow < nHeaderRowCount )
@@ -380,11 +386,10 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
                     maColHeaders.push_back(pToken);
                 else
                     maData.push_back(pToken);
-
-                pToken = static_cast<FormulaToken*>(pCol->Next());
+                ++tokenIter;
             }
+            ++aColIter;
         }
-        pCol = static_cast<Table*>(rCols.Next());
     }
 }
 
@@ -715,10 +720,7 @@ void Chart2Positioner::createPositionMap()
     glueState();
 
     bool bNoGlue = (meGlue == GLUETYPE_NONE);
-    SAL_WNODEPRECATED_DECLARATIONS_PUSH
-    auto_ptr<Table> pCols(new Table);
-    SAL_WNODEPRECATED_DECLARATIONS_POP
-    Table* pCol = NULL;
+    auto_ptr<ChartTokenMap> pCols(new ChartTokenMap);
     SCROW nNoGlueRow = 0;
     for (vector<ScTokenRef>::const_iterator itr = mrRefTokens.begin(), itrEnd = mrRefTokens.end();
           itr != itrEnd; ++itr)
@@ -748,12 +750,15 @@ void Chart2Positioner::createPositionMap()
 
             for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol)
             {
-                pCol = static_cast<Table*>(pCols->Get(nInsCol));
-                if (!pCol)
+                ScTokenPtrMap* pCol = NULL;
+                ChartTokenMap::iterator it = pCols->find( nInsCol );
+                if ( it == pCols->end() )
                 {
-                    pCol = new Table;
-                    pCols->Insert(nInsCol, pCol);
+                    pCol = new ScTokenPtrMap;
+                    (*pCols)[nInsCol] = pCol;
                 }
+                else
+                    pCol = it->second;
 
                 sal_uInt32 nInsRow = static_cast<sal_uInt32>(bNoGlue ? nNoGlueRow : nRow1);
                 for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow, ++nInsRow)
@@ -768,12 +773,12 @@ void Chart2Positioner::createPositionMap()
                     aCellData.nRow = nRow;
                     aCellData.nTab = nTab;
 
-                    if (pCol->Get(nInsRow) == NULL)
+                    if ( pCol->find(nInsRow) == pCol->end() )
                     {
                         if (bExternal)
-                            pCol->Insert(nInsRow, new ScExternalSingleRefToken(nFileId, aTabName, aCellData));
+                            (*pCol)[nInsRow] = new ScExternalSingleRefToken(nFileId, aTabName, aCellData);
                         else
-                            pCol->Insert(nInsRow, new ScSingleRefToken(aCellData));
+                            (*pCol)[nInsRow] = new ScSingleRefToken(aCellData);
                     }
                 }
             }
@@ -784,29 +789,28 @@ void Chart2Positioner::createPositionMap()
     bool bFillRowHeader = mbRowHeaders;
     bool bFillColumnHeader = mbColHeaders;
 
-    SCSIZE nAllColCount = static_cast<SCSIZE>(pCols->Count());
+    SCSIZE nAllColCount = static_cast<SCSIZE>(pCols->size());
     SCSIZE nAllRowCount = 0;
-    pCol = static_cast<Table*>(pCols->First());
-    if (pCol)
+    if ( !pCols->empty() )
     {
+        nAllRowCount = static_cast<SCSIZE>(pCols->begin()->second->size());
         if (mbDummyUpperLeft)
-            pCol->Insert(0, NULL);        // Dummy fuer Beschriftung
-        nAllRowCount = static_cast<SCSIZE>(pCol->Count());
+            (*pCols)[ 0 ] = NULL;    // Dummy fuer Beschriftung
     }
 
     if( nAllColCount!=0 && nAllRowCount!=0 )
     {
         if (bNoGlue)
         {
-            Table* pFirstCol = static_cast<Table*>(pCols->First());
-            sal_uInt32 nCount = pFirstCol->Count();
-            pFirstCol->First();
-            for (sal_uInt32 n = 0; n < nCount; ++n, pFirstCol->Next())
+            ScTokenPtrMap* pFirstCol = pCols->begin()->second;
+            for ( ScTokenPtrMap::const_iterator it1 = pFirstCol->begin(); it1 != pFirstCol->end(); ++it1 )
             {
-                sal_uInt32 nKey = pFirstCol->GetCurKey();
-                pCols->First();
-                for (pCol = static_cast<Table*>(pCols->Next()); pCol; pCol = static_cast<Table*>(pCols->Next()))
-                    pCol->Insert(nKey, NULL);
+                sal_uInt32 nKey = it1->first;
+                for ( ChartTokenMap::const_iterator it2 = pCols->begin(); it2 != pCols->end(); ++it2 )
+                {
+                    ScTokenPtrMap* pCol = it2->second;
+                    (*pCol)[nKey] = NULL;
+                }
             }
         }
     }
@@ -816,8 +820,8 @@ void Chart2Positioner::createPositionMap()
             bFillRowHeader, bFillColumnHeader, *pCols, mpDoc));
 
     // Destroy all column instances.
-    for (pCol = static_cast<Table*>(pCols->First()); pCol; pCol = static_cast<Table*>(pCols->Next()))
-        delete pCol;
+    for (ChartTokenMap::const_iterator it = pCols->begin(); it != pCols->end(); ++it)
+        delete it->second;
 }
 
 // ============================================================================
commit 6af00cf90f4314be11ac7d8f186bb9da4f228cf1
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Mar 16 09:47:04 2012 +0200

    remove unnecessary use of local variable and auto_ptr

diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 1a04ce4..0c86655 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -717,7 +717,6 @@ void Chart2Positioner::createPositionMap()
     bool bNoGlue = (meGlue == GLUETYPE_NONE);
     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     auto_ptr<Table> pCols(new Table);
-    auto_ptr<Table> pNewRowTable(new Table);
     SAL_WNODEPRECATED_DECLARATIONS_POP
     Table* pCol = NULL;
     SCROW nNoGlueRow = 0;
@@ -752,9 +751,8 @@ void Chart2Positioner::createPositionMap()
                 pCol = static_cast<Table*>(pCols->Get(nInsCol));
                 if (!pCol)
                 {
-                    pCol = pNewRowTable.get();
-                    pCols->Insert(nInsCol, pNewRowTable.release());
-                    pNewRowTable.reset(new Table);
+                    pCol = new Table;
+                    pCols->Insert(nInsCol, pCol);
                 }
 
                 sal_uInt32 nInsRow = static_cast<sal_uInt32>(bNoGlue ? nNoGlueRow : nRow1);
@@ -773,7 +771,7 @@ void Chart2Positioner::createPositionMap()
                     if (pCol->Get(nInsRow) == NULL)
                     {
                         if (bExternal)
-                            pCol->Insert(nInsRow, new ScExternalSingleRefToken(nFileId, aTabName, aCellData))
+                            pCol->Insert(nInsRow, new ScExternalSingleRefToken(nFileId, aTabName, aCellData));
                         else
                             pCol->Insert(nInsRow, new ScSingleRefToken(aCellData));
                     }
@@ -782,7 +780,6 @@ void Chart2Positioner::createPositionMap()
         }
         nNoGlueRow += nRow2 - nRow1 + 1;
     }
-    pNewRowTable.reset(NULL);
 
     bool bFillRowHeader = mbRowHeaders;
     bool bFillColumnHeader = mbColHeaders;
commit 13bf19769e6e0522d920594225b9baa2c1b7dd63
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Mar 16 09:44:48 2012 +0200

    if/else branches contain same code

diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index e2f7059..1a04ce4 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -749,25 +749,12 @@ void Chart2Positioner::createPositionMap()
 
             for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol)
             {
-                if (bNoGlue || meGlue == GLUETYPE_ROWS)
+                pCol = static_cast<Table*>(pCols->Get(nInsCol));
+                if (!pCol)
                 {
-                    pCol = static_cast<Table*>(pCols->Get(nInsCol));
-                    if (!pCol)
-                    {
-                        pCol = pNewRowTable.get();
-                        pCols->Insert(nInsCol, pNewRowTable.release());
-                        pNewRowTable.reset(new Table);
-                    }
-                }
-                else
-                {
-                    pCol = static_cast<Table*>(pCols->Get(nInsCol));
-                    if (!pCol)
-                    {
-                        pCol = pNewRowTable.get();
-                        pCols->Insert(nInsCol, pNewRowTable.release());
-                        pNewRowTable.reset(new Table);
-                    }
+                    pCol = pNewRowTable.get();
+                    pCols->Insert(nInsCol, pNewRowTable.release());
+                    pNewRowTable.reset(new Table);
                 }
 
                 sal_uInt32 nInsRow = static_cast<sal_uInt32>(bNoGlue ? nNoGlueRow : nRow1);
commit 4aa72e0dee42c80667083c0b86a3d0ec5381c1ae
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Mar 16 09:41:43 2012 +0200

    restructure insert code as a precursor to further simplification

diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 1c637fb..e2f7059 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -761,13 +761,13 @@ void Chart2Positioner::createPositionMap()
                 }
                 else
                 {
-                    if (pCols->Insert(nInsCol, pNewRowTable.get()))
+                    pCol = static_cast<Table*>(pCols->Get(nInsCol));
+                    if (!pCol)
                     {
-                        pCol = pNewRowTable.release();
+                        pCol = pNewRowTable.get();
+                        pCols->Insert(nInsCol, pNewRowTable.release());
                         pNewRowTable.reset(new Table);
                     }
-                    else
-                        pCol = static_cast<Table*>(pCols->Get(nInsCol));
                 }
 
                 sal_uInt32 nInsRow = static_cast<sal_uInt32>(bNoGlue ? nNoGlueRow : nRow1);
@@ -786,7 +786,7 @@ void Chart2Positioner::createPositionMap()
                     if (pCol->Get(nInsRow) == NULL)
                     {
                         if (bExternal)
-                            pCol->Insert(nInsRow, new ScExternalSingleRefToken(nFileId, aTabName, aCellData));
+                            pCol->Insert(nInsRow, new ScExternalSingleRefToken(nFileId, aTabName, aCellData))
                         else
                             pCol->Insert(nInsRow, new ScSingleRefToken(aCellData));
                     }
commit 3ffdb45ae047f12480e73fdd4b28fe35f1e8d48c
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Mar 16 09:38:49 2012 +0200

    simplify code - remove unnecessary and complicated allocation

diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 5ff808b..1c637fb 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -717,7 +717,6 @@ void Chart2Positioner::createPositionMap()
     bool bNoGlue = (meGlue == GLUETYPE_NONE);
     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     auto_ptr<Table> pCols(new Table);
-    auto_ptr<FormulaToken> pNewAddress;
     auto_ptr<Table> pNewRowTable(new Table);
     SAL_WNODEPRECATED_DECLARATIONS_POP
     Table* pCol = NULL;
@@ -784,19 +783,18 @@ void Chart2Positioner::createPositionMap()
                     aCellData.nRow = nRow;
                     aCellData.nTab = nTab;
 
-                    if (bExternal)
-                        pNewAddress.reset(new ScExternalSingleRefToken(nFileId, aTabName, aCellData));
-                    else
-                        pNewAddress.reset(new ScSingleRefToken(aCellData));
-
-                    if (pCol->Insert(nInsRow, pNewAddress.get()))
-                        pNewAddress.release(); // To prevent the instance from being destroyed.
+                    if (pCol->Get(nInsRow) == NULL)
+                    {
+                        if (bExternal)
+                            pCol->Insert(nInsRow, new ScExternalSingleRefToken(nFileId, aTabName, aCellData));
+                        else
+                            pCol->Insert(nInsRow, new ScSingleRefToken(aCellData));
+                    }
                 }
             }
         }
         nNoGlueRow += nRow2 - nRow1 + 1;
     }
-    pNewAddress.reset(NULL);
     pNewRowTable.reset(NULL);
 
     bool bFillRowHeader = mbRowHeaders;


More information about the Libreoffice-commits mailing list