sw/inc/calbck.hxx | 246 ++++++++++++++++++++++++--------- sw/source/core/attr/calbck.cxx | 305 ++++------------------------------------- 2 files changed, 214 insertions(+), 337 deletions(-)
New commits: commit ccc6ec97d85734beb375467fdc570a4db0e2925c Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 14:58:03 2015 +0100 SwDepend: naming conventions Change-Id: I778aaefdcc3ec741065cd1e58265c14a7dae5f97 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index d1c93f5..d3a02ec 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -196,32 +196,32 @@ public: /* * Helper class for objects that need to depend on more than one SwClient */ -class SW_DLLPUBLIC SwDepend: public SwClient +class SW_DLLPUBLIC SwDepend SAL_FINAL : public SwClient { - SwClient *pToTell; + SwClient *m_pToTell; public: - SwDepend() : pToTell(nullptr) {} - SwDepend(SwClient *pTellHim, SwModify *pDepend) : SwClient(pDepend), pToTell(pTellHim) {} + SwDepend() : m_pToTell(nullptr) {} + SwDepend(SwClient *pTellHim, SwModify *pDepend) : SwClient(pDepend), m_pToTell(pTellHim) {} - SwClient* GetToTell() { return pToTell; } + SwClient* GetToTell() { return m_pToTell; } /** get Client information */ virtual bool GetInfo( SfxPoolItem& rInfo) const SAL_OVERRIDE - { return pToTell ? pToTell->GetInfo( rInfo ) : true; } + { return m_pToTell ? m_pToTell->GetInfo( rInfo ) : true; } protected: virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem *pNewValue ) SAL_OVERRIDE { if( pNewValue && pNewValue->Which() == RES_OBJECTDYING ) CheckRegistration(pOldValue,pNewValue); - else if( pToTell ) - pToTell->ModifyNotification(pOldValue, pNewValue); + else if( m_pToTell ) + m_pToTell->ModifyNotification(pOldValue, pNewValue); } virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) SAL_OVERRIDE - { if(pToTel) pToTell->SwClientNotifyCall(rModify, rHint); } + { if(m_pToTell) m_pToTell->SwClientNotifyCall(rModify, rHint); } }; -class SwClientIter : public sw::Ring<SwClientIter> +class SwClientIter SAL_FINAL : public sw::Ring<SwClientIter> { friend SwClient* SwModify::Remove(SwClient *); ///< for pointer adjustments friend void SwModify::Add(SwClient *pDepend); ///< for pointer adjustments commit e341d3353e30be084da5b1c1758f8de25519159a Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 14:57:08 2015 +0100 SwDepend: cosmetics Change-Id: I6b20b0b3b301811cdd426a26cc40e12498516c2f diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 54d9b18..d1c93f5 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -27,6 +27,7 @@ #include <hintids.hxx> #include <hints.hxx> + class SwModify; class SwClientIter; class SfxPoolItem; @@ -200,7 +201,7 @@ class SW_DLLPUBLIC SwDepend: public SwClient SwClient *pToTell; public: - SwDepend() : pToTell(0) {} + SwDepend() : pToTell(nullptr) {} SwDepend(SwClient *pTellHim, SwModify *pDepend) : SwClient(pDepend), pToTell(pTellHim) {} SwClient* GetToTell() { return pToTell; } @@ -217,10 +218,7 @@ protected: pToTell->ModifyNotification(pOldValue, pNewValue); } virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) SAL_OVERRIDE - { - if ( pToTell ) - pToTell->SwClientNotifyCall( rModify, rHint ); - } + { if(pToTel) pToTell->SwClientNotifyCall(rModify, rHint); } }; class SwClientIter : public sw::Ring<SwClientIter> commit 0ec458926072457103cc9461cd908b8993d50402 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 14:51:53 2015 +0100 inline SwDepends trivials Change-Id: I6fb306aec5fee5f97a7ef33862f74f6030136fc0 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 135b4fe..54d9b18 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -24,6 +24,8 @@ #include "swdllapi.h" #include <boost/noncopyable.hpp> #include <ring.hxx> +#include <hintids.hxx> +#include <hints.hxx> class SwModify; class SwClientIter; @@ -199,15 +201,26 @@ class SW_DLLPUBLIC SwDepend: public SwClient public: SwDepend() : pToTell(0) {} - SwDepend(SwClient *pTellHim, SwModify *pDepend); + SwDepend(SwClient *pTellHim, SwModify *pDepend) : SwClient(pDepend), pToTell(pTellHim) {} SwClient* GetToTell() { return pToTell; } /** get Client information */ - virtual bool GetInfo( SfxPoolItem & ) const SAL_OVERRIDE; + virtual bool GetInfo( SfxPoolItem& rInfo) const SAL_OVERRIDE + { return pToTell ? pToTell->GetInfo( rInfo ) : true; } protected: - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNewValue ) SAL_OVERRIDE; - virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) SAL_OVERRIDE; + virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem *pNewValue ) SAL_OVERRIDE + { + if( pNewValue && pNewValue->Which() == RES_OBJECTDYING ) + CheckRegistration(pOldValue,pNewValue); + else if( pToTell ) + pToTell->ModifyNotification(pOldValue, pNewValue); + } + virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) SAL_OVERRIDE + { + if ( pToTell ) + pToTell->SwClientNotifyCall( rModify, rHint ); + } }; class SwClientIter : public sw::Ring<SwClientIter> diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 7d317af..636ee94 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -270,30 +270,5 @@ void SwModify::CheckCaching( const sal_uInt16 nWhich ) } } -SwDepend::SwDepend( SwClient* pTellHim, SwModify* pDepend ) - : SwClient( pDepend ) -{ - pToTell = pTellHim; -} - -void SwDepend::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) -{ - if( pNewValue && pNewValue->Which() == RES_OBJECTDYING ) - CheckRegistration(pOldValue,pNewValue); - else if( pToTell ) - pToTell->ModifyNotification(pOldValue, pNewValue); -} - -void SwDepend::SwClientNotify( const SwModify& rMod, const SfxHint& rHint ) -{ - if ( pToTell ) - pToTell->SwClientNotifyCall( rMod, rHint ); -} - -bool SwDepend::GetInfo( SfxPoolItem& rInfo ) const -{ - return pToTell ? pToTell->GetInfo( rInfo ) : true; -} - SwClientIter* SwClientIter::our_pClientIters = nullptr; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit e755c1d446d719fe796ad7811405b7bf0680a190 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 14:30:10 2015 +0100 inline broadcast iterations Change-Id: If6f83887ad398161d9ccb1e2649ca6cdfd933ca5 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 3520416..135b4fe 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -155,10 +155,10 @@ public: // the same, but without setting bModifyLocked or checking for any of the flags // mba: it would be interesting to know why this is necessary // also allows to limit callback to certain type (HACK) - void ModifyBroadcast( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue, TypeId nType = TYPE(SwClient) ); + inline void ModifyBroadcast( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue, TypeId nType = TYPE(SwClient) ); // a more universal broadcasting mechanism - void CallSwClientNotify( const SfxHint& rHint ) const; + inline void CallSwClientNotify( const SfxHint& rHint ) const; // single argument ctors shall be explicit. explicit SwModify( SwModify* pToRegisterIn ) @@ -333,6 +333,19 @@ SwClient::SwClient( SwModify* pToRegisterIn ) if(pToRegisterIn) pToRegisterIn->Add(this); } + +void SwModify::ModifyBroadcast( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue, TypeId nType) +{ + SwClientIter aIter(*this); + for(aIter.First(nType); aIter; aIter.Next()) + aIter->Modify( pOldValue, pNewValue ); +} + +void SwModify::CallSwClientNotify( const SfxHint& rHint ) const +{ + for(SwClientIter aIter(*this); aIter; ++aIter) + aIter->SwClientNotify( *this, rHint ); +} #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index a268b3d..7d317af 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -270,19 +270,6 @@ void SwModify::CheckCaching( const sal_uInt16 nWhich ) } } -void SwModify::CallSwClientNotify( const SfxHint& rHint ) const -{ - for(SwClientIter aIter(*this); aIter; ++aIter) - aIter->SwClientNotify( *this, rHint ); -} - -void SwModify::ModifyBroadcast( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue, TypeId nType ) -{ - SwClientIter aIter(*this); - for(aIter.First(nType); aIter; aIter.Next()) - aIter->Modify( pOldValue, pNewValue ); -} - SwDepend::SwDepend( SwClient* pTellHim, SwModify* pDepend ) : SwClient( pDepend ) { commit 9bfd0481dc7d37da994eb215b238c12f2f68b485 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 14:14:09 2015 +0100 simplify SwClientIter iteration Change-Id: I078fd3808768cd49190984278207045cc73aa8e6 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 5955a7d..3520416 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -276,6 +276,14 @@ public: // otherwise it returns the next SwClient that still is SwClient* operator()() const { return m_pPosition; } + // returns the current SwClient object, wether it is still a client or not + SwClient& operator*() const + { return *m_pCurrent; } + // returns the current SwClient object, wether it is still a client or not + SwClient* operator->() const + { return m_pCurrent; } + explicit operator bool() const + { return m_pCurrent!=nullptr; } // return "true" if an object was removed from a client chain in iteration // adding objects to a client chain in iteration is forbidden diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 6c32760..a268b3d 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -272,24 +272,15 @@ void SwModify::CheckCaching( const sal_uInt16 nWhich ) void SwModify::CallSwClientNotify( const SfxHint& rHint ) const { - SwClientIter aIter(*this); - SwClient* pClient = aIter.GoStart(); - while( pClient ) - { - pClient->SwClientNotify( *this, rHint ); - pClient = ++aIter; - } + for(SwClientIter aIter(*this); aIter; ++aIter) + aIter->SwClientNotify( *this, rHint ); } void SwModify::ModifyBroadcast( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue, TypeId nType ) { - SwClientIter aIter( *this ); - SwClient* pClient = aIter.First( nType ); - while( pClient ) - { - pClient->Modify( pOldValue, pNewValue ); - pClient = aIter.Next(); - } + SwClientIter aIter(*this); + for(aIter.First(nType); aIter; aIter.Next()) + aIter->Modify( pOldValue, pNewValue ); } SwDepend::SwDepend( SwClient* pTellHim, SwModify* pDepend ) commit 8152cf6df78c7a7bb632f708311b17a50eb091c8 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 13:46:59 2015 +0100 simpilfy SwClient::operator() Change-Id: I78e9791d99cbc5434606b98b7b0103758e7e3812 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 6f95eed..5955a7d 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -272,11 +272,10 @@ public: return m_pCurrent = m_pPosition; } - // returns the current SwClient object; - // in case this was already removed, the object marked down to become - // the next current one is returned + // returns the current SwClient object, if its still a listener + // otherwise it returns the next SwClient that still is SwClient* operator()() const - { return m_pPosition == m_pCurrent ? m_pCurrent : m_pPosition; } + { return m_pPosition; } // return "true" if an object was removed from a client chain in iteration // adding objects to a client chain in iteration is forbidden commit e2a38e6599247b90ed4ff903f8a9cc64b6a3af68 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 13:44:40 2015 +0100 inline trivial SwModify functions Change-Id: I0dda2a53e49073a75b9ce14d7aa4b5088eeb2fd7 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index fd7785b..6f95eed 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -141,10 +141,13 @@ class SW_DLLPUBLIC SwModify: public SwClient bool bInSwFntCache : 1; // mba: IMHO this method should be pure virtual - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; + virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE + { NotifyClients( pOld, pNew ); }; public: - SwModify(); + SwModify() + : SwClient(nullptr), pRoot(nullptr), bModifyLocked(false), bLockClientList(false), bInDocDTOR(false), bInCache(false), bInSwFntCache(false) + {} // broadcasting: send notifications to all clients void NotifyClients( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ); @@ -158,7 +161,10 @@ public: void CallSwClientNotify( const SfxHint& rHint ) const; // single argument ctors shall be explicit. - explicit SwModify( SwModify *pToRegisterIn ); + explicit SwModify( SwModify* pToRegisterIn ) + : SwClient(pToRegisterIn), pRoot(nullptr), bModifyLocked(false), bLockClientList(false), bInDocDTOR(false), bInCache(false), bInSwFntCache(false) + {} + virtual ~SwModify(); void Add(SwClient *pDepend); diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 350030c..6c32760 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -56,27 +56,6 @@ void SwClient::CheckRegistration( const SfxPoolItem* pOld, const SfxPoolItem* ) } } - -SwModify::SwModify() - : SwClient(nullptr), pRoot(nullptr) -{ - bModifyLocked = false; - bLockClientList = false; - bInDocDTOR = false; - bInCache = false; - bInSwFntCache = false; -} - -SwModify::SwModify( SwModify* pToRegisterIn ) - : SwClient( pToRegisterIn ), pRoot( nullptr ) -{ - bModifyLocked = false; - bLockClientList = false; - bInDocDTOR = false; - bInCache = false; - bInSwFntCache = false; -} - SwModify::~SwModify() { OSL_ENSURE( !IsModifyLocked(), "Modify destroyed but locked." ); @@ -117,11 +96,6 @@ SwModify::~SwModify() } } -void SwModify::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) -{ - NotifyClients( pOldValue, pNewValue ); -} - void SwModify::NotifyClients( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) { if ( IsInCache() || IsInSwFntCache() ) commit 3fc8c700e5964690b637847294a0b38ac4fbbb02 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 13:23:40 2015 +0100 inline trivial SwClient functions Change-Id: I1672844d0ad7f95d5c5add62703729588190d20f diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 421f61b..fd7785b 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -96,7 +96,7 @@ class SW_DLLPUBLIC SwClient : ::sw::WriterListener protected: // single argument ctors shall be explicit. - explicit SwClient(SwModify *pToRegisterIn); + inline explicit SwClient( SwModify* pToRegisterIn ); // write access to pRegisteredIn shall be granted only to the object itself (protected access) SwModify* GetRegisteredInNonConst() const { return pRegisteredIn; } @@ -105,7 +105,8 @@ public: SwClient() : pRegisteredIn(nullptr) {} virtual ~SwClient(); - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew); + virtual void Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) + { CheckRegistration( pOldValue, pNewValue ); } // in case an SwModify object is destroyed that itself is registered in another SwModify, // its SwClient objects can decide to get registered to the latter instead by calling this method @@ -114,7 +115,7 @@ public: // controlled access to Modify method // mba: this is still considered a hack and it should be fixed; the name makes grep-ing easier void ModifyNotification( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ) { this->Modify ( pOldValue, pNewValue ); } - void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); } + void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); } const SwModify* GetRegisteredIn() const { return pRegisteredIn; } SwModify* GetRegisteredIn() { return pRegisteredIn; } @@ -123,7 +124,7 @@ public: TYPEINFO(); // get information about attribute - virtual bool GetInfo( SfxPoolItem& ) const; + virtual bool GetInfo( SfxPoolItem& ) const { return true; } }; @@ -313,6 +314,12 @@ public: } }; +SwClient::SwClient( SwModify* pToRegisterIn ) + : pRegisteredIn( nullptr ) +{ + if(pToRegisterIn) + pToRegisterIn->Add(this); +} #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 58fe03e..350030c 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -26,12 +26,11 @@ TYPEINIT0( SwClient ); -SwClient::SwClient( SwModify* pToRegisterIn ) - : pRegisteredIn( nullptr ) +SwClient::~SwClient() { - if(pToRegisterIn) - // connect to SwModify - pToRegisterIn->Add(this); + OSL_ENSURE( !pRegisteredIn || pRegisteredIn->GetDepends(), "SwModify still known, but Client already disconnected!" ); + if( pRegisteredIn && pRegisteredIn->GetDepends() ) + pRegisteredIn->Remove( this ); } void SwClient::CheckRegistration( const SfxPoolItem* pOld, const SfxPoolItem* ) @@ -57,23 +56,6 @@ void SwClient::CheckRegistration( const SfxPoolItem* pOld, const SfxPoolItem* ) } } -void SwClient::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue ) -{ - CheckRegistration( pOldValue, pNewValue ); -} - -SwClient::~SwClient() -{ - OSL_ENSURE( !pRegisteredIn || pRegisteredIn->GetDepends(), "SwModify still known, but Client already disconnected!" ); - if( pRegisteredIn && pRegisteredIn->GetDepends() ) - // still connected - pRegisteredIn->Remove( this ); -} - -bool SwClient::GetInfo( SfxPoolItem& ) const -{ - return true; -} SwModify::SwModify() : SwClient(nullptr), pRoot(nullptr) commit e07c6a6fea726904b5669baa50fc8ea45b4328f8 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 12:59:46 2015 +0100 fix naming conventions while at it Change-Id: I2d2daa78869764ebf236444187d4dcdc508208be diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index c0b3ea2..421f61b 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -208,108 +208,108 @@ class SwClientIter : public sw::Ring<SwClientIter> friend SwClient* SwModify::Remove(SwClient *); ///< for pointer adjustments friend void SwModify::Add(SwClient *pDepend); ///< for pointer adjustments - const SwModify& rRoot; + const SwModify& m_rRoot; // the current object in an iteration - SwClient* pAct; + SwClient* 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* pDelNext; + SwClient* m_pPosition; // iterator can be limited to return only SwClient objects of a certain type - TypeId aSrchId; + TypeId m_aSearchType; - static SwClientIter* pClientIters; + static SW_DLLPUBLIC SwClientIter* our_pClientIters; public: SwClientIter( const SwModify& rModify ) - : rRoot(rModify) - , aSrchId(nullptr) + : m_rRoot(rModify) + , m_aSearchType(nullptr) { - MoveTo(pClientIters); - pClientIters = this; - pAct = pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); + MoveTo(our_pClientIters); + our_pClientIters = this; + m_pCurrent = m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()); } ~SwClientIter() { - assert(pClientIters); - if(pClientIters == this) - pClientIters = unique() ? nullptr : GetNextInRing(); + assert(our_pClientIters); + if(our_pClientIters == this) + our_pClientIters = unique() ? nullptr : GetNextInRing(); MoveTo(nullptr); } - const SwModify& GetModify() const { return rRoot; } + const SwModify& GetModify() const { return m_rRoot; } SwClient* operator++() { - if( pDelNext == pAct ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - return pAct = pDelNext; + if( m_pPosition == m_pCurrent ) + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pRight); + return m_pCurrent = m_pPosition; } SwClient* GoStart() { - if((pDelNext = const_cast<SwClient*>(rRoot.GetDepends()))) - while( pDelNext->m_pLeft ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - return pAct = pDelNext; + if((m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()))) + while( m_pPosition->m_pLeft ) + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pLeft); + return m_pCurrent = m_pPosition; } SwClient* GoEnd() { - if(!pDelNext) - pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); - if(pDelNext) - while( pDelNext->m_pRight ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - return pAct = pDelNext; + if(!m_pPosition) + m_pPosition = const_cast<SwClient*>(m_rRoot.GetDepends()); + if(m_pPosition) + while( m_pPosition->m_pRight ) + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pRight); + return m_pCurrent = m_pPosition; } // returns the current SwClient object; // in case this was already removed, the object marked down to become // the next current one is returned SwClient* operator()() const - { return pDelNext == pAct ? pAct : pDelNext; } + { return m_pPosition == m_pCurrent ? m_pCurrent : m_pPosition; } // return "true" if an object was removed from a client chain in iteration // adding objects to a client chain in iteration is forbidden // SwModify::Add() asserts this - bool IsChanged() const { return pDelNext != pAct; } + bool IsChanged() const { return m_pPosition != m_pCurrent; } SwClient* First( TypeId nType ) { - aSrchId = nType; + m_aSearchType = nType; GoStart(); - if(!pDelNext) + if(!m_pPosition) return nullptr; - pAct = nullptr; + m_pCurrent = nullptr; return Next(); } SwClient* Last( TypeId nType ) { - aSrchId = nType; + m_aSearchType = nType; GoEnd(); - if(!pDelNext) + if(!m_pPosition) return nullptr; - if( pDelNext->IsA( aSrchId ) ) - return pDelNext; + if( m_pPosition->IsA( m_aSearchType ) ) + return m_pPosition; return Previous(); } SwClient* Next() { - if( pDelNext == pAct ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - while(pDelNext && !pDelNext->IsA( aSrchId ) ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - return pAct = pDelNext; + if( m_pPosition == m_pCurrent ) + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pRight); + while(m_pPosition && !m_pPosition->IsA( m_aSearchType ) ) + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pRight); + return m_pCurrent = m_pPosition; } SwClient* Previous() { - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - while(pDelNext && !pDelNext->IsA( aSrchId ) ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - return pAct = pDelNext; + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pLeft); + while(m_pPosition && !m_pPosition->IsA( m_aSearchType ) ) + m_pPosition = static_cast<SwClient*>(m_pPosition->m_pLeft); + return m_pCurrent = m_pPosition; } }; diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index bb0a8dc..58fe03e 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -205,9 +205,9 @@ void SwModify::Add( SwClient* pDepend ) if(pDepend->pRegisteredIn != this ) { #if OSL_DEBUG_LEVEL > 0 - if(SwClientIter::pClientIters) + if(SwClientIter::our_pClientIters) { - for(auto& rIter : SwClientIter::pClientIters->GetRingContainer()) + for(auto& rIter : SwClientIter::our_pClientIters->GetRingContainer()) OSL_ENSURE( &rIter.GetModify() != pRoot, "Client added to active ClientIter" ); } #endif @@ -257,15 +257,15 @@ SwClient* SwModify::Remove( SwClient* pDepend ) pR->m_pLeft = pL; // update ClientIters - if(SwClientIter::pClientIters) + if(SwClientIter::our_pClientIters) { - for(auto& rIter : SwClientIter::pClientIters->GetRingContainer()) + for(auto& rIter : SwClientIter::our_pClientIters->GetRingContainer()) { - if( rIter.pAct == pDepend || rIter.pDelNext == pDepend ) + if( rIter.m_pCurrent == pDepend || rIter.m_pPosition == pDepend ) { // if object being removed is the current or next object in an // iterator, advance this iterator - rIter.pDelNext = static_cast<SwClient*>(pR); + rIter.m_pPosition = static_cast<SwClient*>(pR); } } } @@ -361,5 +361,5 @@ bool SwDepend::GetInfo( SfxPoolItem& rInfo ) const return pToTell ? pToTell->GetInfo( rInfo ) : true; } -SwClientIter* SwClientIter::pClientIters = nullptr; +SwClientIter* SwClientIter::our_pClientIters = nullptr; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit c2655a58527ec6b63af7c1191535d06ff71cee0c Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 12:36:12 2015 +0100 now inline SwClientIter, its small enough Change-Id: I2a66c4ee51cd7204300bc7fd9a6fcaf2246bf082 diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 64eafa8..c0b3ea2 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -221,15 +221,49 @@ class SwClientIter : public sw::Ring<SwClientIter> // iterator can be limited to return only SwClient objects of a certain type TypeId aSrchId; + static SwClientIter* pClientIters; + public: - SW_DLLPUBLIC SwClientIter( const SwModify& ); - SW_DLLPUBLIC ~SwClientIter(); + SwClientIter( const SwModify& rModify ) + : rRoot(rModify) + , aSrchId(nullptr) + { + MoveTo(pClientIters); + pClientIters = this; + pAct = pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); + } + ~SwClientIter() + { + assert(pClientIters); + if(pClientIters == this) + pClientIters = unique() ? nullptr : GetNextInRing(); + MoveTo(nullptr); + } const SwModify& GetModify() const { return rRoot; } - SwClient* operator++(); - SwClient* GoStart(); - SwClient* GoEnd(); + SwClient* operator++() + { + if( pDelNext == pAct ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + return pAct = pDelNext; + } + SwClient* GoStart() + { + if((pDelNext = const_cast<SwClient*>(rRoot.GetDepends()))) + while( pDelNext->m_pLeft ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + return pAct = pDelNext; + } + SwClient* GoEnd() + { + if(!pDelNext) + pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); + if(pDelNext) + while( pDelNext->m_pRight ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + return pAct = pDelNext; + } // returns the current SwClient object; // in case this was already removed, the object marked down to become @@ -242,10 +276,41 @@ public: // SwModify::Add() asserts this bool IsChanged() const { return pDelNext != pAct; } - SW_DLLPUBLIC SwClient* First( TypeId nType ); - SW_DLLPUBLIC SwClient* Next(); - SW_DLLPUBLIC SwClient* Last( TypeId nType ); - SW_DLLPUBLIC SwClient* Previous(); + SwClient* First( TypeId nType ) + { + aSrchId = nType; + GoStart(); + if(!pDelNext) + return nullptr; + pAct = nullptr; + return Next(); + } + SwClient* Last( TypeId nType ) + { + aSrchId = nType; + GoEnd(); + if(!pDelNext) + return nullptr; + if( pDelNext->IsA( aSrchId ) ) + return pDelNext; + return Previous(); + } + SwClient* Next() + { + if( pDelNext == pAct ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + while(pDelNext && !pDelNext->IsA( aSrchId ) ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + return pAct = pDelNext; + } + + SwClient* Previous() + { + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + while(pDelNext && !pDelNext->IsA( aSrchId ) ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + return pAct = pDelNext; + } }; #endif diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 8ca06300..bb0a8dc 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -23,7 +23,6 @@ #include <swcache.hxx> #include <swfntcch.hxx> -static SwClientIter* pClientIters = nullptr; TYPEINIT0( SwClient ); @@ -206,9 +205,9 @@ void SwModify::Add( SwClient* pDepend ) if(pDepend->pRegisteredIn != this ) { #if OSL_DEBUG_LEVEL > 0 - if(pClientIters) + if(SwClientIter::pClientIters) { - for(auto& rIter : pClientIters->GetRingContainer()) + for(auto& rIter : SwClientIter::pClientIters->GetRingContainer()) OSL_ENSURE( &rIter.GetModify() != pRoot, "Client added to active ClientIter" ); } #endif @@ -258,9 +257,9 @@ SwClient* SwModify::Remove( SwClient* pDepend ) pR->m_pLeft = pL; // update ClientIters - if(pClientIters) + if(SwClientIter::pClientIters) { - for(auto& rIter : pClientIters->GetRingContainer()) + for(auto& rIter : SwClientIter::pClientIters->GetRingContainer()) { if( rIter.pAct == pDepend || rIter.pDelNext == pDepend ) { @@ -362,84 +361,5 @@ bool SwDepend::GetInfo( SfxPoolItem& rInfo ) const return pToTell ? pToTell->GetInfo( rInfo ) : true; } -SwClientIter::SwClientIter( const SwModify& rModify ) - : rRoot(rModify) - , aSrchId(nullptr) -{ - MoveTo(pClientIters); - pClientIters = this; - pAct = pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); -} - -SwClientIter::~SwClientIter() -{ - assert(pClientIters); - if(pClientIters == this) - pClientIters = unique() ? nullptr : GetNextInRing(); - MoveTo(nullptr); -} - -SwClient* SwClientIter::operator++() -{ - if( pDelNext == pAct ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - return pAct = pDelNext; -} - -SwClient* SwClientIter::GoStart() -{ - if((pDelNext = const_cast<SwClient*>(rRoot.GetDepends()))) - while( pDelNext->m_pLeft ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - return pAct = pDelNext; -} - -SwClient* SwClientIter::GoEnd() -{ - if(!pDelNext) - pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); - if(pDelNext) - while( pDelNext->m_pRight ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - return pAct = pDelNext; -} - -SwClient* SwClientIter::First( TypeId nType ) -{ - aSrchId = nType; - GoStart(); - if(!pDelNext) - return nullptr; - pAct = nullptr; - return Next(); -} - -SwClient* SwClientIter::Last( TypeId nType ) -{ - aSrchId = nType; - GoEnd(); - if(!pDelNext) - return nullptr; - if( pDelNext->IsA( aSrchId ) ) - return pDelNext; - return Previous(); -} - -SwClient* SwClientIter::Next() -{ - if( pDelNext == pAct ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - while(pDelNext && !pDelNext->IsA( aSrchId ) ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - return pAct = pDelNext; -} - -SwClient* SwClientIter::Previous() -{ - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - while(pDelNext && !pDelNext->IsA( aSrchId ) ) - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - return pAct = pDelNext; -} - +SwClientIter* SwClientIter::pClientIters = nullptr; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 9378fc5d1fadb10e078bb852144f5cc8b99cc342 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 02:57:07 2015 +0100 use sw::Ring<> Change-Id: I1ad4425f557a52dec4e9b068995585b15f61466f diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 274bcf6..64eafa8 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -23,6 +23,7 @@ #include <tools/rtti.hxx> #include "swdllapi.h" #include <boost/noncopyable.hpp> +#include <ring.hxx> class SwModify; class SwClientIter; @@ -202,7 +203,7 @@ protected: virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ) SAL_OVERRIDE; }; -class SwClientIter +class SwClientIter : public sw::Ring<SwClientIter> { friend SwClient* SwModify::Remove(SwClient *); ///< for pointer adjustments friend void SwModify::Add(SwClient *pDepend); ///< for pointer adjustments @@ -217,11 +218,6 @@ class SwClientIter // this is necessary because iteration requires access to members of the current object SwClient* pDelNext; - // SwClientIter objects are tracked in linked list so that they can react - // when the current (pAct) or marked down (pDelNext) SwClient is removed - // from its SwModify - SwClientIter *pNxtIter; - // iterator can be limited to return only SwClient objects of a certain type TypeId aSrchId; diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 17aabca..8ca06300 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -206,11 +206,10 @@ void SwModify::Add( SwClient* pDepend ) if(pDepend->pRegisteredIn != this ) { #if OSL_DEBUG_LEVEL > 0 - SwClientIter* pTmp = pClientIters; - while( pTmp ) + if(pClientIters) { - OSL_ENSURE( &pTmp->GetModify() != pRoot, "Client added to active ClientIter" ); - pTmp = pTmp->pNxtIter; + for(auto& rIter : pClientIters->GetRingContainer()) + OSL_ENSURE( &rIter.GetModify() != pRoot, "Client added to active ClientIter" ); } #endif // deregister new client in case it is already registered elsewhere @@ -259,18 +258,18 @@ SwClient* SwModify::Remove( SwClient* pDepend ) pR->m_pLeft = pL; // update ClientIters - SwClientIter* pTmp = pClientIters; - while( pTmp ) + if(pClientIters) { - if( pTmp->pAct == pDepend || pTmp->pDelNext == pDepend ) + for(auto& rIter : pClientIters->GetRingContainer()) { - // if object being removed is the current or next object in an - // iterator, advance this iterator - pTmp->pDelNext = static_cast<SwClient*>(pR); + if( rIter.pAct == pDepend || rIter.pDelNext == pDepend ) + { + // if object being removed is the current or next object in an + // iterator, advance this iterator + rIter.pDelNext = static_cast<SwClient*>(pR); + } } - pTmp = pTmp->pNxtIter; } - pDepend->m_pLeft = nullptr; pDepend->m_pRight = nullptr; } @@ -365,32 +364,19 @@ bool SwDepend::GetInfo( SfxPoolItem& rInfo ) const SwClientIter::SwClientIter( const SwModify& rModify ) : rRoot(rModify) - , pNxtIter(nullptr) , aSrchId(nullptr) { - if( pClientIters ) - pNxtIter = pClientIters; + MoveTo(pClientIters); pClientIters = this; - pAct = pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); } SwClientIter::~SwClientIter() { assert(pClientIters); - // reorganize list of ClientIters - if( pClientIters == this ) - pClientIters = pNxtIter; - else - { - SwClientIter* pTmp = pClientIters; - while( pTmp->pNxtIter != this ) - { - assert(pTmp); - pTmp = pTmp->pNxtIter; - } - pTmp->pNxtIter = pNxtIter; - } + if(pClientIters == this) + pClientIters = unique() ? nullptr : GetNextInRing(); + MoveTo(nullptr); } SwClient* SwClientIter::operator++() commit 5a0d2a4e927ed0c13468febd814cd1d8cfc11112 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 01:51:42 2015 +0100 simplify SwClientIter dtor Change-Id: Ibf41f0c53b0454029601dd1cac479bdd82f50f0c diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 7ad963d..17aabca 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -377,22 +377,19 @@ SwClientIter::SwClientIter( const SwModify& rModify ) SwClientIter::~SwClientIter() { - if( pClientIters ) + assert(pClientIters); + // reorganize list of ClientIters + if( pClientIters == this ) + pClientIters = pNxtIter; + else { - // reorganize list of ClientIters - if( pClientIters == this ) - pClientIters = pNxtIter; - else + SwClientIter* pTmp = pClientIters; + while( pTmp->pNxtIter != this ) { - SwClientIter* pTmp = pClientIters; - while( pTmp->pNxtIter != this ) - if( nullptr == ( pTmp = pTmp->pNxtIter ) ) - { - OSL_ENSURE( this, "Lost my pointer" ); - return ; - } - pTmp->pNxtIter = pNxtIter; + assert(pTmp); + pTmp = pTmp->pNxtIter; } + pTmp->pNxtIter = pNxtIter; } } commit 5730b4b7b20421ed5fce33365b925d640e8e5f21 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 01:39:39 2015 +0100 simplify SwClientIter ctor Change-Id: I26771fb62cf55e5375ea23b260eb37bdfdade70a diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 0967291..7ad963d 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -369,18 +369,10 @@ SwClientIter::SwClientIter( const SwModify& rModify ) , aSrchId(nullptr) { if( pClientIters ) - { - // append to list of ClientIters - SwClientIter* pTmp = pClientIters; - while( pTmp->pNxtIter ) - pTmp = pTmp->pNxtIter; - pTmp->pNxtIter = this; - } - else - pClientIters = this; + pNxtIter = pClientIters; + pClientIters = this; - pAct = const_cast<SwClient*>(rRoot.GetDepends()); - pDelNext = pAct; + pAct = pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); } SwClientIter::~SwClientIter() commit 2559e0112ea4bbb1c5f0c1905a13557f99ffedf5 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 01:08:07 2015 +0100 Last() superficial check Change-Id: Ic0ded0288e322ac99f0500973c304db60e23c9de diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index d066f7f..0967291 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -413,7 +413,7 @@ SwClient* SwClientIter::operator++() SwClient* SwClientIter::GoStart() { - if(pDelNext = const_cast<SwClient*>(rRoot.GetDepends())) + if((pDelNext = const_cast<SwClient*>(rRoot.GetDepends()))) while( pDelNext->m_pLeft ) pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); return pAct = pDelNext; @@ -421,7 +421,9 @@ SwClient* SwClientIter::GoStart() SwClient* SwClientIter::GoEnd() { - if(pDelNext = const_cast<SwClient*>(rRoot.GetDepends())) + if(!pDelNext) + pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); + if(pDelNext) while( pDelNext->m_pRight ) pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); return pAct = pDelNext; @@ -443,7 +445,7 @@ SwClient* SwClientIter::Last( TypeId nType ) GoEnd(); if(!pDelNext) return nullptr; - if( pDelNext && pDelNext->IsA( aSrchId ) ) + if( pDelNext->IsA( aSrchId ) ) return pDelNext; return Previous(); } commit ed02fd49b92d0235e84346dcfbd6850ddbbd0d87 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 01:06:57 2015 +0100 GoStart() GoEnd() consistency Change-Id: I4386c9594db950a40ddbfd25fb5383d7ed4b877b diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 7286bb4..d066f7f 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -413,8 +413,7 @@ SwClient* SwClientIter::operator++() SwClient* SwClientIter::GoStart() { - pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); - if(pDelNext) + if(pDelNext = const_cast<SwClient*>(rRoot.GetDepends())) while( pDelNext->m_pLeft ) pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); return pAct = pDelNext; @@ -422,9 +421,7 @@ SwClient* SwClientIter::GoStart() SwClient* SwClientIter::GoEnd() { - if(!pDelNext) - pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); - if(pDelNext) + if(pDelNext = const_cast<SwClient*>(rRoot.GetDepends())) while( pDelNext->m_pRight ) pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); return pAct = pDelNext; commit b76943b02049b32e25dd82bc93c9d8d143245992 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 00:44:28 2015 +0100 simplify SwClient::Previous() more Change-Id: If0e80981f248a3a388934025a90502290d5f3c47 diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 3aa874d..7286bb4 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -444,6 +444,8 @@ SwClient* SwClientIter::Last( TypeId nType ) { aSrchId = nType; GoEnd(); + if(!pDelNext) + return nullptr; if( pDelNext && pDelNext->IsA( aSrchId ) ) return pDelNext; return Previous(); @@ -460,12 +462,9 @@ SwClient* SwClientIter::Next() SwClient* SwClientIter::Previous() { - while(pDelNext) - { + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + while(pDelNext && !pDelNext->IsA( aSrchId ) ) pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - if( pDelNext && pDelNext->IsA( aSrchId ) ) - break; - } return pAct = pDelNext; } commit daddc79775960775bdc52d9bbd42e0026ce79aae Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 00:34:59 2015 +0100 simplify SwClient::Next() more Change-Id: I7441c17c506f37d2de3658c083179a652f89fcb6 diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 836e8cc..3aa874d 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -453,12 +453,8 @@ SwClient* SwClientIter::Next() { if( pDelNext == pAct ) pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - while(pDelNext) - { - if( pDelNext->IsA( aSrchId ) ) - break; + while(pDelNext && !pDelNext->IsA( aSrchId ) ) pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - } return pAct = pDelNext; } commit d51ba441ee04300c35e7597203b5a327beaf756b Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 00:28:28 2015 +0100 simplify SwClient::Last() with Previous() Change-Id: I2cf788b2a4ff9b4073a15f121b7b76451f6ad825 diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 49815da..836e8cc 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -444,13 +444,9 @@ SwClient* SwClientIter::Last( TypeId nType ) { aSrchId = nType; GoEnd(); - while( pDelNext ) - { - if( pDelNext->IsA( aSrchId ) ) - break; - pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); - } - return pAct = pDelNext; + if( pDelNext && pDelNext->IsA( aSrchId ) ) + return pDelNext; + return Previous(); } SwClient* SwClientIter::Next() commit 1183ef266baea156bade07cc316a4ff27ee1967e Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Fri Mar 13 00:18:58 2015 +0100 simplify SwClient::Previous() Change-Id: Ic120c440ac88c0599180af5aac56ad6d8c9bd974 diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 0dccf1f..49815da 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -468,17 +468,13 @@ SwClient* SwClientIter::Next() SwClient* SwClientIter::Previous() { - do { - if( pDelNext == pAct ) - pAct = static_cast<SwClient*>(pAct->m_pLeft); - else - pAct = static_cast<SwClient*>(pDelNext->m_pLeft); - pDelNext = pAct; - - if( pAct && pAct->IsA( aSrchId ) ) + while(pDelNext) + { + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + if( pDelNext && pDelNext->IsA( aSrchId ) ) break; - } while( pAct ); - return pAct; + } + return pAct = pDelNext; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 4022e29a1aff7f2c8d3cdea860f3a9ab3aa03a03 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 23:58:18 2015 +0100 simplify SwClient::First() with Next() Change-Id: If66ab27cbfe47f1cbeb0ed6a340459a8911af65a diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index b84222e..0dccf1f 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -434,13 +434,10 @@ SwClient* SwClientIter::First( TypeId nType ) { aSrchId = nType; GoStart(); - while( pDelNext ) - { - if( pDelNext->IsA( aSrchId ) ) - break; - pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); - } - return pAct = pDelNext; + if(!pDelNext) + return nullptr; + pAct = nullptr; + return Next(); } SwClient* SwClientIter::Last( TypeId nType ) commit 43d870a01d3b0c0fe956114669f6146d2b20447b Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 23:40:04 2015 +0100 simplify SwClient::Next() Change-Id: I543786f6bb325ba531bf8600ca5b9717efd4535c diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index c5de756..b84222e 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -458,19 +458,15 @@ SwClient* SwClientIter::Last( TypeId nType ) SwClient* SwClientIter::Next() { - do { - if( pDelNext == pAct ) - { - pAct = static_cast<SwClient*>(pAct->m_pRight); - pDelNext = pAct; - } - else - pAct = pDelNext; - - if( pAct && pAct->IsA( aSrchId ) ) + if( pDelNext == pAct ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + while(pDelNext) + { + if( pDelNext->IsA( aSrchId ) ) break; - } while( pAct ); - return pAct; + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + } + return pAct = pDelNext; } SwClient* SwClientIter::Previous() commit 9a74f77cb5e275bc7af876538fcf3f1d05f76567 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 23:07:23 2015 +0100 simplify SwClient::Last() Change-Id: I16639d345fef0fa578d30e43d6283e54bbd52b5b diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index ac3926d..c5de756 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -447,18 +447,13 @@ SwClient* SwClientIter::Last( TypeId nType ) { aSrchId = nType; GoEnd(); - if( pAct ) - do { - if( pAct->IsA( aSrchId ) ) - break; - - if( pDelNext == pAct ) - pAct = static_cast<SwClient*>(pAct->m_pLeft); - else - pAct = static_cast<SwClient*>(pDelNext->m_pLeft); - pDelNext = pAct; - } while( pAct ); - return pAct; + while( pDelNext ) + { + if( pDelNext->IsA( aSrchId ) ) + break; + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + } + return pAct = pDelNext; } SwClient* SwClientIter::Next() commit f811ac1a1940bb58808803d29b77fdc3218568ee Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 22:59:25 2015 +0100 simplify SwClient::First() Change-Id: I6c0f5214bbdc34abb9d94795f4f60b58c178a368 diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 6e775b8..ac3926d 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -434,20 +434,13 @@ SwClient* SwClientIter::First( TypeId nType ) { aSrchId = nType; GoStart(); - if( pAct ) - do { - if( pAct->IsA( aSrchId ) ) - break; - - if( pDelNext == pAct ) - { - pAct = static_cast<SwClient*>(pAct->m_pRight); - pDelNext = pAct; - } - else - pAct = pDelNext; - } while( pAct ); - return pAct; + while( pDelNext ) + { + if( pDelNext->IsA( aSrchId ) ) + break; + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + } + return pAct = pDelNext; } SwClient* SwClientIter::Last( TypeId nType ) commit f4ebba6af836c55fefcec44be590d8411622f7c1 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 22:49:02 2015 +0100 simplify SwClient::GoEnd() Change-Id: I6c2d55c8b748946543ddce72130f900b738418ef diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 835a2d9..6e775b8 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -422,16 +422,12 @@ SwClient* SwClientIter::GoStart() SwClient* SwClientIter::GoEnd() { - pAct = pDelNext; - if( !pAct ) - pAct = const_cast<SwClient*>(rRoot.GetDepends()); - if( pAct ) - { - while( pAct->m_pRight ) - pAct = static_cast<SwClient*>(pAct->m_pRight); - } - pDelNext = pAct; - return pAct; + if(!pDelNext) + pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); + if(pDelNext) + while( pDelNext->m_pRight ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + return pAct = pDelNext; } SwClient* SwClientIter::First( TypeId nType ) commit 81618ec397128e4853c9aa6ce4fcd850ff11e876 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 22:39:06 2015 +0100 simplify SwClient::GoStart() Change-Id: Ic1916f86f1a3797d37a6102aa32ca7d2bd92f78e diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index b3cd51b..835a2d9 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -413,14 +413,11 @@ SwClient* SwClientIter::operator++() SwClient* SwClientIter::GoStart() { - pAct = const_cast<SwClient*>(rRoot.GetDepends()); - if( pAct ) - { - while( pAct->m_pLeft ) - pAct = static_cast<SwClient*>(pAct->m_pLeft); - } - pDelNext = pAct; - return pAct; + pDelNext = const_cast<SwClient*>(rRoot.GetDepends()); + if(pDelNext) + while( pDelNext->m_pLeft ) + pDelNext = static_cast<SwClient*>(pDelNext->m_pLeft); + return pAct = pDelNext; } SwClient* SwClientIter::GoEnd() commit 56a335c259db8aea74452bd7a88ac37c6e5635b4 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Thu Mar 12 22:29:12 2015 +0100 simplify SwClient::operator++() Change-Id: I17bdfb4cec60a4f9b18b7df3ba4c131771ba0f08 diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index 89281e3..b3cd51b 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -407,13 +407,8 @@ SwClientIter::~SwClientIter() SwClient* SwClientIter::operator++() { if( pDelNext == pAct ) - { - pAct = static_cast<SwClient*>(pAct->m_pRight); - pDelNext = pAct; - } - else - pAct = pDelNext; - return pAct; + pDelNext = static_cast<SwClient*>(pDelNext->m_pRight); + return pAct = pDelNext; } SwClient* SwClientIter::GoStart() commit 23fd991fda81668b3998b21b0131dda77965e405 Author: Bjoern Michaelsen <bjoern.michael...@canonical.com> Date: Tue Mar 10 00:57:49 2015 +0100 separate the sane from the less sane in SwClient Change-Id: Ie641019e0de26fc73ffb51b825fef2cc072adc6e diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx index 68fa315..274bcf6 100644 --- a/sw/inc/calbck.hxx +++ b/sw/inc/calbck.hxx @@ -56,23 +56,43 @@ class SfxHint; code gets polluted by pointer casts (see switerator.hxx). */ +class SwModify; +class SwClient; +class SwClientIter; +namespace sw +{ + /// refactoring out the some of the more sane SwClient functionality + class SW_DLLPUBLIC WriterListener : ::boost::noncopyable + { + friend class ::SwModify; + friend class ::SwClient; + friend class ::SwClientIter; + private: + WriterListener* m_pLeft; + WriterListener* m_pRight; ///< double-linked list of other clients + protected: + WriterListener() + : m_pLeft(nullptr), m_pRight(nullptr) + {} + virtual ~WriterListener() {}; + // callbacks received from SwModify (friend class - so these methods can be private) + // should be called only from SwModify the client is registered in + // mba: IMHO these methods should be pure virtual + virtual void Modify(const SfxPoolItem*, const SfxPoolItem*) {}; + virtual void SwClientNotify( const SwModify&, const SfxHint&) {}; + public: + bool IsLast() const { return !m_pLeft && !m_pRight; } + }; +} // SwClient - -class SW_DLLPUBLIC SwClient : ::boost::noncopyable +class SW_DLLPUBLIC SwClient : ::sw::WriterListener { // avoids making the details of the linked list and the callback method public friend class SwModify; friend class SwClientIter; - SwClient *pLeft, *pRight; ///< double-linked list of other clients SwModify *pRegisteredIn; ///< event source - // callbacks received from SwModify (friend class - so these methods can be private) - // should be called only from SwModify the client is registered in - // mba: IMHO these methods should be pure virtual - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew); - virtual void SwClientNotify( const SwModify& rModify, const SfxHint& rHint ); - protected: // single argument ctors shall be explicit. explicit SwClient(SwModify *pToRegisterIn); @@ -82,8 +102,9 @@ protected: public: - inline SwClient(); + SwClient() : pRegisteredIn(nullptr) {} virtual ~SwClient(); + virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew); // in case an SwModify object is destroyed that itself is registered in another SwModify, // its SwClient objects can decide to get registered to the latter instead by calling this method @@ -91,12 +112,11 @@ public: // controlled access to Modify method // mba: this is still considered a hack and it should be fixed; the name makes grep-ing easier - void ModifyNotification( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ) { Modify ( pOldValue, pNewValue ); } + void ModifyNotification( const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue ) { this->Modify ( pOldValue, pNewValue ); } void SwClientNotifyCall( const SwModify& rModify, const SfxHint& rHint ) { SwClientNotify( rModify, rHint ); } const SwModify* GetRegisteredIn() const { return pRegisteredIn; } SwModify* GetRegisteredIn() { return pRegisteredIn; } - bool IsLast() const { return !pLeft && !pRight; } // needed for class SwClientIter TYPEINFO(); @@ -105,16 +125,13 @@ public: virtual bool GetInfo( SfxPoolItem& ) const; }; -inline SwClient::SwClient() : - pLeft(0), pRight(0), pRegisteredIn(0) -{} // SwModify // class has a doubly linked list for dependencies class SW_DLLPUBLIC SwModify: public SwClient { - SwClient* pRoot; // the start of the linked list of clients + sw::WriterListener* pRoot; // the start of the linked list of clients bool bModifyLocked : 1; // don't broadcast changes now bool bLockClientList : 1; // may be set when this instance notifies its clients bool bInDocDTOR : 1; // workaround for problems when a lot of objects are destroyed @@ -144,7 +161,7 @@ public: void Add(SwClient *pDepend); SwClient* Remove(SwClient *pDepend); - const SwClient* GetDepends() const { return pRoot; } + const SwClient* GetDepends() const { return static_cast<SwClient*>(pRoot); } // get information about attribute virtual bool GetInfo( SfxPoolItem& ) const SAL_OVERRIDE; diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx index a06bba2..89281e3 100644 --- a/sw/source/core/attr/calbck.cxx +++ b/sw/source/core/attr/calbck.cxx @@ -28,7 +28,7 @@ static SwClientIter* pClientIters = nullptr; TYPEINIT0( SwClient ); SwClient::SwClient( SwModify* pToRegisterIn ) - : pLeft( nullptr ), pRight( nullptr ), pRegisteredIn( nullptr ) + : pRegisteredIn( nullptr ) { if(pToRegisterIn) // connect to SwModify @@ -63,10 +63,6 @@ void SwClient::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValu CheckRegistration( pOldValue, pNewValue ); } -void SwClient::SwClientNotify( const SwModify&, const SfxHint& ) -{ -} - SwClient::~SwClient() { OSL_ENSURE( !pRegisteredIn || pRegisteredIn->GetDepends(), "SwModify still known, but Client already disconnected!" ); @@ -135,7 +131,7 @@ SwModify::~SwModify() // remove all clients that have not done themselves // mba: possibly a hotfix for forgotten base class calls?! while( pRoot ) - pRoot->CheckRegistration( &aDyObject, &aDyObject ); + static_cast<SwClient*>(pRoot)->CheckRegistration( &aDyObject, &aDyObject ); } } } @@ -225,17 +221,17 @@ void SwModify::Add( SwClient* pDepend ) { // first client added pRoot = pDepend; - pRoot->pLeft = nullptr; - pRoot->pRight = nullptr; + pRoot->m_pLeft = nullptr; + pRoot->m_pRight = nullptr; } else { // append client - pDepend->pRight = pRoot->pRight; - pRoot->pRight = pDepend; - pDepend->pLeft = pRoot; - if( pDepend->pRight ) - pDepend->pRight->pLeft = pDepend; + pDepend->m_pRight = pRoot->m_pRight; + pRoot->m_pRight = pDepend; + pDepend->m_pLeft = pRoot; + if( pDepend->m_pRight ) + pDepend->m_pRight->m_pLeft = pDepend; } // connect client to me @@ -252,15 +248,15 @@ SwClient* SwModify::Remove( SwClient* pDepend ) { // SwClient is my listener // remove it from my list - SwClient* pR = pDepend->pRight; - SwClient* pL = pDepend->pLeft; + ::sw::WriterListener* pR = pDepend->m_pRight; + ::sw::WriterListener* pL = pDepend->m_pLeft; if( pRoot == pDepend ) pRoot = pL ? pL : pR; if( pL ) - pL->pRight = pR; + pL->m_pRight = pR; if( pR ) - pR->pLeft = pL; + pR->m_pLeft = pL; // update ClientIters SwClientIter* pTmp = pClientIters; @@ -270,13 +266,13 @@ SwClient* SwModify::Remove( SwClient* pDepend ) { // if object being removed is the current or next object in an // iterator, advance this iterator - pTmp->pDelNext = pR; + pTmp->pDelNext = static_cast<SwClient*>(pR); } pTmp = pTmp->pNxtIter; } - pDepend->pLeft = nullptr; - pDepend->pRight = nullptr; + pDepend->m_pLeft = nullptr; + pDepend->m_pRight = nullptr; } else { @@ -412,7 +408,7 @@ SwClient* SwClientIter::operator++() { if( pDelNext == pAct ) { - pAct = pAct->pRight; + pAct = static_cast<SwClient*>(pAct->m_pRight); pDelNext = pAct; } else @@ -425,8 +421,8 @@ SwClient* SwClientIter::GoStart() pAct = const_cast<SwClient*>(rRoot.GetDepends()); if( pAct ) { - while( pAct->pLeft ) - pAct = pAct->pLeft; + while( pAct->m_pLeft ) + pAct = static_cast<SwClient*>(pAct->m_pLeft); } pDelNext = pAct; return pAct; @@ -439,8 +435,8 @@ SwClient* SwClientIter::GoEnd() pAct = const_cast<SwClient*>(rRoot.GetDepends()); if( pAct ) { - while( pAct->pRight ) - pAct = pAct->pRight; + while( pAct->m_pRight ) + pAct = static_cast<SwClient*>(pAct->m_pRight); } pDelNext = pAct; return pAct; @@ -457,7 +453,7 @@ SwClient* SwClientIter::First( TypeId nType ) if( pDelNext == pAct ) { - pAct = pAct->pRight; + pAct = static_cast<SwClient*>(pAct->m_pRight); pDelNext = pAct; } else @@ -476,9 +472,9 @@ SwClient* SwClientIter::Last( TypeId nType ) break; if( pDelNext == pAct ) - pAct = pAct->pLeft; + pAct = static_cast<SwClient*>(pAct->m_pLeft); else - pAct = pDelNext->pLeft; + pAct = static_cast<SwClient*>(pDelNext->m_pLeft); pDelNext = pAct; } while( pAct ); return pAct; @@ -489,7 +485,7 @@ SwClient* SwClientIter::Next() do { if( pDelNext == pAct ) { - pAct = pAct->pRight; + pAct = static_cast<SwClient*>(pAct->m_pRight); pDelNext = pAct; } else @@ -505,9 +501,9 @@ SwClient* SwClientIter::Previous() { do { if( pDelNext == pAct ) - pAct = pAct->pLeft; + pAct = static_cast<SwClient*>(pAct->m_pLeft); else - pAct = pDelNext->pLeft; + pAct = static_cast<SwClient*>(pDelNext->m_pLeft); pDelNext = pAct; if( pAct && pAct->IsA( aSrchId ) ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits