LibreOffice Module cppuhelper (master) 1
cppuhelper/inc/compbase2.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 "unoimplbase.hxx"
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
29namespace cppuhelper
30{
38 public cppu::OWeakObject,
39 public css::lang::XComponent
40{
41public:
42 virtual ~WeakComponentImplHelperBase2() override;
43
44 // css::lang::XComponent
45 virtual void SAL_CALL dispose() override;
46 virtual void SAL_CALL
47 addEventListener(css::uno::Reference<css::lang::XEventListener> const& rxListener) override;
48 virtual void SAL_CALL
49 removeEventListener(css::uno::Reference<css::lang::XEventListener> const& rxListener) override;
50
51 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override;
52
57 virtual void disposing(std::unique_lock<std::mutex>&);
58
59protected:
60 void throwIfDisposed(std::unique_lock<std::mutex>&)
61 {
62 if (m_bDisposed)
63 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this));
64 }
66};
67
70CPPUHELPER_DLLPUBLIC css::uno::Any
71WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd,
73
74template <typename... Ifc>
75class SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper2 : public WeakComponentImplHelperBase2,
76 public css::lang::XTypeProvider,
77 public Ifc...
78{
79public:
80 virtual void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); }
81
82 virtual void SAL_CALL release() noexcept override { OWeakObject::release(); }
83
84 // css::lang::XComponent
85 virtual void SAL_CALL dispose() noexcept final override
86 {
88 }
89 virtual void SAL_CALL addEventListener(
90 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
91 {
93 }
94 virtual void SAL_CALL removeEventListener(
95 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
96 {
98 }
99
100 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override
101 {
102 return WeakComponentImplHelper_query(rType, class_data_get(), this);
103 }
104
105 // css::lang::XTypeProvider
106 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
107 {
108 static const css::uno::Sequence<css::uno::Type> aTypeList{
111 };
112 return aTypeList;
113 }
114 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
115 {
116 return css::uno::Sequence<sal_Int8>();
117 }
118
119private:
120 static cppu::class_data* class_data_get()
121 {
122 return cppu::detail::ImplClassData<WeakComponentImplHelper2, Ifc...>{}();
123 }
124};
125
126} // namespace cppuextra
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:48
css::uno::Type const & get()
This is a straight copy of the include/comphelper/unoimplbase.hxx file, copied here because it is nig...
Definition: unoimplbase.hxx:26
virtual void SAL_CALL dispose() noexcept final override
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
virtual void SAL_CALL release() noexcept override
decreasing m_refCount
virtual void SAL_CALL acquire() noexcept override
increasing m_refCount
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
Basic queryInterface() implementation supporting com::sun::star::uno::XWeak and com::sun::star::uno::...
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Serves two purposes (1) extracts code that doesn't need to be templated (2) helps to handle the custo...
OInterfaceContainerHelper4< css::lang::XEventListener > maEventListeners
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) override
Definition: compbase.cxx:34
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) override
Definition: compbase.cxx:43
virtual void SAL_CALL dispose() override
Definition: compbase.cxx:19
void throwIfDisposed(std::unique_lock< std::mutex > &)
#define CPPUHELPER_DLLPUBLIC
bool m_bDisposed
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
This is a straight copy of the include/comphelper/compbase.hxx file, copied here because it is nigh i...
Definition: compbase.cxx:15
css::uno::Any WeakComponentImplHelper_query(css::uno::Type const &rType, cppu::class_data *cd, WeakComponentImplHelperBase2 *pBase)
WeakComponentImplHelper.
Definition: compbase.cxx:211
void dispose()