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

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Jun 7 14:10:04 PDT 2011


 sc/inc/stlalgorithm.hxx           |   42 ++++++++++++++++++++++++++++++++++++++
 sc/source/core/tool/rangelst.cxx  |   14 ++----------
 sc/source/ui/inc/viewdata.hxx     |    3 +-
 sc/source/ui/unoobj/chart2uno.cxx |   17 +--------------
 sc/source/ui/view/viewdata.cxx    |    3 ++
 5 files changed, 52 insertions(+), 27 deletions(-)

New commits:
commit 1fd8c2d3c6e1caaca4755a06e4f5d3b547c17089
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Jun 7 17:09:21 2011 -0400

    Shared commonly used STL function objects & remove memory leak.

diff --git a/sc/inc/stlalgorithm.hxx b/sc/inc/stlalgorithm.hxx
new file mode 100644
index 0000000..3a0bff2
--- /dev/null
+++ b/sc/inc/stlalgorithm.hxx
@@ -0,0 +1,42 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       Kohei Yoshida <kyoshida at novell.com> (Novell, Inc.)
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef __SC_STLALGORITHM_HXX__
+#define __SC_STLALGORITHM_HXX__
+
+#include <functional>
+
+template<typename T>
+struct ScDeleteObjectByPtr : public ::std::unary_function<T*, void>
+{
+    void operator() (T* p)
+    {
+        delete p;
+    }
+};
+
+#endif
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index f83b751..7ce506a 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -42,6 +42,7 @@
 #include "refupdat.hxx"
 #include "rechead.hxx"
 #include "compiler.hxx"
+#include "stlalgorithm.hxx"
 
 using ::std::vector;
 using ::std::advance;
@@ -92,15 +93,6 @@ private:
     vector<ScRange*>& mrRanges;
 };
 
-template<typename T>
-struct DeleteObject : public ::std::unary_function<void, T*>
-{
-    void operator() (T* p)
-    {
-        delete p;
-    }
-};
-
 class CountCells : public ::std::unary_function<void, const ScRange*>
 {
 public:
@@ -470,7 +462,7 @@ ScRange* ScRangeList::Remove(size_t nPos)
 
 void ScRangeList::RemoveAll()
 {
-    for_each(maRanges.begin(), maRanges.end(), DeleteObject<ScRange>());
+    for_each(maRanges.begin(), maRanges.end(), ScDeleteObjectByPtr<ScRange>());
     maRanges.clear();
 }
 
@@ -523,7 +515,7 @@ void ScRangeList::push_back(ScRange* p)
 
 ScRangePairList::~ScRangePairList()
 {
-    for_each( maPairs.begin(), maPairs.end(), DeleteObject<ScRangePair>() );
+    for_each( maPairs.begin(), maPairs.end(), ScDeleteObjectByPtr<ScRangePair>() );
     maPairs.clear();
 }
 
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 736191e..ad50098 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -151,7 +151,6 @@ private:
     bool            mbOldCursorValid;           // "virtuelle" Cursorpos. bei zusammengefassten
 
                     ScViewDataTable();
-                    ~ScViewDataTable();
 
     void            WriteUserDataSequence(
                         com::sun::star::uno::Sequence <com::sun::star::beans::PropertyValue>& rSettings,
@@ -160,6 +159,8 @@ private:
     void            ReadUserDataSequence(
                         const com::sun::star::uno::Sequence <com::sun::star::beans::PropertyValue>& rSettings,
                         ScViewData& rViewData, SCTAB nTab, bool& rHasZoom);
+public:
+    ~ScViewDataTable();
 };
 
 // ---------------------------------------------------------------------------
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 95241f3..609c920 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -43,6 +43,7 @@
 #include "compiler.hxx"
 #include "reftokenhelper.hxx"
 #include "chartlis.hxx"
+#include "stlalgorithm.hxx"
 
 #include <sfx2/objsh.hxx>
 #include <tools/table.hxx>
@@ -156,20 +157,6 @@ uno::Reference< sheet::XSpreadsheetDocument > lcl_GetSpreadSheetDocument( ScDocu
     return uno::Reference< sheet::XSpreadsheetDocument >( lcl_GetXModel( pDoc ), uno::UNO_QUERY );
 }
 
-// ============================================================================
-
-namespace {
-
-struct DeleteInstance : public unary_function<FormulaToken*, void>
-{
-    void operator() (FormulaToken* p) const
-    {
-        delete p;
-    }
-};
-
-}
-
 struct TokenTable
 {
     SCROW mnRowCount;
@@ -184,7 +171,7 @@ struct TokenTable
     }
     void clear()
     {
-        ::std::for_each(maTokens.begin(), maTokens.end(), DeleteInstance());
+        ::std::for_each(maTokens.begin(), maTokens.end(), ScDeleteObjectByPtr<FormulaToken>());
     }
     
     void push_back( FormulaToken* pToken )
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index fe60ab8..9b1a5be 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -64,6 +64,7 @@
 #include "unonames.hxx"
 #include "inputopt.hxx"
 #include "viewutil.hxx"
+#include "stlalgorithm.hxx"
 #include <xmloff/xmluconv.hxx>
 #include "ViewSettingsSequenceDefines.hxx"
 #include <rtl/ustrbuf.hxx>
@@ -435,6 +436,8 @@ ScViewData::~ScViewData()
 {
     KillEditView();
     delete pOptions;
+    ::std::for_each(
+        maTabData.begin(), maTabData.end(), ScDeleteObjectByPtr<ScViewDataTable>());
 }
 
 void ScViewData::UpdateCurrentTab()


More information about the Libreoffice-commits mailing list