1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CPPUHELPER_IMPLBASE2_HXX_
28 #define _CPPUHELPER_IMPLBASE2_HXX_
29 
30 #include <cppuhelper/implbase_ex.hxx>
31 #include <rtl/instance.hxx>
32 
33 namespace cppu
34 {
35     /** @internal */
36     struct class_data2
37     {
38         sal_Int16 m_nTypes;
39         sal_Bool m_storedTypeRefs;
40         sal_Bool m_storedId;
41         sal_Int8 m_id[ 16 ];
42         type_entry m_typeEntries[ 2 + 1 ];
43     };
44 
45     /** @internal */
46     template< typename Ifc1, typename Ifc2, typename Impl > struct ImplClassData2
47     {
48         class_data* operator ()()
49         {
50             static class_data2 s_cd =
51             {
52                 2 +1, sal_False, sal_False,
53                 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
54                 {
55 					{ { Ifc1::static_type }, ((sal_IntPtr)(Ifc1 *) (Impl *) 16) - 16 },
56 					{ { Ifc2::static_type }, ((sal_IntPtr)(Ifc2 *) (Impl *) 16) - 16 },
57 					{ { ::com::sun::star::lang::XTypeProvider::static_type }, ((sal_IntPtr)(::com::sun::star::lang::XTypeProvider *) (Impl *) 16) - 16 }
58                 }
59             };
60             return reinterpret_cast< class_data * >(&s_cd);
61         }
62     };
63 
64     /** Implementation helper implementing interface ::com::sun::star::lang::XTypeProvider
65         and queryInterface(), but no reference counting.
66 
67         @derive
68         Inherit from this class giving your interface(s) to be implemented as template argument(s).
69         Your base class defines method implementations, acquire(), release() and delegates incoming
70         queryInterface() calls to this base class.
71     */
72     template< class Ifc1, class Ifc2 >
73     class SAL_NO_VTABLE ImplHelper2
74         : public ::com::sun::star::lang::XTypeProvider
75         , public Ifc1, public Ifc2
76     {
77         /** @internal */
78         struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, ImplHelper2<Ifc1, Ifc2> > > {};
79     public:
80         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
81             { return ImplHelper_query( rType, cd::get(), this ); }
82         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
83             { return ImplHelper_getTypes( cd::get() ); }
84         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException)
85             { return ImplHelper_getImplementationId( cd::get() ); }
86     };
87     /** Implementation helper implementing interfaces ::com::sun::star::lang::XTypeProvider and
88         ::com::sun::star::uno::XInterface which supports weak mechanism to be held weakly
89         (supporting ::com::sun::star::uno::XWeak thru ::cppu::OWeakObject).
90 
91         @derive
92         Inherit from this class giving your interface(s) to be implemented as template argument(s).
93         Your sub class defines method implementations for these interface(s).
94     */
95     template< class Ifc1, class Ifc2 >
96     class SAL_NO_VTABLE WeakImplHelper2
97         : public OWeakObject
98         , public ::com::sun::star::lang::XTypeProvider
99         , public Ifc1, public Ifc2
100     {
101         /** @internal */
102         struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, WeakImplHelper2<Ifc1, Ifc2> > > {};
103     public:
104         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
105             { return WeakImplHelper_query( rType, cd::get(), this, (OWeakObject *)this ); }
106         virtual void SAL_CALL acquire() throw ()
107             { OWeakObject::acquire(); }
108         virtual void SAL_CALL release() throw ()
109             { OWeakObject::release(); }
110         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
111             { return WeakImplHelper_getTypes( cd::get() ); }
112         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException)
113             { return ImplHelper_getImplementationId( cd::get() ); }
114     };
115     /** Implementation helper implementing interfaces ::com::sun::star::lang::XTypeProvider and
116         ::com::sun::star::uno::XInterface which supports weak mechanism to be held weakly
117         (supporting ::com::sun::star::uno::XWeak thru ::cppu::OWeakAggObject).
118         In addition, it supports also aggregation meaning object of this class can be aggregated
119         (::com::sun::star::uno::XAggregation thru ::cppu::OWeakAggObject).
120         If a delegator is set (this object is aggregated), then incoming queryInterface()
121         calls are delegated to the delegator object. If the delegator does not support the
122         demanded interface, it calls queryAggregation() on its aggregated objects.
123 
124         @derive
125         Inherit from this class giving your interface(s) to be implemented as template argument(s).
126         Your sub class defines method implementations for these interface(s).
127     */
128     template< class Ifc1, class Ifc2 >
129     class SAL_NO_VTABLE WeakAggImplHelper2
130         : public OWeakAggObject
131         , public ::com::sun::star::lang::XTypeProvider
132         , public Ifc1, public Ifc2
133     {
134         /** @internal */
135         struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, WeakAggImplHelper2<Ifc1, Ifc2> > > {};
136     public:
137         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
138             { return OWeakAggObject::queryInterface( rType ); }
139         virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
140             { return WeakAggImplHelper_queryAgg( rType, cd::get(), this, (OWeakAggObject *)this ); }
141         virtual void SAL_CALL acquire() throw ()
142             { OWeakAggObject::acquire(); }
143         virtual void SAL_CALL release() throw ()
144             { OWeakAggObject::release(); }
145         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
146             { return WeakAggImplHelper_getTypes( cd::get() ); }
147         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException)
148             { return ImplHelper_getImplementationId( cd::get() ); }
149     };
150     /** Implementation helper implementing interfaces ::com::sun::star::lang::XTypeProvider and
151         ::com::sun::star::uno::XInterface inherting from a BaseClass.
152         All acquire() and release() calls are delegated to the BaseClass. Upon queryInterface(),
153         if a demanded interface is not supported by this class directly, the request is
154         delegated to the BaseClass.
155 
156         @attention
157         The BaseClass has to be complete in a sense, that ::com::sun::star::uno::XInterface
158         and ::com::sun::star::lang::XTypeProvider are implemented properly.  The
159         BaseClass must have at least one ctor that can be called with six or
160         fewer arguments, of which none is of non-const reference type.
161 
162         @derive
163         Inherit from this class giving your additional interface(s) to be implemented as
164         template argument(s). Your sub class defines method implementations for these interface(s).
165     */
166     template< class BaseClass, class Ifc1, class Ifc2 >
167     class SAL_NO_VTABLE ImplInheritanceHelper2
168         : public BaseClass
169         , public Ifc1, public Ifc2
170     {
171         /** @internal */
172         struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, ImplInheritanceHelper2<BaseClass, Ifc1, Ifc2> > > {};
173     protected:
174         template< typename T1 >
175         explicit ImplInheritanceHelper2(T1 const & arg1): BaseClass(arg1) {}
176         template< typename T1, typename T2 >
177         ImplInheritanceHelper2(T1 const & arg1, T2 const & arg2):
178             BaseClass(arg1, arg2) {}
179         template< typename T1, typename T2, typename T3 >
180         ImplInheritanceHelper2(
181             T1 const & arg1, T2 const & arg2, T3 const & arg3):
182             BaseClass(arg1, arg2, arg3) {}
183         template< typename T1, typename T2, typename T3, typename T4 >
184         ImplInheritanceHelper2(
185             T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4):
186             BaseClass(arg1, arg2, arg3, arg4) {}
187         template<
188             typename T1, typename T2, typename T3, typename T4, typename T5 >
189         ImplInheritanceHelper2(
190             T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
191             T5 const & arg5):
192             BaseClass(arg1, arg2, arg3, arg4, arg5) {}
193         template<
194             typename T1, typename T2, typename T3, typename T4, typename T5,
195             typename T6 >
196         ImplInheritanceHelper2(
197             T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
198             T5 const & arg5, T6 const & arg6):
199             BaseClass(arg1, arg2, arg3, arg4, arg5, arg6) {}
200     public:
201         ImplInheritanceHelper2() {}
202         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
203             {
204                 ::com::sun::star::uno::Any aRet( ImplHelper_queryNoXInterface( rType, cd::get(), this ) );
205                 if (aRet.hasValue())
206                     return aRet;
207                 return BaseClass::queryInterface( rType );
208             }
209         virtual void SAL_CALL acquire() throw ()
210             { BaseClass::acquire(); }
211         virtual void SAL_CALL release() throw ()
212             { BaseClass::release(); }
213         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
214             { return ImplInhHelper_getTypes( cd::get(), BaseClass::getTypes() ); }
215         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException)
216             { return ImplHelper_getImplementationId( cd::get() ); }
217     };
218     /** Implementation helper implementing interfaces ::com::sun::star::lang::XTypeProvider and
219         ::com::sun::star::uno::XInterface inherting from a BaseClass.
220         All acquire(),  release() and queryInterface() calls are delegated to the BaseClass.
221         Upon queryAggregation(), if a demanded interface is not supported by this class directly,
222         the request is delegated to the BaseClass.
223 
224         @attention
225         The BaseClass has to be complete in a sense, that ::com::sun::star::uno::XInterface,
226         ::com::sun::star::uno::XAggregation and ::com::sun::star::lang::XTypeProvider
227         are implemented properly.  The BaseClass must have at least one ctor
228         that can be called with six or fewer arguments, of which none is of
229         non-const reference type.
230 
231         @derive
232         Inherit from this class giving your additional interface(s) to be implemented as
233         template argument(s). Your sub class defines method implementations for these interface(s).
234     */
235     template< class BaseClass, class Ifc1, class Ifc2 >
236     class SAL_NO_VTABLE AggImplInheritanceHelper2
237         : public BaseClass
238         , public Ifc1, public Ifc2
239     {
240         /** @internal */
241         struct cd : public rtl::StaticAggregate< class_data, ImplClassData2 < Ifc1, Ifc2, AggImplInheritanceHelper2<BaseClass, Ifc1, Ifc2> > > {};
242     protected:
243         template< typename T1 >
244         explicit AggImplInheritanceHelper2(T1 const & arg1): BaseClass(arg1) {}
245         template< typename T1, typename T2 >
246         AggImplInheritanceHelper2(T1 const & arg1, T2 const & arg2):
247             BaseClass(arg1, arg2) {}
248         template< typename T1, typename T2, typename T3 >
249         AggImplInheritanceHelper2(
250             T1 const & arg1, T2 const & arg2, T3 const & arg3):
251             BaseClass(arg1, arg2, arg3) {}
252         template< typename T1, typename T2, typename T3, typename T4 >
253         AggImplInheritanceHelper2(
254             T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4):
255             BaseClass(arg1, arg2, arg3, arg4) {}
256         template<
257             typename T1, typename T2, typename T3, typename T4, typename T5 >
258         AggImplInheritanceHelper2(
259             T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
260             T5 const & arg5):
261             BaseClass(arg1, arg2, arg3, arg4, arg5) {}
262         template<
263             typename T1, typename T2, typename T3, typename T4, typename T5,
264             typename T6 >
265         AggImplInheritanceHelper2(
266             T1 const & arg1, T2 const & arg2, T3 const & arg3, T4 const & arg4,
267             T5 const & arg5, T6 const & arg6):
268             BaseClass(arg1, arg2, arg3, arg4, arg5, arg6) {}
269     public:
270         AggImplInheritanceHelper2() {}
271         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
272             { return BaseClass::queryInterface( rType ); }
273         virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( ::com::sun::star::uno::Type const & rType ) throw (::com::sun::star::uno::RuntimeException)
274             {
275                 ::com::sun::star::uno::Any aRet( ImplHelper_queryNoXInterface( rType, cd::get(), this ) );
276                 if (aRet.hasValue())
277                     return aRet;
278                 return BaseClass::queryAggregation( rType );
279             }
280         virtual void SAL_CALL acquire() throw ()
281             { BaseClass::acquire(); }
282         virtual void SAL_CALL release() throw ()
283             { BaseClass::release(); }
284         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException)
285             { return ImplInhHelper_getTypes( cd::get(), BaseClass::getTypes() ); }
286         virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException)
287             { return ImplHelper_getImplementationId( cd::get() ); }
288     };
289 }
290 
291 #endif
292