[Libreoffice-commits] core.git: 5 commits - sw/inc sw/qa sw/source
Bjoern Michaelsen
bjoern.michaelsen at canonical.com
Tue Dec 2 02:15:41 PST 2014
sw/inc/edimp.hxx | 2
sw/inc/ring.hxx | 70 ++++++++++++++++++++++++++++++----
sw/qa/core/uwriter.cxx | 20 ++++++---
sw/source/core/crsr/viscrs.cxx | 6 +-
sw/source/core/doc/doccorr.cxx | 6 +-
sw/source/core/frmedt/fecopy.cxx | 2
sw/source/uibase/docvw/SidebarWin.cxx | 6 +-
7 files changed, 87 insertions(+), 25 deletions(-)
New commits:
commit 2dd7cc5b925d0b4c62553eeba9f6524ce7b6217b
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date: Tue Dec 2 11:14:24 2014 +0100
simplify
Change-Id: I8cd66f270526880f6ad7fb083aaa65c87079dfc1
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index 8fd104c..55a9390 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -1317,7 +1317,7 @@ void SwDocTest::testIntrusiveRing()
CPPUNIT_ASSERT_EQUAL((*ppRing)->GetNext(), *ppNext);
CPPUNIT_ASSERT_EQUAL((*ppNext)->GetPrev(), *ppRing);
}
- BOOST_FOREACH(TestRing& r, std::make_pair(aRing1.beginRing(), aRing1.endRing()))
+ BOOST_FOREACH(TestRing& r, aRing1.rangeRing())
{
TestRing* pRing = &r;
CPPUNIT_ASSERT(pRing);
commit 55a509616614cc4e50acbb9f257f7334db6667f9
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date: Tue Dec 2 11:11:55 2014 +0100
test constness
Change-Id: I74523d0264f2fe78353c8f61d98295c65cd23ee1
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index f667542..8fd104c 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -1323,6 +1323,12 @@ void SwDocTest::testIntrusiveRing()
CPPUNIT_ASSERT(pRing);
//pRing->debug();
}
+ const TestRing* pConstRing = &aRing1;
+ BOOST_FOREACH(const TestRing& r, pConstRing->rangeRing()) // this should fail without r being const
+ {
+ const TestRing* pRing = &r;
+ CPPUNIT_ASSERT(pRing);
+ }
}
void SwDocTest::setUp()
commit 2277558d01c168feec10c6340f919e7847ab2dbe
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date: Tue Dec 2 11:04:15 2014 +0100
rename numberOf() to STL-like size()
Change-Id: I82332e91ed152e42b55ae921b3b61c5144253c39
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index e587ad3..d58733f 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -124,7 +124,7 @@ namespace sw
{ return std::make_pair(beginRing(), endRing()); }
/** @return the number of elements in the container */
- sal_uInt32 numberOf() const
+ size_t size() const
{ return algo::count(static_cast< const T* >(this)); }
};
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index 45e0cf6..f667542 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.numberOf(), static_cast<sal_uInt32>(1));
+ CPPUNIT_ASSERT_EQUAL(aRing1.size(), static_cast<size_t>(1));
aRing2.MoveTo(&aRing1);
aRing3.MoveTo(&aRing1);
- CPPUNIT_ASSERT_EQUAL(aRing1.numberOf(), static_cast<sal_uInt32>(3));
- CPPUNIT_ASSERT_EQUAL(aRing2.numberOf(), static_cast<sal_uInt32>(3));
- CPPUNIT_ASSERT_EQUAL(aRing3.numberOf(), static_cast<sal_uInt32>(3));
+ 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));
aRing5.MoveTo(&aRing4);
- CPPUNIT_ASSERT_EQUAL(aRing4.numberOf(), static_cast<sal_uInt32>(2));
+ CPPUNIT_ASSERT_EQUAL(aRing4.size(), static_cast<size_t>(2));
aRing4.MoveRingTo(&aRing1);
BOOST_FOREACH(TestRing* pRing, vRings)
{
- CPPUNIT_ASSERT_EQUAL(pRing->numberOf(), static_cast<sal_uInt32>(5));
+ CPPUNIT_ASSERT_EQUAL(pRing->size(), static_cast<size_t>(5));
}
for(std::vector<TestRing*>::iterator ppRing = vRings.begin(); ppRing != vRings.end(); ++ppRing)
{
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index b305c19..8c1b5d1 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -369,10 +369,10 @@ void SwSelPaintRects::HighlightInputFld()
pCrsrForInputTxtFld->GetMark()->nContent.Assign( pTxtNode, *(pCurTxtInputFldAtCrsr->End()) );
pCrsrForInputTxtFld->FillRects();
-
- for (size_t a(0); a < pCrsrForInputTxtFld->size(); ++a)
+ SwRects* pRects = static_cast<SwRects*>(pCrsrForInputTxtFld.get());
+ for (size_t a(0); a < pRects->size(); ++a)
{
- const SwRect aNextRect((*pCrsrForInputTxtFld)[a]);
+ const SwRect aNextRect((*pRects)[a]);
const Rectangle aPntRect(aNextRect.SVRect());
aInputFldRanges.push_back(basegfx::B2DRange(
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index e69cfe9..95a5033 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->numberOf();
+ sal_uInt32 nCursorCount = pStartCursor->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...
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
index 84d9974..e6f4a91 100644
--- a/sw/source/uibase/docvw/SidebarWin.cxx
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
@@ -677,10 +677,10 @@ void SwSidebarWin::SetPosAndSize()
::boost::scoped_ptr<SwShellCrsr> pTmpCrsrForAnnotationTextRange( pTmpCrsr );
pTmpCrsrForAnnotationTextRange->FillRects();
-
- for( sal_uInt16 a(0); a < pTmpCrsrForAnnotationTextRange->size(); ++a )
+ SwRects* pRects(pTmpCrsrForAnnotationTextRange.get());
+ for( size_t a(0); a < pRects->size(); ++a )
{
- const SwRect aNextRect((*pTmpCrsrForAnnotationTextRange)[a]);
+ const SwRect aNextRect((*pRects)[a]);
const Rectangle aPntRect(aNextRect.SVRect());
aAnnotationTextRanges.push_back(basegfx::B2DRange(
commit 98f0516f158fbcacdc50e4e3f9e25f9ee6651d09
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date: Tue Dec 2 10:13:57 2014 +0100
ring docs
Change-Id: Ie26b98bb2e2946f326de6ff58677e33539db70b6
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index 33bc069..e587ad3 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -30,9 +30,14 @@ namespace sw
class Ring_node_traits;
template <class T> class RingIterator;
+ /**
+ * An intrusive container class double linking the contained nodes
+ * @example sw/qa/core/uwriter.cxx
+ */
template <class T>
class Ring
{
+ /** internal implementation class -- not for external use */
struct Ring_node_traits
{
typedef T node;
@@ -46,33 +51,79 @@ namespace sw
friend struct Ring_node_traits;
typedef boost::intrusive::circular_list_algorithms<Ring_node_traits> algo;
T* pNext;
- T* pPrev; ///< In order to speed up inserting and deleting.
+ T* pPrev;
protected:
+ /**
+ * Creates a new item in a ring container all by itself.
+ * Note: Ring instances can newer be outside a container. At most, they
+ * are alone in one.
+ */
Ring()
{ algo::init_header(static_cast< T* >(this)); }
- Ring( T* );
+ /**
+ * Creates a new item and add it to an existing ring container.
+ * Note: the newly created item will be inserted just before item pRing.
+ * @param pRing ring container to add the created item to
+ */
+ Ring( T* pRing );
public:
typedef RingIterator<T> iterator;
typedef RingIterator<const T> const_iterator;
virtual ~Ring()
{ algo::unlink(static_cast< T* >(this)); };
+ /**
+ * Removes this item from its current ring container and adds it to
+ * another ring container. If the item was not alone in the original
+ * ring container, the other items in the ring will stay in the old
+ * ring container.
+ * Note: the newly created item will be inserted just before item pDestRing.
+ * @param pDestRing the container to add this item to
+ */
void MoveTo( T* pDestRing );
+ /**
+ * Merges two ring containers. All item from both ring containers will
+ * be in the same ring container in the end.
+ * Note: The items of this ring container will be inserted just before
+ * item pDestRing
+ * @param pDestRing the container to merge this container with
+ */
void MoveRingTo( T* pDestRing );
- T* GetNext() const { return pNext; }
- T* GetPrev() const { return pPrev; }
- // unfortunately we cant name these STL-conforming, as some derived classes
- // also derive from other STL containers (which is bad anyway, but ...)
+ /** @return the next item in the ring container */
+ T* GetNext() const
+ { return pNext; }
+ /** @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 */
sal_uInt32 numberOf() const
{ return algo::count(static_cast< const T* >(this)); }
};
commit 1bea427d55ecf4a1914a6c404fc0f06a7bb044bd
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date: Tue Dec 2 09:36:37 2014 +0100
add rangeRing() for easier iteration
Change-Id: I0ef002c0c32c1435cbc62f954f98dc11c3f69945
diff --git a/sw/inc/edimp.hxx b/sw/inc/edimp.hxx
index 9f22e64..f3f985a 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, std::make_pair((pCURSH)->beginRing(), (pCURSH)->endRing())) \
+ BOOST_FOREACH(SwPaM& __r, (pCURSH)->rangeRing()) \
{
#define FOREACHPAM_END() }
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index e364be8..33bc069 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -21,6 +21,7 @@
#include <swdllapi.h>
#include <swtypes.hxx>
+#include <utility>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/intrusive/circular_list_algorithms.hpp>
@@ -67,6 +68,10 @@ namespace sw
iterator endRing();
const_iterator beginRing() const;
const_iterator endRing() const;
+ 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()); }
sal_uInt32 numberOf() const
{ return algo::count(static_cast< const T* >(this)); }
diff --git a/sw/source/core/doc/doccorr.cxx b/sw/source/core/doc/doccorr.cxx
index 67f6c95..5dc2ca0 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, std::make_pair(pShell->beginRing(), pShell->endRing()))
+ BOOST_FOREACH(const SwViewShell& rShell, pShell->rangeRing())
{
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, std::make_pair(pShell->beginRing(), pShell->endRing()))
+ BOOST_FOREACH(const SwViewShell& rShell, pShell->rangeRing())
{
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, std::make_pair(pStartPaM->beginRing(), pStartPaM->endRing()))
+ BOOST_FOREACH(SwPaM& rPaM, pStartPaM->rangeRing())
{
lcl_PaMCorrRel1( &rPaM, pOldNode, aNewPos, nCntIdx);
}
More information about the Libreoffice-commits
mailing list