1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 #include <com/sun/star/lang/XTypeProvider.hpp>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/uno/RuntimeException.hpp>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/uno/Type.hxx>
34 #include <cppuhelper/implbase_ex.hxx>
35 #include <cppuhelper/weak.hxx>
36 #include <rtl/instance.hxx>
37 #include <sal/types.h>
39 #if defined LIBO_INTERNAL_ONLY
47 template<std::size_t N
> struct class_dataN
{
49 sal_Bool m_storedTypeRefs
;
52 type_entry m_typeEntries
[N
+ 1];
55 template<typename Impl
, typename
... Ifc
> struct ImplClassData
{
56 class_data
* operator ()() {
57 static class_dataN
<sizeof... (Ifc
)> s_cd
= {
58 sizeof... (Ifc
) + 1, false, false, {},
60 { { Ifc::static_type
},
61 (reinterpret_cast<sal_IntPtr
>(
62 static_cast<Ifc
*>(reinterpret_cast<Impl
*>(16)))
65 CPPUHELPER_DETAIL_TYPEENTRY(css::lang::XTypeProvider
)
68 return reinterpret_cast<class_data
*>(&s_cd
);
76 /** Implementation helper implementing interfaces
77 com::sun::star::uno::XInterface, com::sun::star::lang::XTypeProvider, and
78 com::sun::star::uno::XWeak (through cppu::OWeakObject).
81 Inherit from this class giving your interface(s) to be implemented as
84 template<typename
... Ifc
>
85 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper
:
86 public OWeakObject
, public css::lang::XTypeProvider
, public Ifc
...
90 class_data
, detail::ImplClassData
<WeakImplHelper
, Ifc
...>>
96 virtual ~WeakImplHelper() {}
99 css::uno::Any SAL_CALL
queryInterface(css::uno::Type
const & aType
)
100 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
101 { return WeakImplHelper_query(aType
, cd::get(), this, this); }
103 void SAL_CALL
acquire() throw () SAL_OVERRIDE
{ OWeakObject::acquire(); }
105 void SAL_CALL
release() throw () SAL_OVERRIDE
{ OWeakObject::release(); }
107 css::uno::Sequence
<css::uno::Type
> SAL_CALL
getTypes()
108 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
109 { return WeakImplHelper_getTypes(cd::get()); }
111 css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId()
112 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
113 { return css::uno::Sequence
<sal_Int8
>(); }
116 /** Implementation helper implementing interfaces
117 com::sun::star::uno::XInterface and com::sun::star::lang::XTypeProvider
118 inherting from a BaseClass.
120 All acquire() and release() calls are delegated to the BaseClass. Upon
121 queryInterface(), if a demanded interface is not supported by this class
122 directly, the request is delegated to the BaseClass.
125 The BaseClass has to be complete in the sense that
126 com::sun::star::uno::XInterface and com::sun::star::lang::XTypeProvider are
127 implemented properly.
130 Inherit from this class giving your additional interface(s) to be
131 implemented as template argument(s).
133 template<typename BaseClass
, typename
... Ifc
>
134 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplInheritanceHelper
:
135 public BaseClass
, public Ifc
...
138 rtl::StaticAggregate
<
139 class_data
, detail::ImplClassData
<ImplInheritanceHelper
, Ifc
...>>
143 template<typename
... Arg
> ImplInheritanceHelper(Arg
&&... arg
):
144 BaseClass(std::forward
<Arg
>(arg
)...)
147 virtual ~ImplInheritanceHelper() {}
150 css::uno::Any SAL_CALL
queryInterface(css::uno::Type
const & aType
)
151 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
153 css::uno::Any
ret(ImplHelper_queryNoXInterface(aType
, cd::get(), this));
154 return ret
.hasValue() ? ret
: BaseClass::queryInterface(aType
);
157 void SAL_CALL
acquire() throw () SAL_OVERRIDE
{ BaseClass::acquire(); }
159 void SAL_CALL
release() throw () SAL_OVERRIDE
{ BaseClass::release(); }
161 css::uno::Sequence
<css::uno::Type
> SAL_CALL
getTypes()
162 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
163 { return ImplInhHelper_getTypes(cd::get(), BaseClass::getTypes()); }
165 css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId()
166 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
167 { return css::uno::Sequence
<sal_Int8
>(); }
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */