Avoid potential negative array index access to cached text.
[LibreOffice.git] / cppuhelper / inc / compbase2.hxx
blob6e1486d9fabe29ec31ae8d4d56237769da6aac97
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 <cppuhelper/cppuhelperdllapi.h>
15 #include "interfacecontainer4.hxx"
16 #include "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 /**
25 This is a straight copy of the include/comphelper/compbase.hxx file, copied here
26 because it is nigh impossible to move shared code down into the URE layer.
29 namespace cppuhelper
31 /**
32 Serves two purposes
33 (1) extracts code that doesn't need to be templated
34 (2) helps to handle the custom where we have conflicting interfaces
35 e.g. multiple UNO interfaces that extend css::lang::XComponent
37 class CPPUHELPER_DLLPUBLIC WeakComponentImplHelperBase2 : public virtual UnoImplBase,
38 public cppu::OWeakObject,
39 public css::lang::XComponent
41 public:
42 virtual ~WeakComponentImplHelperBase2() override;
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;
51 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override;
53 /**
54 Called by dispose for subclasses to do dispose() work.
55 The mutex is held when called, and subclasses can unlock() the guard if necessary.
57 virtual void disposing(std::unique_lock<std::mutex>&);
59 protected:
60 void throwIfDisposed(std::unique_lock<std::mutex>&)
62 if (m_bDisposed)
63 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject*>(this));
65 OInterfaceContainerHelper4<css::lang::XEventListener> maEventListeners;
68 /** WeakComponentImplHelper
70 CPPUHELPER_DLLPUBLIC css::uno::Any
71 WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd,
72 WeakComponentImplHelperBase2* pBase);
74 template <typename... Ifc>
75 class SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper2 : public WeakComponentImplHelperBase2,
76 public css::lang::XTypeProvider,
77 public Ifc...
79 public:
80 virtual void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); }
82 virtual void SAL_CALL release() noexcept override { OWeakObject::release(); }
84 // css::lang::XComponent
85 virtual void SAL_CALL dispose() noexcept final override
87 WeakComponentImplHelperBase2::dispose();
89 virtual void SAL_CALL addEventListener(
90 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
92 WeakComponentImplHelperBase2::addEventListener(rxListener);
94 virtual void SAL_CALL removeEventListener(
95 css::uno::Reference<css::lang::XEventListener> const& rxListener) final override
97 WeakComponentImplHelperBase2::removeEventListener(rxListener);
100 virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const& rType) override
102 return WeakComponentImplHelper_query(rType, class_data_get(), this);
105 // css::lang::XTypeProvider
106 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
108 static const css::uno::Sequence<css::uno::Type> aTypeList{
109 cppu::UnoType<css::uno::XWeak>::get(), cppu::UnoType<css::lang::XComponent>::get(),
110 cppu::UnoType<css::lang::XTypeProvider>::get(), cppu::UnoType<Ifc>::get()...
112 return aTypeList;
114 virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
116 return css::uno::Sequence<sal_Int8>();
119 private:
120 static cppu::class_data* class_data_get()
122 return cppu::detail::ImplClassData<WeakComponentImplHelper2, Ifc...>{}();
126 } // namespace cppuextra
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */