sw/inc/calbck.hxx | 57 ++++++++++++++++---------------- sw/qa/core/uwriter.cxx | 69 ++++++++++++++++++++++++++++++--------- sw/source/core/fields/expfld.cxx | 2 - 3 files changed, 84 insertions(+), 44 deletions(-)
New commits: commit 317c8e5c80308e829c4bc29958e03931cd8db3ef Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 20 15:22:44 2015 +0100 use static_cast<> and typeid, its faster Change-Id: I80f66686a09dfe629b9aa9f9cb7babe1c5a6edac diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 4ff6cc7..6ad3116 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -120,13 +120,13 @@ public: virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) { CheckRegistration( pOldValue, pNewValue ); } // when overriding this, you MUST call SwClient::SwClientModify() in the override! - virtual void SwClientNotify( const SwModify&, const SfxHint& rHint) - SAL_OVERRIDE + virtual void SwClientNotify( const SwModify&, const SfxHint& rHint) SAL_OVERRIDE { - // assuming the compiler to realize that a dynamic_cast to a final class is just a pointer compare ... - auto pLegacyHint(dynamic_cast<const sw::LegacyModifyHint*>(&rHint)); - if(pLegacyHint) + if(typeid(rHint) == typeid(sw::LegacyModifyHint)) + { + auto pLegacyHint(static_cast<const sw::LegacyModifyHint*>(&rHint)); Modify(pLegacyHint->m_pOld, pLegacyHint->m_pNew); + } }; // in case an SwModify object is destroyed that itself is registered in another SwModify, commit f18d1141936eafc15d428ceb823fe28584b0e2d5 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 20 13:21:58 2015 +0100 more testcode Change-Id: I6bce3350385adfa02c0501d98762e16d66f0b490 diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index c3fcad4..5818d9b 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -1390,6 +1390,7 @@ void SwDocTest::testIntrusiveRing() namespace { + struct TestHint SAL_FINAL : SfxHint {}; struct TestModify : SwModify { TYPEINFO_OVERRIDE(); @@ -1399,9 +1400,17 @@ namespace { TYPEINFO_OVERRIDE(); int m_nModifyCount; - TestClient() : m_nModifyCount(0) {}; + int m_nNotifyCount; + TestClient() : m_nModifyCount(0), m_nNotifyCount(0) {}; virtual void Modify( const SfxPoolItem*, const SfxPoolItem*) SAL_OVERRIDE { ++m_nModifyCount; } + virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) + { + if(typeid(TestHint) == typeid(rHint)) + ++m_nNotifyCount; + else + SwClient::SwClientNotify(rModify, rHint); + } }; TYPEINIT1( TestClient, SwClient ); // sad copypasta as tools/rtti.hxxs little brain cant cope with templates @@ -1420,16 +1429,35 @@ void SwDocTest::testClientModify() (void) OtherTestClient(); // avoid loplugin:unreffun TestModify aMod; TestClient aClient1, aClient2; + OtherTestClient aOtherClient1; + // test client registration + CPPUNIT_ASSERT_EQUAL(aClient1.GetRegisteredIn(),static_cast<SwModify*>(nullptr)); + CPPUNIT_ASSERT_EQUAL(aClient2.GetRegisteredIn(),static_cast<SwModify*>(nullptr)); aMod.Add(&aClient1); aMod.Add(&aClient2); CPPUNIT_ASSERT_EQUAL(aClient1.GetRegisteredIn(),static_cast<SwModify*>(&aMod)); CPPUNIT_ASSERT_EQUAL(aClient2.GetRegisteredIn(),static_cast<SwModify*>(&aMod)); + // test broadcast aMod.ModifyBroadcast(nullptr, nullptr); CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,1); CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,1); + CPPUNIT_ASSERT_EQUAL(aClient1.m_nNotifyCount,0); + CPPUNIT_ASSERT_EQUAL(aClient2.m_nNotifyCount,0); aMod.ModifyBroadcast(nullptr, nullptr); CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,2); CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,2); + CPPUNIT_ASSERT_EQUAL(aClient1.m_nNotifyCount,0); + CPPUNIT_ASSERT_EQUAL(aClient2.m_nNotifyCount,0); + // test notify + { + TestHint aHint; + aMod.CallSwClientNotify(aHint); + CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,2); + CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,2); + CPPUNIT_ASSERT_EQUAL(aClient1.m_nNotifyCount,1); + CPPUNIT_ASSERT_EQUAL(aClient2.m_nNotifyCount,1); + } + // test typed iteration CPPUNIT_ASSERT(!aClient1.IsA(TYPE(OtherTestClient))); { SwIterator<OtherTestClient,SwModify> aIter(aMod); @@ -1446,8 +1474,24 @@ void SwDocTest::testClientModify() } CPPUNIT_ASSERT_EQUAL(nCount,2); } + aMod.Add(&aOtherClient1); + CPPUNIT_ASSERT_EQUAL(aOtherClient1.m_nModifyCount,0); + { + int nCount = 0; + SwIterator<TestClient,SwModify> aIter(aMod); + for(TestClient* pClient = aIter.First(); pClient ; pClient = aIter.Next()) + { + CPPUNIT_ASSERT_EQUAL(pClient->m_nModifyCount,2); + ++nCount; + } + CPPUNIT_ASSERT_EQUAL(nCount,2); + } + CPPUNIT_ASSERT_EQUAL(aOtherClient1.m_nModifyCount,0); + aMod.Remove(&aOtherClient1); CPPUNIT_ASSERT_EQUAL(aClient1.GetRegisteredIn(),static_cast<SwModify*>(&aMod)); CPPUNIT_ASSERT_EQUAL(aClient2.GetRegisteredIn(),static_cast<SwModify*>(&aMod)); + CPPUNIT_ASSERT_EQUAL(aOtherClient1.GetRegisteredIn(),static_cast<SwModify*>(nullptr)); + // test client self-deregistration during iteration { int nCount = 0; SwIterator<TestClient,SwModify> aIter(aMod); @@ -1472,6 +1516,8 @@ void SwDocTest::testClientModify() aMod.ModifyBroadcast(nullptr, nullptr); CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,2); CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,2); + CPPUNIT_ASSERT_EQUAL(aClient1.m_nNotifyCount,1); + CPPUNIT_ASSERT_EQUAL(aClient2.m_nNotifyCount,1); } void SwDocTest::setUp() commit c5036a67632a2b3a5dae7e8e4cfc6820484ac660 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 20 12:30:12 2015 +0100 copy a full OtherTestClient implementation Change-Id: I3d72385ae643bec9623fd2e8f406504a20b4142c diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index 31e0ee8..c3fcad4 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -1400,26 +1400,19 @@ namespace TYPEINFO_OVERRIDE(); int m_nModifyCount; TestClient() : m_nModifyCount(0) {}; - virtual void Modify( const SfxPoolItem*, const SfxPoolItem*) - SAL_OVERRIDE - { - ShowReg(); - ++m_nModifyCount; - } - - void ShowReg() - { - if(GetRegisteredIn()) - { - std::cout << "TestClient " << this << " registered in " << GetRegisteredIn() << std::endl; - } - else - std::cout << "TestClient " << this << " not registered " << std::endl; - } + virtual void Modify( const SfxPoolItem*, const SfxPoolItem*) SAL_OVERRIDE + { ++m_nModifyCount; } }; TYPEINIT1( TestClient, SwClient ); + // sad copypasta as tools/rtti.hxxs little brain cant cope with templates struct OtherTestClient : SwClient - { TYPEINFO_OVERRIDE(); }; + { + TYPEINFO_OVERRIDE(); + int m_nModifyCount; + OtherTestClient() : m_nModifyCount(0) {}; + virtual void Modify( const SfxPoolItem*, const SfxPoolItem*) SAL_OVERRIDE + { ++m_nModifyCount; } + }; TYPEINIT1( OtherTestClient, SwClient ); } void SwDocTest::testClientModify() commit 0bf4e6e21101a66bb63778ab49006ee90c16ea94 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 20 03:08:22 2015 +0100 make ClientIteratorBase only know about WriterListener Change-Id: Ice6fb793e3f27abfbf000b4a290fd4f3309e1770 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 2af23b7..4ff6cc7 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -98,6 +98,7 @@ class SW_DLLPUBLIC SwClient : ::sw::WriterListener // avoids making the details of the linked list and the callback method public friend class SwModify; friend class sw::ClientIteratorBase; + template<typename E, typename S> friend class SwIterator; SwModify *pRegisteredIn; ///< event source @@ -192,7 +193,7 @@ public: void Add(SwClient *pDepend); SwClient* Remove(SwClient *pDepend); - const SwClient* GetDepends() const { return static_cast<SwClient*>(pRoot); } + const sw::WriterListener* GetDepends() const { return pRoot; } // get information about attribute virtual bool GetInfo( SfxPoolItem& ) const SAL_OVERRIDE; @@ -250,11 +251,11 @@ namespace sw protected: const SwModify& m_rRoot; // the current object in an iteration - SwClient* m_pCurrent; + WriterListener* m_pCurrent; // in case the current object is already removed, the next object in the list // is marked down to become the current object in the next step // this is necessary because iteration requires access to members of the current object - SwClient* m_pPosition; + WriterListener* m_pPosition; static SW_DLLPUBLIC ClientIteratorBase* our_pClientIters; ClientIteratorBase( const SwModify& rModify ) @@ -262,15 +263,15 @@ namespace sw { MoveTo(our_pClientIters); our_pClientIters = this; - m_pCurrent = m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()); + m_pCurrent = m_pPosition = const_cast<WriterListener*>(m_rRoot.GetDepends()); } - SwClient* GetLeftOfPos() { return static_cast<SwClient*>(m_pPosition->m_pLeft); } - SwClient* GetRightOfPos() { return static_cast<SwClient*>(m_pPosition->m_pRight); } - SwClient* GoStart() + WriterListener* GetLeftOfPos() { return m_pPosition->m_pLeft; } + WriterListener* GetRightOfPos() { return m_pPosition->m_pRight; } + WriterListener* GoStart() { - if((m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()))) + if((m_pPosition = const_cast<WriterListener*>(m_rRoot.GetDepends()))) while( m_pPosition->m_pLeft ) - m_pPosition = static_cast<SwClient*>(m_pPosition->m_pLeft); + m_pPosition = m_pPosition->m_pLeft; return m_pCurrent = m_pPosition; } ~ClientIteratorBase() SAL_OVERRIDE @@ -285,7 +286,7 @@ namespace sw // SwModify::Add() asserts this bool IsChanged() const { return m_pPosition != m_pCurrent; } // ensures the iterator to point at a current client - SwClient* Sync() { return m_pCurrent = m_pPosition; } + WriterListener* Sync() { return m_pCurrent = m_pPosition; } }; } @@ -306,29 +307,29 @@ public: TElementType* Last() { if(!m_pPosition) - m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()); + m_pPosition = const_cast<sw::WriterListener*>(m_rRoot.GetDepends()); if(!m_pPosition) - return PTR_CAST(TElementType,Sync()); + return PTR_CAST(TElementType,static_cast<SwClient*>(Sync())); while(GetRightOfPos()) m_pPosition = GetRightOfPos(); - if(m_pPosition->IsA(TYPE(TElementType))) - return PTR_CAST(TElementType,Sync()); + if(static_cast<SwClient*>(m_pPosition)->IsA(TYPE(TElementType))) + return PTR_CAST(TElementType,static_cast<SwClient*>(Sync())); return Previous(); } TElementType* Next() { if(!IsChanged()) m_pPosition = GetRightOfPos(); - while(m_pPosition && !m_pPosition->IsA( TYPE(TElementType) ) ) + while(m_pPosition && !static_cast<SwClient*>(m_pPosition)->IsA( TYPE(TElementType) ) ) m_pPosition = GetRightOfPos(); - return PTR_CAST(TElementType,Sync()); + return PTR_CAST(TElementType,static_cast<SwClient*>(Sync())); } TElementType* Previous() { m_pPosition = GetLeftOfPos(); - while(m_pPosition && !m_pPosition->IsA( TYPE(TElementType) ) ) + while(m_pPosition && !static_cast<SwClient*>(m_pPosition)->IsA( TYPE(TElementType) ) ) m_pPosition = GetLeftOfPos(); - return PTR_CAST(TElementType,Sync()); + return PTR_CAST(TElementType,static_cast<SwClient*>(Sync())); } using sw::ClientIteratorBase::IsChanged; }; @@ -339,27 +340,27 @@ template< typename TSource > class SwIterator<SwClient, TSource> SAL_FINAL : pri public: SwIterator( const TSource& rSrc ) : sw::ClientIteratorBase(rSrc) {} SwClient* First() - { return GoStart(); } + { return static_cast<SwClient*>(GoStart()); } SwClient* Last() { if(!m_pPosition) - m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()); + m_pPosition = const_cast<sw::WriterListener*>(m_rRoot.GetDepends()); if(!m_pPosition) return m_pCurrent = nullptr; while(GetRightOfPos()) m_pPosition = GetRightOfPos(); - return Sync(); + return static_cast<SwClient*>(Sync()); } SwClient* Next() { if(!IsChanged()) m_pPosition = GetRightOfPos(); - return Sync(); + return static_cast<SwClient*>(Sync()); } SwClient* Previous() { m_pPosition = GetLeftOfPos(); - return Sync(); + return static_cast<SwClient*>(Sync()); } using sw::ClientIteratorBase::IsChanged; }; diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx index 24ba569..80b9ace 100644 --- a/sw/source/core/fields/expfld.cxx +++ b/sw/source/core/fields/expfld.cxx @@ -528,7 +528,7 @@ sal_uLong SwSetExpFieldType::GetSeqFormat() if( !GetDepends() ) return SVX_NUM_ARABIC; - const SwField *pFld = static_cast<const SwFmtFld*>(GetDepends())->GetField(); + const SwField *pFld = SwIterator<SwFmtFld,SwSetExpFieldType>(*this).First()->GetField(); return pFld->GetFormat(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits