[Libreoffice-commits] core.git: 3 commits - sw/inc sw/qa sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Wed Dec 3 00:24:44 PST 2014


 sw/inc/edimp.hxx                 |    2 
 sw/inc/ring.hxx                  |   98 +++++++++++++++++++++------------------
 sw/qa/core/uwriter.cxx           |   16 +++---
 sw/source/core/doc/doccorr.cxx   |    6 +-
 sw/source/core/edit/autofmt.cxx  |    2 
 sw/source/core/frmedt/fecopy.cxx |    2 
 sw/source/core/frmedt/fews.cxx   |    9 +--
 7 files changed, 72 insertions(+), 63 deletions(-)

New commits:
commit 02ef3abd83f2d5f702349a8cd47928621ee5c620
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Dec 3 09:22:54 2014 +0100

    fdo#86929: Kill FOREACHPAM_START for good
    
    Change-Id: Ibaff13e84f186616259ba9bbf9224bbe2d30c5d6

diff --git a/sw/source/core/frmedt/fews.cxx b/sw/source/core/frmedt/fews.cxx
index 16aa9bd..8b0aa53 100644
--- a/sw/source/core/frmedt/fews.cxx
+++ b/sw/source/core/frmedt/fews.cxx
@@ -507,9 +507,9 @@ bool SwFEShell::Sort(const SwSortOptions& rOpt)
     else
     {
         // Sort text nothing else
-        FOREACHPAM_START(GetCrsr())
-
-            SwPaM* pPam = PCURCRSR;
+        for(SwPaM& rPaM : GetCrsr()->GetRingContainer())
+        {
+            SwPaM* pPam = &rPaM;
 
             SwPosition* pStart = pPam->Start();
             SwPosition* pEnd   = pPam->End();
@@ -534,8 +534,7 @@ bool SwFEShell::Sort(const SwSortOptions& rOpt)
             pPam->GetPoint()->nNode += nOffset;
             pCNd = pPam->GetCntntNode();
             pPam->GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
-
-        FOREACHPAM_END()
+        }
     }
 
     EndAllAction();
commit 881458eb2970d6be0ac0648159efcd37fa1623e2
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Dec 3 09:09:58 2014 +0100

    move size() into the container too
    
    Change-Id: I22ee641e7d07fa7c0cae7a4b36ce61dbed62b31f

diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index 61181eb..174a5bb 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -22,6 +22,7 @@
 #include <swdllapi.h>
 #include <swtypes.hxx>
 #include <utility>
+#include <iterator>
 #include <boost/iterator/iterator_facade.hpp>
 #include <boost/intrusive/circular_list_algorithms.hpp>
 
@@ -94,9 +95,6 @@ namespace sw
         /** @return the previous item in the ring container */
         T* GetPrev() const
             { return pPrev; }
-        /** @return the number of elements in the container */
-        size_t size() const
-            { return algo::count(static_cast< const T* >(this)); }
         /** @return a stl-like container with begin()/end() for iteration */
         ring_container GetRingContainer();
         /** @return a stl-like container with begin()/end() for const iteration */
@@ -161,9 +159,9 @@ namespace sw
         iterator end();
         const_iterator begin() const;
         const_iterator end() const;
-        ///** @return the number of elements in the container */
-        //size_t size() const
-        //    { return algo::count(static_cast< const T* >(this)); }
+        /** @return the number of elements in the container */
+        size_t size() const
+            { return std::distance(begin(), end()); }
     };
     template <class T>
     class RingIterator SAL_FINAL : public boost::iterator_facade<
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index 584f398..bad84c9 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -1296,18 +1296,18 @@ void SwDocTest::testIntrusiveRing()
     vRings.push_back(&aRing3);
     vRings.push_back(&aRing4);
     vRings.push_back(&aRing5);
-    CPPUNIT_ASSERT_EQUAL(aRing1.size(), static_cast<size_t>(1));
+    CPPUNIT_ASSERT_EQUAL(aRing1.GetRingContainer().size(), static_cast<size_t>(1));
     aRing2.MoveTo(&aRing1);
     aRing3.MoveTo(&aRing1);
-    CPPUNIT_ASSERT_EQUAL(aRing1.size(), static_cast<size_t>(3));
-    CPPUNIT_ASSERT_EQUAL(aRing2.size(), static_cast<size_t>(3));
-    CPPUNIT_ASSERT_EQUAL(aRing3.size(), static_cast<size_t>(3));
+    CPPUNIT_ASSERT_EQUAL(aRing1.GetRingContainer().size(), static_cast<size_t>(3));
+    CPPUNIT_ASSERT_EQUAL(aRing2.GetRingContainer().size(), static_cast<size_t>(3));
+    CPPUNIT_ASSERT_EQUAL(aRing3.GetRingContainer().size(), static_cast<size_t>(3));
     aRing5.MoveTo(&aRing4);
-    CPPUNIT_ASSERT_EQUAL(aRing4.size(), static_cast<size_t>(2));
+    CPPUNIT_ASSERT_EQUAL(aRing4.GetRingContainer().size(), static_cast<size_t>(2));
     aRing4.MoveRingTo(&aRing1);
     BOOST_FOREACH(TestRing* pRing, vRings)
     {
-        CPPUNIT_ASSERT_EQUAL(pRing->size(), static_cast<size_t>(5));
+        CPPUNIT_ASSERT_EQUAL(pRing->GetRingContainer().size(), static_cast<size_t>(5));
     }
     for(std::vector<TestRing*>::iterator ppRing = vRings.begin(); ppRing != vRings.end(); ++ppRing)
     {
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 95a5033..c10c8d9 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -719,7 +719,7 @@ bool SwFEShell::Paste( SwDoc* pClpDoc, bool bIncludingPageFrames )
         SwNodeIndex aClpIdx( aIdx );
         SwPaM* pStartCursor = GetCrsr();
         SwPaM* pCurrCrsr = pStartCursor;
-        sal_uInt32 nCursorCount = pStartCursor->size();
+        sal_uInt32 nCursorCount = pStartCursor->GetRingContainer().size();
         // If the target selection is a multi-selection, often the last and first
         // cursor of the ring points to identical document positions. Then
         // we should avoid double insertion of text portions...
commit acf5b740e3dc763eb53c3fdf507a27479386728e
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Wed Dec 3 08:59:10 2014 +0100

    move container stuff out of sw::Ring<>
    
    Change-Id: Idf72c16318735d6b3ef7f421aceacc225a7697bf

diff --git a/sw/inc/edimp.hxx b/sw/inc/edimp.hxx
index f3f985a..a62f0d2 100644
--- a/sw/inc/edimp.hxx
+++ b/sw/inc/edimp.hxx
@@ -31,7 +31,7 @@ class SwNodeIndex;
 #define PCURCRSR (static_cast<SwPaM *>(&__r))
 
 #define FOREACHPAM_START(pCURSH) \
-    BOOST_FOREACH(SwPaM& __r, (pCURSH)->rangeRing()) \
+    for(SwPaM& __r : (pCURSH)->GetRingContainer()) \
     {
 
 #define FOREACHPAM_END() }
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index d58733f..61181eb 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -27,9 +27,7 @@
 
 namespace sw
 {
-    class Ring_node_traits;
-    template <class T> class RingIterator;
-
+    template <class T> class RingContainer;
     /**
      * An intrusive container class double linking the contained nodes
      * @example sw/qa/core/uwriter.cxx
@@ -68,8 +66,8 @@ namespace sw
          */
         Ring( T* pRing );
     public:
-        typedef RingIterator<T> iterator;
-        typedef RingIterator<const T> const_iterator;
+        typedef RingContainer<T> ring_container;
+        typedef RingContainer<const T> const_ring_container;
         virtual ~Ring()
             { algo::unlink(static_cast< T* >(this)); };
         /**
@@ -96,36 +94,13 @@ namespace sw
         /** @return the previous item in the ring container */
         T* GetPrev() const
             { return pPrev; }
-        /**
-         * iterator access
-         * @code
-         * for(Ring<SwPaM>::iterator ppRing = pPaM->beginRing(); ppRing != pPaM->endRing(); ++ppRing)
-         *     do_stuff(*ppRing);
-         * @endcode
-         * @TODO: unfortunately we cant name these STL-conforming, as some derived classes
-         * also derive from other STL containers. This should be fixed though.
-         * That should allow this to be used directly with C++11s for( : )
-         * iteration statement.
-         */
-        iterator beginRing();
-        iterator endRing();
-        const_iterator beginRing() const;
-        const_iterator endRing() const;
-        /**
-         * simplified iteration with BOOST_FOREACH (example for Ring<SwPaM>):
-         * @code
-         * BOOST_FOREACH(SwPaM& rPaM, pPaM->rangeRing())
-         *     do_stuff(rPaM);
-         * @endcode
-         */
-        std::pair<iterator, iterator> rangeRing()
-            { return std::make_pair(beginRing(), endRing()); }
-        std::pair<const_iterator, const_iterator> rangeRing() const
-            { return std::make_pair(beginRing(), endRing()); }
-
         /** @return the number of elements in the container */
         size_t size() const
             { return algo::count(static_cast< const T* >(this)); }
+        /** @return a stl-like container with begin()/end() for iteration */
+        ring_container GetRingContainer();
+        /** @return a stl-like container with begin()/end() for const iteration */
+        const_ring_container GetRingContainer() const;
     };
 
     template <class T>
@@ -161,8 +136,37 @@ namespace sw
         std::swap(*(&pPrev), *(&pDestRing->pPrev));
     }
 
+    template <class T> class RingIterator;
     template <class T>
-    class RingIterator : public boost::iterator_facade<
+    class RingContainer SAL_FINAL
+    {
+        T* m_pStart;
+
+    public:
+        RingContainer( T* pRing ) : m_pStart(pRing) {};
+        typedef RingIterator<T> iterator;
+        typedef RingIterator<const T> const_iterator;
+        /**
+         * iterator access
+         * @code
+         * for(Ring<SwPaM>::iterator ppRing = pPaM->beginRing(); ppRing != pPaM->endRing(); ++ppRing)
+         *     do_stuff(*ppRing);
+         * @endcode
+         * @TODO: unfortunately we cant name these STL-conforming, as some derived classes
+         * also derive from other STL containers. This should be fixed though.
+         * That should allow this to be used directly with C++11s for( : )
+         * iteration statement.
+         */
+        iterator begin();
+        iterator end();
+        const_iterator begin() const;
+        const_iterator end() const;
+        ///** @return the number of elements in the container */
+        //size_t size() const
+        //    { return algo::count(static_cast< const T* >(this)); }
+    };
+    template <class T>
+    class RingIterator SAL_FINAL : public boost::iterator_facade<
           RingIterator<T>
         , T
         , boost::forward_traversal_tag
@@ -193,20 +197,28 @@ namespace sw
     };
 
     template <class T>
-    inline typename Ring<T>::iterator Ring<T>::beginRing()
-        { return Ring<T>::iterator(static_cast< T* >(this)); };
+    inline typename Ring<T>::ring_container Ring<T>::GetRingContainer()
+        { return Ring<T>::ring_container(static_cast< T* >(this)); };
+
+    template <class T>
+    inline typename Ring<T>::const_ring_container Ring<T>::GetRingContainer() const
+        { return Ring<T>::const_ring_container(static_cast< const T* >(this)); };
+
+    template <class T>
+    inline typename RingContainer<T>::iterator RingContainer<T>::begin()
+        { return RingContainer<T>::iterator(m_pStart); };
 
     template <class T>
-    inline typename Ring<T>::iterator Ring<T>::endRing()
-        { return Ring<T>::iterator(static_cast< T* >(this), false); };
+    inline typename RingContainer<T>::iterator RingContainer<T>::end()
+        { return RingContainer<T>::iterator(m_pStart, false); };
 
     template <class T>
-    inline typename Ring<T>::const_iterator Ring<T>::beginRing() const
-        { return Ring<T>::const_iterator(static_cast< const T* >(this)); };
+    inline typename RingContainer<T>::const_iterator RingContainer<T>::begin() const
+        { return RingContainer<T>::const_iterator(m_pStart); };
 
     template <class T>
-    inline typename Ring<T>::const_iterator Ring<T>::endRing() const
-        { return Ring<T>::const_iterator(static_cast< const T* >(this), false); };
+    inline typename RingContainer<T>::const_iterator RingContainer<T>::end() const
+        { return RingContainer<T>::const_iterator(m_pStart, false); };
 }
 #endif
 
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index 55a9390..584f398 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -1317,14 +1317,14 @@ void SwDocTest::testIntrusiveRing()
         CPPUNIT_ASSERT_EQUAL((*ppRing)->GetNext(), *ppNext);
         CPPUNIT_ASSERT_EQUAL((*ppNext)->GetPrev(), *ppRing);
     }
-    BOOST_FOREACH(TestRing& r, aRing1.rangeRing())
+    for(TestRing& r: aRing1.GetRingContainer())
     {
         TestRing* pRing = &r;
         CPPUNIT_ASSERT(pRing);
         //pRing->debug();
     }
     const TestRing* pConstRing = &aRing1;
-    BOOST_FOREACH(const TestRing& r, pConstRing->rangeRing()) // this should fail without r being const
+    for(const TestRing& r: pConstRing->GetRingContainer()) // this should fail without r being const
     {
         const TestRing* pRing = &r;
         CPPUNIT_ASSERT(pRing);
diff --git a/sw/source/core/doc/doccorr.cxx b/sw/source/core/doc/doccorr.cxx
index 5dc2ca0..eaf11f6 100644
--- a/sw/source/core/doc/doccorr.cxx
+++ b/sw/source/core/doc/doccorr.cxx
@@ -99,7 +99,7 @@ void PaMCorrAbs( const SwPaM& rRange,
 
     if( pShell )
     {
-        BOOST_FOREACH(const SwViewShell& rShell, pShell->rangeRing())
+        for(const SwViewShell& rShell : pShell->GetRingContainer())
         {
             if(!rShell.IsA( TYPE( SwCrsrShell )))
                 continue;
@@ -249,7 +249,7 @@ void PaMCorrRel( const SwNodeIndex &rOldNode,
     SwCrsrShell const* pShell = pDoc->GetEditShell();
     if( pShell )
     {
-        BOOST_FOREACH(const SwViewShell& rShell, pShell->rangeRing())
+        for(const SwViewShell& rShell : pShell->GetRingContainer())
         {
             if(!rShell.IsA( TYPE( SwCrsrShell )))
                 continue;
@@ -262,7 +262,7 @@ void PaMCorrRel( const SwNodeIndex &rOldNode,
                     ((_pStkCrsr = static_cast<SwPaM *>(_pStkCrsr->GetNext())) != pCrsrShell->GetStkCrsr()) );
 
             SwPaM* pStartPaM = pCrsrShell->_GetCrsr();
-            BOOST_FOREACH(SwPaM& rPaM, pStartPaM->rangeRing())
+            for(SwPaM& rPaM : pStartPaM->GetRingContainer())
             {
                 lcl_PaMCorrRel1( &rPaM, pOldNode, aNewPos, nCntIdx);
             }
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 93beffdb..132501f 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -2538,7 +2538,7 @@ void SwEditShell::AutoFormat( const SvxSwAutoFmtFlags* pAFlags )
     // There are more than one or a selection is open
     if( pCrsr->GetNext() != pCrsr || pCrsr->HasMark() )
     {
-        BOOST_FOREACH(SwPaM& rPaM, GetCrsr()->rangeRing())
+        for(SwPaM& rPaM : GetCrsr()->GetRingContainer())
         {
             if( rPaM.HasMark() )
             {


More information about the Libreoffice-commits mailing list