tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / cppuhelper / implbase.hxx
blobf2f08650ea1cae1118090319216e7cf8105ba391
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CPPUHELPER_IMPLBASE_HXX
21 #define INCLUDED_CPPUHELPER_IMPLBASE_HXX
23 #include "sal/config.h"
25 #include <cstddef>
26 #include <utility>
28 #include "com/sun/star/lang/XTypeProvider.hpp"
29 #include "com/sun/star/uno/Any.h"
30 #include "com/sun/star/uno/Sequence.hxx"
31 #include "com/sun/star/uno/Type.h"
32 #include "cppuhelper/implbase_ex.hxx"
33 #include "cppuhelper/weak.hxx"
34 #include "rtl/instance.hxx"
35 #include "sal/types.h"
37 #if defined LIBO_INTERNAL_ONLY
39 // A replacement for ImplHelperN has deliberately been left out, as ImplHelperN
40 // is unlikely ever be a better choice than WeakImplHelper, so all their
41 // existing uses are probably confused and should use WeakImplHelper instead.
43 // Replacements for WeakAggImplHelperN and AggImplInheritanceHelperN have
44 // deliberately been left out, as the underlying aggregation mechanism is known
45 // broken in general and should not be used.
47 namespace cppu {
49 /// @cond INTERNAL
51 namespace detail {
53 template<std::size_t N> struct class_dataN {
54 sal_Int16 m_nTypes;
55 sal_Bool m_storedTypeRefs;
56 sal_Bool m_storedId;
57 sal_Int8 m_id[16];
58 type_entry m_typeEntries[N + 1];
61 template<typename Impl, typename... Ifc> struct ImplClassData {
62 class_data * operator ()() {
63 static class_dataN<sizeof... (Ifc)> s_cd = {
64 sizeof... (Ifc) + 1, false, false, {},
66 { { Ifc::static_type },
67 (reinterpret_cast<sal_IntPtr>(
68 static_cast<Ifc *>(reinterpret_cast<Impl *>(16)))
69 - 16)
70 }...,
71 CPPUHELPER_DETAIL_TYPEENTRY(css::lang::XTypeProvider)
74 return reinterpret_cast<class_data *>(&s_cd);
80 /// @endcond
82 /** Implementation helper implementing interfaces
83 css::uno::XInterface, css::lang::XTypeProvider, and
84 css::uno::XWeak (through cppu::OWeakObject).
86 @derive
87 Inherit from this class giving your interface(s) to be implemented as
88 template argument(s).
90 template<typename... Ifc>
91 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper:
92 public OWeakObject, public css::lang::XTypeProvider, public Ifc...
94 struct cd:
95 rtl::StaticAggregate<
96 class_data, detail::ImplClassData<WeakImplHelper, Ifc...>>
97 {};
99 protected:
100 WeakImplHelper() {}
102 virtual ~WeakImplHelper() override {}
104 public:
105 WeakImplHelper(WeakImplHelper const &) = default;
106 WeakImplHelper(WeakImplHelper &&) = default;
107 WeakImplHelper & operator =(WeakImplHelper const &) = default;
108 WeakImplHelper & operator =(WeakImplHelper &&) = default;
110 css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) override
111 { return WeakImplHelper_query(aType, cd::get(), this, this); }
113 void SAL_CALL acquire() SAL_NOEXCEPT override { OWeakObject::acquire(); }
115 void SAL_CALL release() SAL_NOEXCEPT override { OWeakObject::release(); }
117 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
118 { return WeakImplHelper_getTypes(cd::get()); }
120 css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
121 { return css::uno::Sequence<sal_Int8>(); }
124 /** Implementation helper implementing interfaces
125 css::uno::XInterface and css::lang::XTypeProvider
126 inheriting from a BaseClass.
128 All acquire() and release() calls are delegated to the BaseClass. Upon
129 queryInterface(), if a demanded interface is not supported by this class
130 directly, the request is delegated to the BaseClass.
132 @attention
133 The BaseClass has to be complete in the sense that
134 css::uno::XInterface and css::lang::XTypeProvider are
135 implemented properly.
137 @derive
138 Inherit from this class giving your additional interface(s) to be
139 implemented as template argument(s).
141 template<typename BaseClass, typename... Ifc>
142 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplInheritanceHelper:
143 public BaseClass, public Ifc...
145 struct cd:
146 rtl::StaticAggregate<
147 class_data, detail::ImplClassData<ImplInheritanceHelper, Ifc...>>
150 protected:
151 template<typename... Arg> ImplInheritanceHelper(Arg &&... arg):
152 BaseClass(std::forward<Arg>(arg)...)
155 virtual ~ImplInheritanceHelper() {}
157 public:
158 ImplInheritanceHelper(ImplInheritanceHelper const &) = default;
159 ImplInheritanceHelper(ImplInheritanceHelper &&) = default;
160 ImplInheritanceHelper & operator =(ImplInheritanceHelper const &) = default;
161 ImplInheritanceHelper & operator =(ImplInheritanceHelper &&) = default;
163 css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) override
165 css::uno::Any ret(ImplHelper_queryNoXInterface(aType, cd::get(), this));
166 return ret.hasValue() ? ret : BaseClass::queryInterface(aType);
169 void SAL_CALL acquire() SAL_NOEXCEPT override { BaseClass::acquire(); }
171 void SAL_CALL release() SAL_NOEXCEPT override { BaseClass::release(); }
173 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
174 { return ImplInhHelper_getTypes(cd::get(), BaseClass::getTypes()); }
176 css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
177 { return css::uno::Sequence<sal_Int8>(); }
182 #endif
184 #endif
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */