android: Update app-specific/MIME type icons
[LibreOffice.git] / include / comphelper / compbase.hxx
blob280d3d26b554755910429d8ef14fc2e3b7a288fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #pragma once
12 #include <sal/config.h>
14 #include <comphelper/comphelperdllapi.h>
15 #include <comphelper/interfacecontainer4.hxx>
16 #include <comphelper/unoimplbase.hxx>
17 #include <cppuhelper/weak.hxx>
18 #include <cppuhelper/queryinterface.hxx>
19 #include <cppuhelper/implbase.hxx>
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/lang/XTypeProvider.hpp>
22 #include <mutex>
24 namespace comphelper
26 /**
27 Serves two purposes
28 (1) extracts code that doesn't need to be templated
29 (2) helps to handle the custom where we have conflicting interfaces
30 e.g. multiple UNO interfaces that extend css::lang::XComponent
32 class COMPHELPER_DLLPUBLIC WeakComponentImplHelperBase : public virtual comphelper::UnoImplBase,
33 public cppu::OWeakObject,
34 public css::lang::XComponent
36 public:
37 virtual ~WeakComponentImplHelperBase() override;
39 // css::lang::XComponent
40 virtual void SAL_CALL dispose() override;
41 virtual void SAL_CALL
42 addEventListener(css::uno::Reference<css::lang::XEventListener> const& rxListener) override;
43 virtual void SAL_CALL
44 removeEventListener(css::uno::Reference<css::lang::XEventListener> const& rxListener) override;
46 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override;
48 /**
49 Called by dispose for subclasses to do dispose() work.
50 The mutex is held when called, and subclasses can unlock() the guard if necessary.
52 virtual void disposing(std::unique_lock<std::mutex>&);
54 protected:
55 void throwIfDisposed(std::unique_lock<std::mutex>&)
57 if (m_bDisposed)
58 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this));
60 comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> maEventListeners;
63 template <typename... Ifc>
64 class SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper : public WeakComponentImplHelperBase,
65 public css::lang::XTypeProvider,
66 public Ifc...
68 public:
69 virtual void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); }
71 virtual void SAL_CALL release() noexcept override { OWeakObject::release(); }
73 // css::lang::XComponent
74 virtual void SAL_CALL dispose() noexcept final override
76 WeakComponentImplHelperBase::dispose();
78 virtual void SAL_CALL addEventListener(
79 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
81 WeakComponentImplHelperBase::addEventListener(rxListener);
83 virtual void SAL_CALL removeEventListener(
84 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
86 WeakComponentImplHelperBase::removeEventListener(rxListener);
89 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override
91 return WeakComponentImplHelper_query(rType, class_data_get(), this);
94 // css::lang::XTypeProvider
95 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
97 static const css::uno::Sequence<css::uno::Type> aTypeList{
98 cppu::UnoType<css::uno::XWeak>::get(), cppu::UnoType<css::lang::XComponent>::get(),
99 cppu::UnoType<css::lang::XTypeProvider>::get(), cppu::UnoType<Ifc>::get()...
101 return aTypeList;
103 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
105 return css::uno::Sequence<sal_Int8>();
108 private:
109 static cppu::class_data* class_data_get()
111 return cppu::detail::ImplClassData<WeakComponentImplHelper, Ifc...>{}();
115 /** WeakComponentImplHelper
117 COMPHELPER_DLLPUBLIC css::uno::Any
118 WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd,
119 WeakComponentImplHelperBase* pBase);
121 } // namespace comphelper
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */