LibreOffice Module comphelper (master) 1
compbase.hxx
Go to the documentation of this file.
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.
4 *
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 */
9
10#pragma once
11
12#include <sal/config.h>
13
16#include <cppuhelper/weak.hxx>
19#include <com/sun/star/lang/XComponent.hpp>
20#include <com/sun/star/lang/XTypeProvider.hpp>
21#include <mutex>
22
23namespace comphelper
24{
32 public css::lang::XComponent
33{
34public:
35 virtual ~WeakComponentImplHelperBase() override;
36
37 // css::lang::XComponent
38 virtual void SAL_CALL dispose() override;
39 virtual void SAL_CALL
40 addEventListener(css::uno::Reference<css::lang::XEventListener> const& rxListener) override;
41 virtual void SAL_CALL
42 removeEventListener(css::uno::Reference<css::lang::XEventListener> const& rxListener) override;
43
44 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override;
45
50 virtual void disposing(std::unique_lock<std::mutex>&);
51
52protected:
55 bool m_bDisposed = false;
56};
57
58template <typename... Ifc>
59class SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper : public WeakComponentImplHelperBase,
60 public css::lang::XTypeProvider,
61 public Ifc...
62{
63public:
64 virtual void SAL_CALL acquire() noexcept final override { OWeakObject::acquire(); }
65
66 virtual void SAL_CALL release() noexcept final override { OWeakObject::release(); }
67
68 // css::lang::XComponent
69 virtual void SAL_CALL dispose() noexcept final override
70 {
72 }
73 virtual void SAL_CALL addEventListener(
74 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
75 {
77 }
78 virtual void SAL_CALL removeEventListener(
79 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
80 {
82 }
83
84 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override
85 {
86 return WeakComponentImplHelper_query(rType, class_data_get(), this);
87 }
88
89 // css::lang::XTypeProvider
90 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
91 {
92 static const css::uno::Sequence<css::uno::Type> aTypeList{
95 };
96 return aTypeList;
97 }
98 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
99 {
100 return css::uno::Sequence<sal_Int8>();
101 }
102
103private:
104 static cppu::class_data* class_data_get()
105 {
106 return cppu::detail::ImplClassData<WeakComponentImplHelper, Ifc...>{}();
107 }
108};
109
112COMPHELPER_DLLPUBLIC css::uno::Any
113WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd,
114 WeakComponentImplHelperBase* pBase);
115
116} // namespace comphelper
117
118/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Serves two purposes (1) extracts code that doesn't need to be templated (2) helps to handle the custo...
Definition: compbase.hxx:33
virtual void SAL_CALL dispose() override
Definition: compbase.cxx:19
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > maEventListeners
Definition: compbase.hxx:53
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) override
Definition: compbase.cxx:43
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) override
Definition: compbase.cxx:34
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: compbase.hxx:98
static cppu::class_data * class_data_get()
Definition: compbase.hxx:104
virtual void SAL_CALL acquire() noexcept final override
Definition: compbase.hxx:64
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
Definition: compbase.hxx:78
virtual void SAL_CALL release() noexcept final override
Definition: compbase.hxx:66
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
Definition: compbase.hxx:73
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: compbase.hxx:90
virtual void SAL_CALL dispose() noexcept final override
Definition: compbase.hxx:69
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
Definition: compbase.hxx:84
css::uno::Type const & get()
#define COMPHELPER_DLLPUBLIC
bool m_bDisposed
css::uno::Any WeakComponentImplHelper_query(css::uno::Type const &rType, cppu::class_data *cd, WeakComponentImplHelperBase *pBase)
WeakComponentImplHelper.
Definition: compbase.cxx:211
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
void dispose()
std::mutex mutex
Definition: random.cxx:41