bump product version to 4.2.0.1
[LibreOffice.git] / include / comphelper / implbase_var.hxx
blobbb02de5200d8a43cf02839a09e5a7cdd5fccc1e1
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 /** This header generates the following template classes with a variable number
21 of interfaces:
23 comphelper::ImplHelper<N> <typename Ifc1, ..., typename Ifc<N> >
24 comphelper::WeakImplHelper<N> <typename Ifc1, ..., typename Ifc<N> >
25 comphelper::WeakComponentImplHelper<N> <typename Ifc1, ...,
26 typename Ifc<N> >
27 comphelper::ImplInheritanceHelper<N> <typename BaseClass,
28 typename Ifc1, ..., typename Ifc<N> >
30 as already present in headers cppuhelper/implbase<1-12>.hxx and
31 cppuhelper/compbase<1-12>.hxx.
32 <N> denotes the number of interface types passed as template arguments.
33 Don't use this header for interface numbers up to 12;
34 always use the existing cppuhelper/(impl|comp)base<1-12>.hxx headers
35 for this purpose, which eases debugging.
37 Including this header requires a little discipline, because it has no
38 include guards. Please use the following external include guard rule
39 where <N> is the number of interface types:
41 #ifndef INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_<N>
42 #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_<N>
43 #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER <N>
44 #include <comphelper/implbase_var.hxx>
45 #endif
47 Additionally you can
49 #define COMPHELPER_IMPLBASE_MAX_CTOR_ARGS <N>
51 to control the maximum number of templated ctor arguments for the
52 ImplInheritanceHelper<N> classes.
53 The default is a maximum of 6 arguments.
56 #ifndef COMPHELPER_IMPLBASE_INTERFACE_NUMBER
57 #error "you have to define COMPHELPER_IMPLBASE_INTERFACE_NUMBER prior to including comphelper/implbase_var.hxx!"
58 #endif // ! defined(COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
60 #if !defined(COMPHELPER_IMPLBASE_TEST_PHASE) && COMPHELPER_IMPLBASE_INTERFACE_NUMBER <= 12
61 #error "include proper header file: cppuhelper/implbase<N>.hxx or cppuhelper/compbase<N>.hxx!"
62 #endif
64 #ifndef COMPHELPER_IMPLBASE_MAX_CTOR_ARGS
65 #define COMPHELPER_IMPLBASE_MAX_CTOR_ARGS 6 // default
66 #endif
68 #include <cppuhelper/implbase_ex.hxx>
69 #include <rtl/instance.hxx>
70 #include <cppuhelper/compbase_ex.hxx>
72 #include <boost/preprocessor/cat.hpp>
73 #include <boost/preprocessor/repetition.hpp>
74 #include <boost/preprocessor/arithmetic/add.hpp>
76 namespace comphelper {
78 // Suppress warnings about hidden functions in case any of the IfcN has
79 // functions named dispose, addEventListener, or removeEventListener:
80 #if defined __SUNPRO_CC
81 #pragma disable_warn
82 #endif
84 namespace detail {
86 struct BOOST_PP_CAT(class_data, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
88 sal_Int16 m_nTypes;
89 sal_Bool m_storedTypeRefs;
90 sal_Bool m_storedId;
91 sal_Int8 m_id[16];
92 ::cppu::type_entry m_typeEntries[COMPHELPER_IMPLBASE_INTERFACE_NUMBER + 1];
95 /// @internal
96 template < BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
97 typename Ifc), typename Impl >
98 struct BOOST_PP_CAT(ImplClassData, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
100 ::cppu::class_data * operator()() {
101 static BOOST_PP_CAT(class_data, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
102 s_cd = {
103 COMPHELPER_IMPLBASE_INTERFACE_NUMBER + 1, sal_False, sal_False,
104 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
106 #define COMPHELPER_IMPLBASE_classdataList(z_, n_, unused_) \
107 { { BOOST_PP_CAT(Ifc, n_)::static_type }, \
108 reinterpret_cast<sal_IntPtr>( static_cast< BOOST_PP_CAT(Ifc, n_) * >( \
109 reinterpret_cast<Impl *>(16) ) ) - 16 },
110 BOOST_PP_REPEAT(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
111 COMPHELPER_IMPLBASE_classdataList, ~)
112 #undef COMPHELPER_IMPLBASE_classdataList
113 { { ::com::sun::star::lang::XTypeProvider::static_type },
114 reinterpret_cast<sal_IntPtr>(
115 static_cast< ::com::sun::star::lang::XTypeProvider * >(
116 reinterpret_cast<Impl *>(16) ) ) - 16 }
119 return reinterpret_cast< ::cppu::class_data * >(&s_cd);
123 } // namespace detail
125 /** Implementation helper implementing interface
126 ::com::sun::star::lang::XTypeProvider and method
127 XInterface::queryInterface(), but no reference counting.
129 @derive
130 Inherit from this class giving your interface(s) to be implemented as
131 template argument(s). Your sub class defines method implementations for
132 these interface(s) including acquire()/release() and delegates incoming
133 queryInterface() calls to this base class.
135 template< BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
136 typename Ifc) >
137 class SAL_NO_VTABLE BOOST_PP_CAT(ImplHelper,
138 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
139 : public ::com::sun::star::lang::XTypeProvider,
140 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc)
142 /// @internal
143 struct cd : public ::rtl::StaticAggregate<
144 ::cppu::class_data,
145 BOOST_PP_CAT(detail::ImplClassData,
146 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
148 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc),
149 BOOST_PP_CAT(ImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)<
150 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)>
151 > > {};
153 protected:
154 BOOST_PP_CAT(ImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)() {}
155 virtual ~BOOST_PP_CAT(ImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)() {}
157 public:
158 virtual ::com::sun::star::uno::Any
159 SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType )
160 throw (::com::sun::star::uno::RuntimeException)
161 { return ::cppu::ImplHelper_query( rType, cd::get(), this ); }
162 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
163 SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
164 { return ::cppu::ImplHelper_getTypes( cd::get() ); }
165 virtual ::com::sun::star::uno::Sequence<sal_Int8>
166 SAL_CALL getImplementationId()
167 throw (::com::sun::star::uno::RuntimeException)
168 { return ::cppu::ImplHelper_getImplementationId( cd::get() ); }
171 /** Implementation helper implementing interfaces
172 ::com::sun::star::lang::XTypeProvider and
173 ::com::sun::star::uno::XInterface
174 which supports weak mechanism to be held weakly
175 (supporting ::com::sun::star::uno::XWeak thru ::cppu::OWeakObject).
177 @derive
178 Inherit from this class giving your interface(s) to be implemented as
179 template argument(s). Your sub class defines method implementations for
180 these interface(s).
182 template< BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
183 typename Ifc) >
184 class SAL_NO_VTABLE BOOST_PP_CAT(WeakImplHelper,
185 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
186 : public ::cppu::OWeakObject,
187 public ::com::sun::star::lang::XTypeProvider,
188 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc)
190 /// @internal
191 struct cd : public ::rtl::StaticAggregate<
192 ::cppu::class_data,
193 BOOST_PP_CAT(detail::ImplClassData,
194 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
196 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc),
197 BOOST_PP_CAT(WeakImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)<
198 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)>
199 > > {};
201 public:
202 virtual ::com::sun::star::uno::Any
203 SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType )
204 throw (::com::sun::star::uno::RuntimeException)
206 return ::cppu::WeakImplHelper_query(
207 rType, cd::get(), this, static_cast<OWeakObject *>(this) );
209 virtual void SAL_CALL acquire() throw ()
210 { OWeakObject::acquire(); }
211 virtual void SAL_CALL release() throw ()
212 { OWeakObject::release(); }
213 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
214 SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
215 { return ::cppu::WeakImplHelper_getTypes( cd::get() ); }
216 virtual ::com::sun::star::uno::Sequence<sal_Int8>
217 SAL_CALL getImplementationId()
218 throw (::com::sun::star::uno::RuntimeException)
219 { return ::cppu::ImplHelper_getImplementationId( cd::get() ); }
222 /** Implementation helper implementing interfaces
223 ::com::sun::star::lang::XTypeProvider and
224 ::com::sun::star::uno::XInterface inherting from a BaseClass.
226 All acquire() and release() calls are delegated to the BaseClass.
227 Upon queryInterface(), if a demanded interface is not supported by this
228 class directly, the request is delegated to the BaseClass.
230 @attention
231 The BaseClass has to be complete in a sense, that
232 ::com::sun::star::uno::XInterface and
233 ::com::sun::star::lang::XTypeProvider are implemented properly.
234 The BaseClass must have at least one ctor that can be called with
235 COMPHELPER_IMPLBASE_MAX_CTOR_ARGS or fewer arguments.
237 @derive
238 Inherit from this class giving your additional interface(s) to be
239 implemented as template argument(s). Your sub class defines method
240 implementations for these interface(s).
242 template <typename BaseClass,
243 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
244 typename Ifc) >
245 class SAL_NO_VTABLE BOOST_PP_CAT(ImplInheritanceHelper,
246 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
247 : public BaseClass,
248 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc)
250 /// @internal
251 struct cd : public ::rtl::StaticAggregate<
252 ::cppu::class_data,
253 BOOST_PP_CAT(detail::ImplClassData,
254 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
256 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc),
257 BOOST_PP_CAT(ImplInheritanceHelper,
258 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)<
259 BaseClass,
260 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)>
261 > > {};
263 protected:
264 #define COMPHELPER_IMPLBASE_templctor_args(z_, n_, unused_) \
265 BOOST_PP_CAT(T, n_) const& BOOST_PP_CAT(arg, n_)
266 #define COMPHELPER_IMPLBASE_templctor(z_, n_, classname_) \
267 template< BOOST_PP_ENUM_PARAMS( BOOST_PP_ADD(n_, 1), typename T) > \
268 explicit BOOST_PP_CAT(classname_, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)( \
269 BOOST_PP_ENUM(BOOST_PP_ADD(n_, 1), \
270 COMPHELPER_IMPLBASE_templctor_args, ~) ) \
271 : BaseClass( BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n_, 1), arg) ) {}
273 BOOST_PP_CAT(ImplInheritanceHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)()
274 : BaseClass() {}
275 BOOST_PP_REPEAT(COMPHELPER_IMPLBASE_MAX_CTOR_ARGS,
276 COMPHELPER_IMPLBASE_templctor, ImplInheritanceHelper)
278 public:
279 virtual ::com::sun::star::uno::Any
280 SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType )
281 throw (::com::sun::star::uno::RuntimeException)
283 ::com::sun::star::uno::Any const aRet(
284 ::cppu::ImplHelper_queryNoXInterface( rType, cd::get(), this ) );
285 if (aRet.hasValue())
286 return aRet;
287 return BaseClass::queryInterface( rType );
289 virtual void SAL_CALL acquire() throw ()
290 { BaseClass::acquire(); }
291 virtual void SAL_CALL release() throw ()
292 { BaseClass::release(); }
293 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
294 SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
296 return ::cppu::ImplInhHelper_getTypes(
297 cd::get(), BaseClass::getTypes() );
299 virtual ::com::sun::star::uno::Sequence<sal_Int8>
300 SAL_CALL getImplementationId()
301 throw (::com::sun::star::uno::RuntimeException)
302 { return ::cppu::ImplHelper_getImplementationId( cd::get() ); }
305 // not needed anymore:
306 #undef COMPHELPER_IMPLBASE_templctor_args
307 #undef COMPHELPER_IMPLBASE_templctor
309 /** Implementation helper supporting
310 ::com::sun::star::lang::XTypeProvider and
311 ::com::sun::star::lang::XComponent.
313 Upon disposing objects of this class, sub-classes receive a disposing()
314 call. Objects of this class can be held weakly, i.e. by a
315 ::com::sun::star::uno::WeakReference.
317 @attention
318 The life-cycle of the passed mutex reference has to be longer than objects
319 of this class.
321 @derive
322 Inherit from this class giving your interface(s) to be implemented as
323 template argument(s). Your sub class defines method implementations for
324 these interface(s).
326 template < BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
327 typename Ifc) >
328 class SAL_NO_VTABLE BOOST_PP_CAT(WeakComponentImplHelper,
329 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
330 : public ::cppu::WeakComponentImplHelperBase,
331 public ::com::sun::star::lang::XTypeProvider,
332 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc)
334 /// @internal
335 struct cd : public ::rtl::StaticAggregate<
336 ::cppu::class_data,
337 BOOST_PP_CAT(detail::ImplClassData,
338 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
340 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc),
341 BOOST_PP_CAT(WeakComponentImplHelper,
342 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)<
343 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)>
344 > > {};
346 public:
347 BOOST_PP_CAT(WeakComponentImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)(
348 ::osl::Mutex & rMutex ) : WeakComponentImplHelperBase(rMutex) {}
350 virtual ::com::sun::star::uno::Any
351 SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType )
352 throw (::com::sun::star::uno::RuntimeException)
354 return ::cppu::WeakComponentImplHelper_query(
355 rType, cd::get(), this,
356 static_cast< ::cppu::WeakComponentImplHelperBase * >(this) );
358 virtual void SAL_CALL acquire() throw ()
359 { WeakComponentImplHelperBase::acquire(); }
360 virtual void SAL_CALL release() throw ()
361 { WeakComponentImplHelperBase::release(); }
362 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
363 SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
364 { return ::cppu::WeakComponentImplHelper_getTypes( cd::get() ); }
365 virtual ::com::sun::star::uno::Sequence<sal_Int8>
366 SAL_CALL getImplementationId()
367 throw (::com::sun::star::uno::RuntimeException)
368 { return ::cppu::ImplHelper_getImplementationId( cd::get() ); }
370 // implement XComponent directly avoiding ambiguities:
371 virtual void SAL_CALL dispose()
372 throw (::com::sun::star::uno::RuntimeException)
373 { WeakComponentImplHelperBase::dispose(); }
374 virtual void SAL_CALL addEventListener(
375 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>
376 const & xListener ) throw (::com::sun::star::uno::RuntimeException)
377 { WeakComponentImplHelperBase::addEventListener( xListener ); }
378 virtual void SAL_CALL removeEventListener(
379 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>
380 const & xListener ) throw (::com::sun::star::uno::RuntimeException)
381 { WeakComponentImplHelperBase::removeEventListener( xListener ); }
384 template < BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER,
385 typename Ifc) >
386 class SAL_NO_VTABLE BOOST_PP_CAT(PartialWeakComponentImplHelper,
387 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
388 : public ::cppu::WeakComponentImplHelperBase,
389 public ::com::sun::star::lang::XTypeProvider,
390 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, public Ifc)
392 /// @internal
393 struct cd : public ::rtl::StaticAggregate<
394 ::cppu::class_data,
395 BOOST_PP_CAT(detail::ImplClassData,
396 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)
398 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc),
399 BOOST_PP_CAT(PartialWeakComponentImplHelper,
400 COMPHELPER_IMPLBASE_INTERFACE_NUMBER)<
401 BOOST_PP_ENUM_PARAMS(COMPHELPER_IMPLBASE_INTERFACE_NUMBER, Ifc)>
402 > > {};
404 public:
405 BOOST_PP_CAT(PartialWeakComponentImplHelper, COMPHELPER_IMPLBASE_INTERFACE_NUMBER)(
406 ::osl::Mutex & rMutex ) : WeakComponentImplHelperBase(rMutex) {}
408 virtual ::com::sun::star::uno::Any
409 SAL_CALL queryInterface( ::com::sun::star::uno::Type const& rType )
410 throw (::com::sun::star::uno::RuntimeException)
412 return ::cppu::WeakComponentImplHelper_query(
413 rType, cd::get(), this,
414 static_cast< ::cppu::WeakComponentImplHelperBase * >(this) );
416 virtual void SAL_CALL acquire() throw ()
417 { WeakComponentImplHelperBase::acquire(); }
418 virtual void SAL_CALL release() throw ()
419 { WeakComponentImplHelperBase::release(); }
420 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
421 SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
422 { return ::cppu::WeakComponentImplHelper_getTypes( cd::get() ); }
423 virtual ::com::sun::star::uno::Sequence<sal_Int8>
424 SAL_CALL getImplementationId()
425 throw (::com::sun::star::uno::RuntimeException)
426 { return ::cppu::ImplHelper_getImplementationId( cd::get() ); }
430 } // namespace comphelper
432 // undef for multiple use/inclusion of this header:
433 #undef COMPHELPER_IMPLBASE_MAX_CTOR_ARGS
434 #undef COMPHELPER_IMPLBASE_INTERFACE_NUMBER
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */