Branch libreoffice-5-0-4
[LibreOffice.git] / include / cppuhelper / implbase2.hxx
blobb76305facae3738779d8e4b26a98aefa29fa51ca
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 .
19 #ifndef INCLUDED_CPPUHELPER_IMPLBASE2_HXX
20 #define INCLUDED_CPPUHELPER_IMPLBASE2_HXX
22 #include <cppuhelper/implbase_ex.hxx>
23 #include <rtl/instance.hxx>
25 namespace cppu
27 /// @cond INTERNAL
29 struct class_data2
31 sal_Int16 m_nTypes;
32 sal_Bool m_storedTypeRefs;
33 sal_Bool m_storedId;
34 sal_Int8 m_id[ 16 ];
35 type_entry m_typeEntries[ 2 + 1 ];
38 template< typename Ifc1, typename Ifc2, typename Impl > struct ImplClassData2
40 class_data* operator ()()
42 static class_data2 s_cd =
44 2 +1, sal_False, sal_False,
45 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
47 CPPUHELPER_DETAIL_TYPEENTRY(Ifc1),
48 CPPUHELPER_DETAIL_TYPEENTRY(Ifc2),
49 CPPUHELPER_DETAIL_TYPEENTRY(com::sun::star::lang::XTypeProvider)
52 return reinterpret_cast< class_data * >(&s_cd);
56 /// @endcond
58 /** Implementation helper implementing interface com::sun::star::lang::XTypeProvider
59 and queryInterface(), but no reference counting.
61 @derive
62 Inherit from this class giving your interface(s) to be implemented as template argument(s).
63 Your base class defines method implementations, acquire(), release() and delegates incoming
64 queryInterface() calls to this base class.
66 template< class Ifc1, class Ifc2 >
67 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelper2
68 : public com::sun::star::lang::XTypeProvider
69 , public Ifc1, public Ifc2
71 struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, ImplHelper2<Ifc1, Ifc2> > > {};
72 public:
73 virtual com::sun::star::uno::Any SAL_CALL queryInterface( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
74 { return ImplHelper_query( rType, cd::get(), this ); }
75 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
76 { return ImplHelper_getTypes( cd::get() ); }
77 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
78 { return ImplHelper_getImplementationId( cd::get() ); }
80 #if !defined _MSC_VER // public -> protected changes mangled names there
81 protected:
82 #endif
83 ~ImplHelper2() throw () {}
85 /** Implementation helper implementing interfaces com::sun::star::lang::XTypeProvider and
86 com::sun::star::uno::XInterface which supports weak mechanism to be held weakly
87 (supporting com::sun::star::uno::XWeak through ::cppu::OWeakObject).
89 @derive
90 Inherit from this class giving your interface(s) to be implemented as template argument(s).
91 Your sub class defines method implementations for these interface(s).
93 template< class Ifc1, class Ifc2 >
94 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE SAL_DLLPUBLIC_EXPORT WeakImplHelper2
95 : public OWeakObject
96 , public com::sun::star::lang::XTypeProvider
97 , public Ifc1, public Ifc2
99 struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, WeakImplHelper2<Ifc1, Ifc2> > > {};
100 public:
101 virtual com::sun::star::uno::Any SAL_CALL queryInterface( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
102 { return WeakImplHelper_query( rType, cd::get(), this, static_cast<OWeakObject *>(this) ); }
103 virtual void SAL_CALL acquire() throw () SAL_OVERRIDE
104 { OWeakObject::acquire(); }
105 virtual void SAL_CALL release() throw () SAL_OVERRIDE
106 { OWeakObject::release(); }
107 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
108 { return WeakImplHelper_getTypes( cd::get() ); }
109 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
110 { return ImplHelper_getImplementationId( cd::get() ); }
112 /** Implementation helper implementing interfaces com::sun::star::lang::XTypeProvider and
113 com::sun::star::uno::XInterface which supports weak mechanism to be held weakly
114 (supporting com::sun::star::uno::XWeak through ::cppu::OWeakAggObject).
115 In addition, it supports also aggregation meaning object of this class can be aggregated
116 (com::sun::star::uno::XAggregation through ::cppu::OWeakAggObject).
117 If a delegator is set (this object is aggregated), then incoming queryInterface()
118 calls are delegated to the delegator object. If the delegator does not support the
119 demanded interface, it calls queryAggregation() on its aggregated objects.
121 @derive
122 Inherit from this class giving your interface(s) to be implemented as template argument(s).
123 Your sub class defines method implementations for these interface(s).
125 template< class Ifc1, class Ifc2 >
126 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakAggImplHelper2
127 : public OWeakAggObject
128 , public com::sun::star::lang::XTypeProvider
129 , public Ifc1, public Ifc2
131 struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, WeakAggImplHelper2<Ifc1, Ifc2> > > {};
132 public:
133 virtual com::sun::star::uno::Any SAL_CALL queryInterface( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
134 { return OWeakAggObject::queryInterface( rType ); }
135 virtual com::sun::star::uno::Any SAL_CALL queryAggregation( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
136 { return WeakAggImplHelper_queryAgg( rType, cd::get(), this, static_cast<OWeakAggObject *>(this) ); }
137 virtual void SAL_CALL acquire() throw () SAL_OVERRIDE
138 { OWeakAggObject::acquire(); }
139 virtual void SAL_CALL release() throw () SAL_OVERRIDE
140 { OWeakAggObject::release(); }
141 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
142 { return WeakAggImplHelper_getTypes( cd::get() ); }
143 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
144 { return ImplHelper_getImplementationId( cd::get() ); }
146 /** Implementation helper implementing interfaces com::sun::star::lang::XTypeProvider and
147 com::sun::star::uno::XInterface inherting from a BaseClass.
148 All acquire() and release() calls are delegated to the BaseClass. Upon queryInterface(),
149 if a demanded interface is not supported by this class directly, the request is
150 delegated to the BaseClass.
152 @attention
153 The BaseClass has to be complete in a sense, that com::sun::star::uno::XInterface
154 and com::sun::star::lang::XTypeProvider are implemented properly. The
155 BaseClass must have at least one ctor that can be called with six or
156 fewer arguments, of which none is of non-const reference type.
158 @derive
159 Inherit from this class giving your additional interface(s) to be implemented as
160 template argument(s). Your sub class defines method implementations for these interface(s).
162 template< class BaseClass, class Ifc1, class Ifc2 >
163 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplInheritanceHelper2
164 : public BaseClass
165 , public Ifc1, public Ifc2
167 struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, ImplInheritanceHelper2<BaseClass, Ifc1, Ifc2> > > {};
168 protected:
169 template< typename T1 >
170 explicit ImplInheritanceHelper2(T1 const & arg1): BaseClass(arg1) {}
171 template< typename T1, typename T2 >
172 ImplInheritanceHelper2(T1 const & arg1, T2 const & arg2):
173 BaseClass(arg1, arg2) {}
174 template< typename T1, typename T2, typename T3 >
175 ImplInheritanceHelper2(
176 T1 const & arg1, T2 const & arg2, T3 const & arg3):
177 BaseClass(arg1, arg2, arg3) {}
178 template< typename T1, typename T2, typename T3, typename T4 >
179 ImplInheritanceHelper2(
180 T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4):
181 BaseClass(arg1, arg2, arg3, arg4) {}
182 template<
183 typename T1, typename T2, typename T3, typename T4, typename T5 >
184 ImplInheritanceHelper2(
185 T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
186 T5 const & arg5):
187 BaseClass(arg1, arg2, arg3, arg4, arg5) {}
188 template<
189 typename T1, typename T2, typename T3, typename T4, typename T5,
190 typename T6 >
191 ImplInheritanceHelper2(
192 T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
193 T5 const & arg5, T6 const & arg6):
194 BaseClass(arg1, arg2, arg3, arg4, arg5, arg6) {}
195 public:
196 ImplInheritanceHelper2() {}
197 virtual com::sun::star::uno::Any SAL_CALL queryInterface( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
199 com::sun::star::uno::Any aRet( ImplHelper_queryNoXInterface( rType, cd::get(), this ) );
200 if (aRet.hasValue())
201 return aRet;
202 return BaseClass::queryInterface( rType );
204 virtual void SAL_CALL acquire() throw () SAL_OVERRIDE
205 { BaseClass::acquire(); }
206 virtual void SAL_CALL release() throw () SAL_OVERRIDE
207 { BaseClass::release(); }
208 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
209 { return ImplInhHelper_getTypes( cd::get(), BaseClass::getTypes() ); }
210 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
211 { return ImplHelper_getImplementationId( cd::get() ); }
213 /** Implementation helper implementing interfaces com::sun::star::lang::XTypeProvider and
214 com::sun::star::uno::XInterface inherting from a BaseClass.
215 All acquire(), release() and queryInterface() calls are delegated to the BaseClass.
216 Upon queryAggregation(), if a demanded interface is not supported by this class directly,
217 the request is delegated to the BaseClass.
219 @attention
220 The BaseClass has to be complete in a sense, that com::sun::star::uno::XInterface,
221 com::sun::star::uno::XAggregation and com::sun::star::lang::XTypeProvider
222 are implemented properly. The BaseClass must have at least one ctor
223 that can be called with six or fewer arguments, of which none is of
224 non-const reference type.
226 @derive
227 Inherit from this class giving your additional interface(s) to be implemented as
228 template argument(s). Your sub class defines method implementations for these interface(s).
230 template< class BaseClass, class Ifc1, class Ifc2 >
231 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE AggImplInheritanceHelper2
232 : public BaseClass
233 , public Ifc1, public Ifc2
235 struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, AggImplInheritanceHelper2<BaseClass, Ifc1, Ifc2> > > {};
236 protected:
237 template< typename T1 >
238 explicit AggImplInheritanceHelper2(T1 const & arg1): BaseClass(arg1) {}
239 template< typename T1, typename T2 >
240 AggImplInheritanceHelper2(T1 const & arg1, T2 const & arg2):
241 BaseClass(arg1, arg2) {}
242 template< typename T1, typename T2, typename T3 >
243 AggImplInheritanceHelper2(
244 T1 const & arg1, T2 const & arg2, T3 const & arg3):
245 BaseClass(arg1, arg2, arg3) {}
246 template< typename T1, typename T2, typename T3, typename T4 >
247 AggImplInheritanceHelper2(
248 T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4):
249 BaseClass(arg1, arg2, arg3, arg4) {}
250 template<
251 typename T1, typename T2, typename T3, typename T4, typename T5 >
252 AggImplInheritanceHelper2(
253 T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
254 T5 const & arg5):
255 BaseClass(arg1, arg2, arg3, arg4, arg5) {}
256 template<
257 typename T1, typename T2, typename T3, typename T4, typename T5,
258 typename T6 >
259 AggImplInheritanceHelper2(
260 T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
261 T5 const & arg5, T6 const & arg6):
262 BaseClass(arg1, arg2, arg3, arg4, arg5, arg6) {}
263 public:
264 AggImplInheritanceHelper2() {}
265 virtual com::sun::star::uno::Any SAL_CALL queryInterface( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException) SAL_OVERRIDE
266 { return BaseClass::queryInterface( rType ); }
267 virtual com::sun::star::uno::Any SAL_CALL queryAggregation( com::sun::star::uno::Type const & rType ) throw (com::sun::star::uno::RuntimeException) SAL_OVERRIDE
269 com::sun::star::uno::Any aRet( ImplHelper_queryNoXInterface( rType, cd::get(), this ) );
270 if (aRet.hasValue())
271 return aRet;
272 return BaseClass::queryAggregation( rType );
274 virtual void SAL_CALL acquire() throw () SAL_OVERRIDE
275 { BaseClass::acquire(); }
276 virtual void SAL_CALL release() throw () SAL_OVERRIDE
277 { BaseClass::release(); }
278 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes() throw (com::sun::star::uno::RuntimeException) SAL_OVERRIDE
279 { return ImplInhHelper_getTypes( cd::get(), BaseClass::getTypes() ); }
280 virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (com::sun::star::uno::RuntimeException) SAL_OVERRIDE
281 { return ImplHelper_getImplementationId( cd::get() ); }
285 #endif
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */