LibreOffice Module cppuhelper (master) 1
implbase.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_CPPUHELPER_IMPLBASE_HXX
21#define INCLUDED_CPPUHELPER_IMPLBASE_HXX
22
23#include "sal/config.h"
24
25#include <cstddef>
26#include <utility>
27
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"
33#include "cppuhelper/weak.hxx"
34#include "rtl/instance.hxx"
35#include "sal/types.h"
36
37#if defined LIBO_INTERNAL_ONLY
38
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.
42//
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.
46
47namespace cppu {
48
50
51namespace detail {
52
53template<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];
59};
60
61template<typename Impl, typename... Ifc> struct ImplClassData {
62 class_data * operator ()() {
63 static class_dataN<sizeof... (Ifc)> s_cd = {
64 sizeof... (Ifc) + 1, false, false, {},
65 {
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)
72 }
73 };
74 return reinterpret_cast<class_data *>(&s_cd);
75 }
76};
77
78}
79
81
90template<typename... Ifc>
91class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper:
92 public OWeakObject, public css::lang::XTypeProvider, public Ifc...
93{
94 struct cd:
95 rtl::StaticAggregate<
96 class_data, detail::ImplClassData<WeakImplHelper, Ifc...>>
97 {};
98
99protected:
100 WeakImplHelper() {}
101
102 virtual ~WeakImplHelper() override {}
103
104public:
105 WeakImplHelper(WeakImplHelper const &) = default;
106 WeakImplHelper(WeakImplHelper &&) = default;
107 WeakImplHelper & operator =(WeakImplHelper const &) = default;
108 WeakImplHelper & operator =(WeakImplHelper &&) = default;
109
110 css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) override
111 { return WeakImplHelper_query(aType, cd::get(), this, this); }
112
113 void SAL_CALL acquire() SAL_NOEXCEPT override { OWeakObject::acquire(); }
114
115 void SAL_CALL release() SAL_NOEXCEPT override { OWeakObject::release(); }
116
117 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
118 { return WeakImplHelper_getTypes(cd::get()); }
119
120 css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
121 { return css::uno::Sequence<sal_Int8>(); }
122};
123
141template<typename BaseClass, typename... Ifc>
142class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplInheritanceHelper:
143 public BaseClass, public Ifc...
144{
145 struct cd:
146 rtl::StaticAggregate<
147 class_data, detail::ImplClassData<ImplInheritanceHelper, Ifc...>>
148 {};
149
150protected:
151 template<typename... Arg> ImplInheritanceHelper(Arg &&... arg):
152 BaseClass(std::forward<Arg>(arg)...)
153 {}
154
155 virtual ~ImplInheritanceHelper() {}
156
157public:
158 ImplInheritanceHelper(ImplInheritanceHelper const &) = default;
159 ImplInheritanceHelper(ImplInheritanceHelper &&) = default;
160 ImplInheritanceHelper & operator =(ImplInheritanceHelper const &) = default;
161 ImplInheritanceHelper & operator =(ImplInheritanceHelper &&) = default;
162
163 css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) override
164 {
165 css::uno::Any ret(ImplHelper_queryNoXInterface(aType, cd::get(), this));
166 return ret.hasValue() ? ret : BaseClass::queryInterface(aType);
167 }
168
169 void SAL_CALL acquire() SAL_NOEXCEPT override { BaseClass::acquire(); }
170
171 void SAL_CALL release() SAL_NOEXCEPT override { BaseClass::release(); }
172
173 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override
174 { return ImplInhHelper_getTypes(cd::get(), BaseClass::getTypes()); }
175
176 css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override
177 { return css::uno::Sequence<sal_Int8>(); }
178};
179
180}
181
182#endif
183
184#endif
185
186/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
increasing m_refCount
Definition: weak.cxx:217
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
decreasing m_refCount
Definition: weak.cxx:223
def forward(n)
Sequence< Type > SAL_CALL ImplInhHelper_getTypes(class_data *cd, Sequence< Type > const &rAddTypes)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
Any SAL_CALL WeakImplHelper_query(Type const &rType, class_data *cd, void *that, OWeakObject *pBase)
Sequence< Type > SAL_CALL WeakImplHelper_getTypes(class_data *cd)
Any SAL_CALL ImplHelper_queryNoXInterface(Type const &rType, class_data *cd, void *that)
#define N
::rtl::ByteSequence m_id
#define SAL_NO_VTABLE
unsigned char sal_Bool
signed char sal_Int8