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

Michael Stahl mstahl at redhat.com
Wed Aug 19 12:53:55 PDT 2015


 sc/inc/dbdata.hxx              |   12 ++++--
 sc/source/core/tool/dbdata.cxx |   81 ++++++++++++++++++++---------------------
 2 files changed, 50 insertions(+), 43 deletions(-)

New commits:
commit f15cbf2451d08ccddde9643c9f926a322f9f9917
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Aug 19 17:07:09 2015 +0200

    sc: replace boost::ptr_vector with std::vector<std::unique_ptr>
    
    Change-Id: I2a56ebf8edb30b5f16e09237f9480484a699170e
    Reviewed-on: https://gerrit.libreoffice.org/17861
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index 877a7fc..7508e0f 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -25,11 +25,11 @@
 #include "address.hxx"
 #include "global.hxx"
 
-#include <boost/ptr_container/ptr_vector.hpp>
 #include <boost/scoped_ptr.hpp>
 
 #include <memory>
 #include <set>
+#include <vector>
 
 class ScDocument;
 struct ScSortParam;
@@ -219,9 +219,15 @@ public:
      */
     class AnonDBs
     {
-        typedef ::boost::ptr_vector<ScDBData> DBsType;
-        DBsType maDBs;
+        typedef ::std::vector<std::unique_ptr<ScDBData>> DBsType;
+        DBsType m_DBs;
+
+        AnonDBs& operator=(AnonDBs const&) = delete;
+
     public:
+        AnonDBs();
+        AnonDBs(AnonDBs const&);
+
         typedef DBsType::iterator iterator;
         typedef DBsType::const_iterator const_iterator;
 
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 4857b18..2c1f207 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -19,7 +19,6 @@
 
 #include <sal/config.h>
 
-#include <o3tl/ptr_container.hxx>
 #include <unotools/transliterationwrapper.hxx>
 
 #include "dbdata.hxx"
@@ -656,16 +655,16 @@ sal_Int32 ScDBData::GetColumnNameOffset( const OUString& rName ) const
 
 namespace {
 
-class FindByTable : public unary_function<ScDBData, bool>
+class FindByTable : public unary_function<std::unique_ptr<ScDBData>, bool>
 {
     SCTAB mnTab;
 public:
     FindByTable(SCTAB nTab) : mnTab(nTab) {}
 
-    bool operator() (const ScDBData& r) const
+    bool operator() (std::unique_ptr<ScDBData> const& p) const
     {
         ScRange aRange;
-        r.GetArea(aRange);
+        p->GetArea(aRange);
         return aRange.aStart.Tab() == mnTab;
     }
 };
@@ -694,10 +693,6 @@ public:
         mnCol2(nCol2), mnRow2(nRow2), mnTab2(nTab2),
         mnDx(nDx), mnDy(nDy), mnDz(nDz) {}
 
-    void operator() (ScDBData& r)
-    {
-        r.UpdateReference(mpDoc, meMode, mnCol1, mnRow1, mnTab1, mnCol2, mnRow2, mnTab2, mnDx, mnDy, mnDz);
-    }
     void operator() (std::unique_ptr<ScDBData> const& p)
     {
         p->UpdateReference(mpDoc, meMode, mnCol1, mnRow1, mnTab1, mnCol2, mnRow2, mnTab2, mnDx, mnDy, mnDz);
@@ -710,10 +705,6 @@ class UpdateMoveTabFunc : public unary_function<std::unique_ptr<ScDBData>, void>
     SCTAB mnNewTab;
 public:
     UpdateMoveTabFunc(SCTAB nOld, SCTAB nNew) : mnOldTab(nOld), mnNewTab(nNew) {}
-    void operator() (ScDBData& r)
-    {
-        r.UpdateMoveTab(mnOldTab, mnNewTab);
-    }
     void operator() (std::unique_ptr<ScDBData> const& p)
     {
         p->UpdateMoveTab(mnOldTab, mnNewTab);
@@ -730,10 +721,6 @@ public:
     FindByCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bStartOnly) :
         mnCol(nCol), mnRow(nRow), mnTab(nTab), mbStartOnly(bStartOnly) {}
 
-    bool operator() (const ScDBData& r)
-    {
-        return r.IsDBAtCursor(mnCol, mnRow, mnTab, mbStartOnly);
-    }
     bool operator() (std::unique_ptr<ScDBData> const& p)
     {
         return p->IsDBAtCursor(mnCol, mnRow, mnTab, mbStartOnly);
@@ -746,11 +733,6 @@ class FindByRange : public unary_function<std::unique_ptr<ScDBData>, bool>
 public:
     FindByRange(const ScRange& rRange) : mrRange(rRange) {}
 
-    bool operator() (const ScDBData& r)
-    {
-        return r.IsDBAtArea(
-            mrRange.aStart.Tab(), mrRange.aStart.Col(), mrRange.aStart.Row(), mrRange.aEnd.Col(), mrRange.aEnd.Row());
-    }
     bool operator() (std::unique_ptr<ScDBData> const& p)
     {
         return p->IsDBAtArea(
@@ -780,14 +762,14 @@ public:
     }
 };
 
-class FindByPointer : public unary_function<ScDBData, bool>
+class FindByPointer : public unary_function<std::unique_ptr<ScDBData>, bool>
 {
     const ScDBData* mpDBData;
 public:
     FindByPointer(const ScDBData* pDBData) : mpDBData(pDBData) {}
-    bool operator() (const ScDBData& r) const
+    bool operator() (std::unique_ptr<ScDBData> const& p) const
     {
-        return &r == mpDBData;
+        return p.get() == mpDBData;
     }
 };
 
@@ -884,42 +866,42 @@ bool ScDBCollection::NamedDBs::operator== (const NamedDBs& r) const
 
 ScDBCollection::AnonDBs::iterator ScDBCollection::AnonDBs::begin()
 {
-    return maDBs.begin();
+    return m_DBs.begin();
 }
 
 ScDBCollection::AnonDBs::iterator ScDBCollection::AnonDBs::end()
 {
-    return maDBs.end();
+    return m_DBs.end();
 }
 
 ScDBCollection::AnonDBs::const_iterator ScDBCollection::AnonDBs::begin() const
 {
-    return maDBs.begin();
+    return m_DBs.begin();
 }
 
 ScDBCollection::AnonDBs::const_iterator ScDBCollection::AnonDBs::end() const
 {
-    return maDBs.end();
+    return m_DBs.end();
 }
 
 const ScDBData* ScDBCollection::AnonDBs::findAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bStartOnly) const
 {
     DBsType::const_iterator itr = find_if(
-        maDBs.begin(), maDBs.end(), FindByCursor(nCol, nRow, nTab, bStartOnly));
-    return itr == maDBs.end() ? NULL : &(*itr);
+        m_DBs.begin(), m_DBs.end(), FindByCursor(nCol, nRow, nTab, bStartOnly));
+    return itr == m_DBs.end() ? nullptr : itr->get();
 }
 
 const ScDBData* ScDBCollection::AnonDBs::findByRange(const ScRange& rRange) const
 {
     DBsType::const_iterator itr = find_if(
-        maDBs.begin(), maDBs.end(), FindByRange(rRange));
-    return itr == maDBs.end() ? NULL : &(*itr);
+        m_DBs.begin(), m_DBs.end(), FindByRange(rRange));
+    return itr == m_DBs.end() ? nullptr : itr->get();
 }
 
 void ScDBCollection::AnonDBs::deleteOnTab(SCTAB nTab)
 {
     FindByTable func(nTab);
-    maDBs.erase_if(func);
+    m_DBs.erase(std::remove_if(m_DBs.begin(), m_DBs.end(), func), m_DBs.end());
 }
 
 ScDBData* ScDBCollection::AnonDBs::getByRange(const ScRange& rRange)
@@ -933,30 +915,49 @@ ScDBData* ScDBCollection::AnonDBs::getByRange(const ScRange& rRange)
             aName, rRange.aStart.Tab(), rRange.aStart.Col(), rRange.aStart.Row(),
             rRange.aEnd.Col(), rRange.aEnd.Row(), true, false, false));
         pData = pNew.get();
-        o3tl::ptr_container::push_back(maDBs, std::move(pNew));
+        m_DBs.push_back(std::move(pNew));
     }
     return const_cast<ScDBData*>(pData);
 }
 
 void ScDBCollection::AnonDBs::insert(ScDBData* p)
 {
-    ::std::unique_ptr<ScDBData> pNew(p);
-    o3tl::ptr_container::push_back(maDBs, std::move(pNew));
+    m_DBs.push_back(std::unique_ptr<ScDBData>(p));
 }
 
 bool ScDBCollection::AnonDBs::empty() const
 {
-    return maDBs.empty();
+    return m_DBs.empty();
 }
 
 bool ScDBCollection::AnonDBs::has( const ScDBData* p ) const
 {
-    return find_if( maDBs.begin(), maDBs.end(), FindByPointer(p)) != maDBs.end();
+    return find_if(m_DBs.begin(), m_DBs.end(), FindByPointer(p)) != m_DBs.end();
 }
 
 bool ScDBCollection::AnonDBs::operator== (const AnonDBs& r) const
 {
-    return maDBs == r.maDBs;
+    if (m_DBs.size() != r.m_DBs.size())
+        return false;
+    for (auto iter1 = begin(), iter2 = r.begin(); iter1 != end(); ++iter1, ++iter2)
+    {
+        if (**iter1 != **iter2)
+            return false;
+    }
+    return true;
+}
+
+ScDBCollection::AnonDBs::AnonDBs()
+{
+}
+
+ScDBCollection::AnonDBs::AnonDBs(AnonDBs const& r)
+{
+    m_DBs.reserve(r.m_DBs.size());
+    for (auto const& it : r.m_DBs)
+    {
+        m_DBs.push_back(std::unique_ptr<ScDBData>(new ScDBData(*it)));
+    }
 }
 
 ScDBCollection::ScDBCollection(ScDocument* pDocument) :
@@ -1080,7 +1081,7 @@ void ScDBCollection::DeleteOnTab( SCTAB nTab )
         NamedDBs::DBsType::iterator itr = maNamedDBs.begin(), itrEnd = maNamedDBs.end();
         for (; itr != itrEnd; ++itr)
         {
-            if (func(**itr))
+            if (func(*itr))
                 v.push_back(itr);
         }
     }


More information about the Libreoffice-commits mailing list