/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_TOOLS_WEAKBASE_H #define INCLUDED_TOOLS_WEAKBASE_H #include #include #include /** the template classes in this header are helper to implement weak references to implementation objects that are not refcounted. THIS IS NOT THREADSAFE Use this only to have 'safe' pointers to implementation objects that you don't own but that you reference with a pointer. Example: class ImplClass : public tools::WeakBase< ImplClass > { ~ImplClass() { clearWeek(); } // not needed but safer, see method description ... }; class UserClass { tools::WeakReference< ImplClass > mxWeakRef; UserClass( ImplClass* pObject ) : mxWeakRef( pObject ) {} DoSomething() { if( mxWeakRef.is() ) mxWeakRef->DoSomethingMore(); } }; */ namespace tools { class WeakBase; /** private connection helper, do not use directly */ struct WeakConnection { sal_Int32 mnRefCount; WeakBase* mpReference; WeakConnection() : mnRefCount( 0 ), mpReference( nullptr ) {}; WeakConnection( WeakBase* pReference ) : mnRefCount( 0 ), mpReference( pReference ) {}; void acquire() { mnRefCount++; } void release() { mnRefCount--; if( mnRefCount == 0 ) delete this; } }; /** template implementation to hold a weak reference to an instance of type reference_type */ template class SAL_WARN_UNUSED WeakReference { public: /** constructs an empty reference */ inline WeakReference(); /** constructs a reference with a pointer to a class derived from WeakBase */ inline WeakReference( reference_type* pReference ); /** constructs a reference from another reference */ inline WeakReference( const WeakReference< reference_type >& rWeakRef ); /** move a reference from another reference */ inline WeakReference( WeakReference< reference_type >&& rWeakRef ); /** returns true if the reference object is not null and still alive */ inline bool is() const; /** returns true if the reference object is not null and still alive */ operator bool() const { return is(); } /** returns the pointer to the reference object or null */ inline reference_type * get() const; /** sets this reference to the given object or null */ inline void reset( reference_type* pReference ); /** resets this reference to null */ inline void reset(); /** returns the pointer to the reference object or null */ inline reference_type * operator->() const; /** returns a ref to the reference object */ inline reference_type& operator*() const; /** returns true if this instance references pReferenceObject */ inline bool operator== (const reference_type * pReferenceObject) const; /** returns true if this instance and the given weakref reference the same object */ inline bool operator== (const WeakReference & handle) const; /** only needed for using this class with stl containers */ inline bool operator!= (const WeakReference & handle) const; /** only needed for using this class with stl containers */ inline bool operator< (const WeakReference & handle) const; /** only needed for using this class with stl containers */ inline bool operator> (const WeakReference & handle) const; /** the assignment operator */ inline WeakReference& operator= (const WeakReference & handle); /** the move assignment operator */ inline WeakReference& operator= (WeakReference && handle); private: rtl::Reference mpWeakConnection; }; /** derive your implementation classes from this class if you want them to support weak references */ class TOOLS_DLLPUBLIC WeakBase { template friend class WeakReference; public: WeakBase() {} virtual ~WeakBase(); /** clears the reference pointer in all living weak references for this instance. Further created weak references will also be invalid. You should call this method in the d'tor of your derived classes for an early invalidate of all living weak references while your object is already inside it d'tor. */ inline void clearWeak(); private: inline WeakConnection* getWeakConnection(); rtl::Reference mpWeakConnection; }; } #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ on: https://gerrit.libreoffice.org/82744 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> readme not a sufficient indicator 2019-11-04T15:44:54+00:00 Caolán McNamara caolanm@redhat.com 2019-11-04T10:04:25+00:00 57aa9ea3a6d178fcea016fadb005dfbcc2ca2e8d Change-Id: Idd5cd004b873280e202b16c182356977045bdab4 Reviewed-on: https://gerrit.libreoffice.org/81993 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Change-Id: Idd5cd004b873280e202b16c182356977045bdab4
Reviewed-on: https://gerrit.libreoffice.org/81993
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Toolbar: Added usage of ImageControl as toolbar control 2019-11-04T00:20:00+00:00 Serge Krot Serge.Krot@cib.de 2019-10-18T15:40:11+00:00 2187cff2d452e20aa1fdfd5d8aa7473242cd1eb6 Reviewed-on: https://gerrit.libreoffice.org/81064 Reviewed-by: Serge Krot (CIB) <Serge.Krot@cib.de> Tested-by: Serge Krot (CIB) <Serge.Krot@cib.de> (cherry picked from commit 48f945a3be16ee0eba0c526e51280dc8deafc316) Change-Id: I2536a505650b6e4c98e79f749c3b237518cc995d Reviewed-on: https://gerrit.libreoffice.org/81872 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Reviewed-on: https://gerrit.libreoffice.org/81064
Reviewed-by: Serge Krot (CIB) <Serge.Krot@cib.de>
Tested-by: Serge Krot (CIB) <Serge.Krot@cib.de>
(cherry picked from commit 48f945a3be16ee0eba0c526e51280dc8deafc316)

Change-Id: I2536a505650b6e4c98e79f749c3b237518cc995d
Reviewed-on: https://gerrit.libreoffice.org/81872
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>