diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2014-12-01 02:27:14 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2014-12-02 00:33:19 +0100 |
commit | 4a5928ee4ca55d22a0fa122886ecc7d6a55e9247 (patch) | |
tree | 7cb37d6262f12078dc1889aa3f834dce8e2290c1 /sw | |
parent | efddd4b6e0e80bdbdb74ea43654d258dedb7d13d (diff) |
more testing and initial iterators
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/ring.hxx | 34 | ||||
-rw-r--r-- | sw/qa/core/uwriter.cxx | 41 | ||||
-rw-r--r-- | sw/source/core/bastyp/ring.cxx | 10 |
3 files changed, 80 insertions, 5 deletions
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx index 8b65d721e848..cec52844857c 100644 --- a/sw/inc/ring.hxx +++ b/sw/inc/ring.hxx @@ -21,12 +21,16 @@ #include <swdllapi.h> #include <swtypes.hxx> +#include <boost/iterator/iterator_facade.hpp> class Ring_node_traits; +class RingIterator; class SW_DLLPUBLIC Ring { friend class Ring_node_traits; + typedef RingIterator iterator; + typedef RingIterator const_iterator; Ring* pNext; Ring* pPrev; ///< In order to speed up inserting and deleting. @@ -44,6 +48,36 @@ public: sal_uInt32 numberOf() const; }; +class RingIterator : public boost::iterator_facade< + RingIterator + , Ring + , boost::forward_traversal_tag + > +{ + public: + RingIterator() + : m_pCurrent(nullptr) + , m_pStart(nullptr) + {} + explicit RingIterator(Ring* pRing, bool bStart = true) + : m_pCurrent(nullptr) + , m_pStart(pRing) + { + if(!bStart) + m_pCurrent = m_pStart; + } + private: + friend class boost::iterator_core_access; + void increment() + { m_pCurrent = m_pCurrent ? m_pCurrent->GetNext() : m_pStart->GetNext(); } + bool equal(RingIterator const& other) const + { return m_pCurrent == other.m_pCurrent && m_pStart == m_pStart; } + Ring& dereference() const + { return m_pCurrent ? *m_pCurrent : * m_pStart; } + Ring* m_pCurrent; + Ring* m_pStart; +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index cb6b1b7ff662..0a38d79ebd67 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -57,6 +57,7 @@ #include "modeltoviewhelper.hxx" #include "scriptinfo.hxx" #include "IMark.hxx" +#include "ring.hxx" typedef tools::SvRef<SwDocShell> SwDocShellRef; @@ -100,7 +101,7 @@ public: void testGraphicAnchorDeletion(); void testTransliterate(); void testMarkMove(); - void testInstrusiveList(); + void testIntrusiveRing(); CPPUNIT_TEST_SUITE(SwDocTest); CPPUNIT_TEST(testTransliterate); @@ -128,7 +129,7 @@ public: CPPUNIT_TEST(testUserPerceivedCharCount); CPPUNIT_TEST(testGraphicAnchorDeletion); CPPUNIT_TEST(testMarkMove); - CPPUNIT_TEST(testInstrusiveList); + CPPUNIT_TEST(testIntrusiveRing); CPPUNIT_TEST_SUITE_END(); private: @@ -1271,8 +1272,42 @@ void SwDocTest::testMarkMove() pBM3->GetMarkEnd().nNode.GetIndex()); } -void SwDocTest::testInstrusiveList() +namespace { + struct TestRing : public Ring + { + TestRing() : Ring() {}; + void debug() + { + SAL_DEBUG("TestRing at: " << this << " prev: " << GetPrev() << " next: " << GetNext()); + } + }; +} + +void SwDocTest::testIntrusiveRing() +{ + TestRing aRing1, aRing2, aRing3, aRing4, aRing5; + CPPUNIT_ASSERT_EQUAL(aRing1.numberOf(), static_cast<sal_uInt32>(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)); + aRing5.MoveTo(&aRing4); + CPPUNIT_ASSERT_EQUAL(aRing4.numberOf(), static_cast<sal_uInt32>(2)); + aRing4.MoveRingTo(&aRing1); + CPPUNIT_ASSERT_EQUAL(aRing1.numberOf(), static_cast<sal_uInt32>(5)); + CPPUNIT_ASSERT_EQUAL(aRing4.numberOf(), static_cast<sal_uInt32>(5)); + CPPUNIT_ASSERT_EQUAL(aRing1.GetNext(), static_cast<Ring*>(&aRing2)); + CPPUNIT_ASSERT_EQUAL(aRing2.GetNext(), static_cast<Ring*>(&aRing3)); + CPPUNIT_ASSERT_EQUAL(aRing3.GetNext(), static_cast<Ring*>(&aRing4)); + CPPUNIT_ASSERT_EQUAL(aRing4.GetNext(), static_cast<Ring*>(&aRing5)); + CPPUNIT_ASSERT_EQUAL(aRing5.GetNext(), static_cast<Ring*>(&aRing1)); + CPPUNIT_ASSERT_EQUAL(aRing2.GetPrev(), static_cast<Ring*>(&aRing1)); + CPPUNIT_ASSERT_EQUAL(aRing3.GetPrev(), static_cast<Ring*>(&aRing2)); + CPPUNIT_ASSERT_EQUAL(aRing4.GetPrev(), static_cast<Ring*>(&aRing3)); + CPPUNIT_ASSERT_EQUAL(aRing5.GetPrev(), static_cast<Ring*>(&aRing4)); + CPPUNIT_ASSERT_EQUAL(aRing1.GetPrev(), static_cast<Ring*>(&aRing5)); } void SwDocTest::setUp() diff --git a/sw/source/core/bastyp/ring.cxx b/sw/source/core/bastyp/ring.cxx index 5db41f54ad50..b7ce9c062d08 100644 --- a/sw/source/core/bastyp/ring.cxx +++ b/sw/source/core/bastyp/ring.cxx @@ -55,7 +55,12 @@ void Ring::MoveTo(Ring *pDestRing) { // insert into "new" if( pDestRing ) - algo::transfer(pDestRing, this); + { + if(algo::unique(this)) + algo::link_before(pDestRing, this); + else + algo::transfer(pDestRing, this); + } else algo::unlink(this); @@ -63,7 +68,8 @@ void Ring::MoveTo(Ring *pDestRing) void Ring::MoveRingTo(Ring *pDestRing) { - algo::transfer(pDestRing, this, this); + std::swap(*(&pPrev->pNext), *(&pDestRing->pPrev->pNext)); + std::swap(*(&pPrev), *(&pDestRing->pPrev)); } sal_uInt32 Ring::numberOf() const |