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
17#include <cppuhelper/weak.hxx>
20#include <com/sun/star/lang/XComponent.hpp>
21#include <com/sun/star/lang/XTypeProvider.hpp>
22#include <mutex>
23
24namespace comphelper
25{
33 public cppu::OWeakObject,
34 public css::lang::XComponent
35{
36public:
37 virtual ~WeakComponentImplHelperBase() override;
38
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;
45
46 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override;
47
52 virtual void disposing(std::unique_lock<std::mutex>&);
53
54protected:
55 void throwIfDisposed(std::unique_lock<std::mutex>&)
56 {
57 if (m_bDisposed)
58 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this));
59 }
61};
62
63template <typename... Ifc>
64class SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper : public WeakComponentImplHelperBase,
65 public css::lang::XTypeProvider,
66 public Ifc...
67{
68public:
69 virtual void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); }
70
71 virtual void SAL_CALL release() noexcept override { OWeakObject::release(); }
72
73 // css::lang::XComponent
74 virtual void SAL_CALL dispose() noexcept final override
75 {
77 }
78 virtual void SAL_CALL addEventListener(
79 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
80 {
82 }
83 virtual void SAL_CALL removeEventListener(
84 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
85 {
87 }
88
89 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override
90 {
91 return WeakComponentImplHelper_query(rType, class_data_get(), this);
92 }
93
94 // css::lang::XTypeProvider
95 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
96 {
97 static const css::uno::Sequence<css::uno::Type> aTypeList{
100 };
101 return aTypeList;
102 }
103 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
104 {
105 return css::uno::Sequence<sal_Int8>();
106 }
107
108private:
109 static cppu::class_data* class_data_get()
110 {
111 return cppu::detail::ImplClassData<WeakComponentImplHelper, Ifc...>{}();
112 }
113};
114
117COMPHELPER_DLLPUBLIC css::uno::Any
118WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd,
119 WeakComponentImplHelperBase* pBase);
120
121} // namespace comphelper
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
This class is meant to be used as a base class for UNO object implementations that want to use std::m...
Definition: unoimplbase.hxx:23
Serves two purposes (1) extracts code that doesn't need to be templated (2) helps to handle the custo...
Definition: compbase.hxx:35
virtual void SAL_CALL dispose() override
Definition: compbase.cxx:19
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > maEventListeners
Definition: compbase.hxx:60
void throwIfDisposed(std::unique_lock< std::mutex > &)
Definition: compbase.hxx:55
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:103
static cppu::class_data * class_data_get()
Definition: compbase.hxx:109
virtual void SAL_CALL acquire() noexcept override
Definition: compbase.hxx:69
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
Definition: compbase.hxx:83
virtual void SAL_CALL release() noexcept override
Definition: compbase.hxx:71
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
Definition: compbase.hxx:78
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: compbase.hxx:95
virtual void SAL_CALL dispose() noexcept final override
Definition: compbase.hxx:74
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
Definition: compbase.hxx:89
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()