From fa26db1c053a8510ada15fcbaa7e36ae0f6920a5 Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Mon, 27 Jan 2020 23:07:02 +0100 Subject: SwAutoCompleteClient: SwClient no more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - also: lets at least use atomic<> in debug code, when not caring about mutexes Change-Id: I0a32caea46a559607ff973a6f4b8e45f955e4015 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87564 Tested-by: Jenkins Reviewed-by: Björn Michaelsen --- sw/source/core/doc/acmplwrd.cxx | 100 ++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 51 deletions(-) (limited to 'sw') diff --git a/sw/source/core/doc/acmplwrd.cxx b/sw/source/core/doc/acmplwrd.cxx index 619faef05aa4..fc911a1993cc 100644 --- a/sw/source/core/doc/acmplwrd.cxx +++ b/sw/source/core/doc/acmplwrd.cxx @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -35,14 +35,12 @@ #include #include +#include -class SwAutoCompleteClient : public SwClient +class SwAutoCompleteClient final: public SvtListener { SwAutoCompleteWord* m_pAutoCompleteWord; SwDoc* m_pDoc; -#if OSL_DEBUG_LEVEL > 0 - static sal_uLong s_nSwAutoCompleteClientCount; -#endif public: SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc); SwAutoCompleteClient(const SwAutoCompleteClient& rClient); @@ -51,13 +49,44 @@ public: SwAutoCompleteClient& operator=(const SwAutoCompleteClient& rClient); const SwDoc& GetDoc() const {return *m_pDoc;} + virtual void Notify(const SfxHint&) override; #if OSL_DEBUG_LEVEL > 0 - static sal_uLong GetElementCount() {return s_nSwAutoCompleteClientCount;} + static sal_uInt32 GetElementCount() {return s_nSwAutoCompleteClientCount.load();} +private: + static std::atomic s_nSwAutoCompleteClientCount; #endif -protected: - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override; }; + +SwAutoCompleteClient::SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc) + : m_pAutoCompleteWord(&rToTell) + , m_pDoc(&rSwDoc) +{ + StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); +#if OSL_DEBUG_LEVEL > 0 + ++s_nSwAutoCompleteClientCount; +#endif +} + +SwAutoCompleteClient::SwAutoCompleteClient(const SwAutoCompleteClient& rClient) + : SvtListener() + , m_pAutoCompleteWord(rClient.m_pAutoCompleteWord) + , m_pDoc(rClient.m_pDoc) +{ + StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); +#if OSL_DEBUG_LEVEL > 0 + ++s_nSwAutoCompleteClientCount; +#endif +} + +SwAutoCompleteClient::~SwAutoCompleteClient() +{ +#if OSL_DEBUG_LEVEL > 0 + --s_nSwAutoCompleteClientCount; +#endif + (void) this; +} + typedef std::vector SwAutoCompleteClientVector; class SwAutoCompleteWord_Impl @@ -72,6 +101,7 @@ public: }; typedef std::vector SwDocPtrVector; + class SwAutoCompleteString : public editeng::IAutoCompleteString { @@ -90,59 +120,22 @@ class SwAutoCompleteString static sal_uLong GetElementCount() {return s_nSwAutoCompleteStringCount;} #endif }; -#if OSL_DEBUG_LEVEL > 0 - sal_uLong SwAutoCompleteClient::s_nSwAutoCompleteClientCount = 0; - sal_uLong SwAutoCompleteString::s_nSwAutoCompleteStringCount = 0; -#endif - -SwAutoCompleteClient::SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc) : - m_pAutoCompleteWord(&rToTell), - m_pDoc(&rSwDoc) -{ - m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this); -#if OSL_DEBUG_LEVEL > 0 - ++s_nSwAutoCompleteClientCount; -#endif -} - -SwAutoCompleteClient::SwAutoCompleteClient(const SwAutoCompleteClient& rClient) : - SwClient(), - m_pAutoCompleteWord(rClient.m_pAutoCompleteWord), - m_pDoc(rClient.m_pDoc) -{ - m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this); -#if OSL_DEBUG_LEVEL > 0 - ++s_nSwAutoCompleteClientCount; -#endif -} - -SwAutoCompleteClient::~SwAutoCompleteClient() -{ -#if OSL_DEBUG_LEVEL > 0 - --s_nSwAutoCompleteClientCount; -#else - (void) this; -#endif -} SwAutoCompleteClient& SwAutoCompleteClient::operator=(const SwAutoCompleteClient& rClient) { m_pAutoCompleteWord = rClient.m_pAutoCompleteWord; m_pDoc = rClient.m_pDoc; - StartListeningToSameModifyAs(rClient); + StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); return *this; } -void SwAutoCompleteClient::Modify( const SfxPoolItem* pOld, const SfxPoolItem *) +void SwAutoCompleteClient::Notify(const SfxHint& rHint) { - switch( pOld ? pOld->Which() : 0 ) + if(rHint.GetId() == SfxHintId::Dying) { - case RES_REMOVE_UNO_OBJECT: - case RES_OBJECTDYING: - if( static_cast(GetRegisteredIn()) == static_cast(pOld)->pObject ) - EndListeningAll(); + EndListeningAll(); m_pAutoCompleteWord->DocumentDying(*m_pDoc); - break; + m_pDoc = nullptr; } } @@ -213,7 +206,7 @@ SwAutoCompleteWord::~SwAutoCompleteWord() m_WordList.DeleteAndDestroyAll(); // so the assertion below works #if OSL_DEBUG_LEVEL > 0 sal_uLong nStrings = SwAutoCompleteString::GetElementCount(); - sal_uLong nClients = SwAutoCompleteClient::GetElementCount(); + sal_uInt32 nClients = SwAutoCompleteClient::GetElementCount(); OSL_ENSURE(!nStrings && !nClients, "AutoComplete: clients or string count mismatch"); #endif } @@ -401,4 +394,9 @@ void SwAutoCompleteWord::DocumentDying(const SwDoc& rDoc) } } +#if OSL_DEBUG_LEVEL > 0 +std::atomic SwAutoCompleteClient::s_nSwAutoCompleteClientCount = 0; +sal_uLong SwAutoCompleteString::s_nSwAutoCompleteStringCount = 0; +#endif + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit