Branch libreoffice-5-0-4
[LibreOffice.git] / include / ucbhelper / macros.hxx
blob8bdd20df0a1537f684126405f999bf1b15d9edf3
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 #ifndef INCLUDED_UCBHELPER_MACROS_HXX
21 #define INCLUDED_UCBHELPER_MACROS_HXX
23 #include <sal/types.h>
24 #include <cppuhelper/queryinterface.hxx>
25 #include <cppuhelper/factory.hxx>
26 #include <cppuhelper/weakref.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/typeprovider.hxx>
30 #include <osl/mutex.hxx>
31 #include <ucbhelper/getcomponentcontext.hxx>
35 #define CPPU_TYPE( T ) cppu::UnoType<T>::get()
36 #define CPPU_TYPE_REF( T ) CPPU_TYPE( T )
38 // XTypeProvider impl. internals
42 #define XTYPEPROVIDER_COMMON_IMPL( Class ) \
43 com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL \
44 Class::getImplementationId() \
45 throw( com::sun::star::uno::RuntimeException, std::exception ) \
46 { \
47 return css::uno::Sequence<sal_Int8>(); \
50 #define GETTYPES_IMPL_START( Class ) \
51 com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL \
52 Class::getTypes() \
53 throw( com::sun::star::uno::RuntimeException, std::exception ) \
54 { \
55 static cppu::OTypeCollection* pCollection = NULL; \
56 if ( !pCollection ) \
57 { \
58 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); \
59 if ( !pCollection ) \
60 { \
61 static cppu::OTypeCollection collection(
63 #define GETTYPES_IMPL_END \
64 ); \
65 pCollection = &collection; \
66 } \
67 } \
68 return (*pCollection).getTypes(); \
73 // XTypeProvider impl.
77 // 2 interfaces supported
78 #define XTYPEPROVIDER_IMPL_2( Class, I1,I2 ) \
79 XTYPEPROVIDER_COMMON_IMPL( Class ) \
80 GETTYPES_IMPL_START( Class ) \
81 CPPU_TYPE_REF( I1 ), \
82 CPPU_TYPE_REF( I2 ) \
83 GETTYPES_IMPL_END
85 // 3 interfaces supported
86 #define XTYPEPROVIDER_IMPL_3( Class, I1,I2,I3 ) \
87 XTYPEPROVIDER_COMMON_IMPL( Class ) \
88 GETTYPES_IMPL_START( Class ) \
89 CPPU_TYPE_REF( I1 ), \
90 CPPU_TYPE_REF( I2 ), \
91 CPPU_TYPE_REF( I3 ) \
92 GETTYPES_IMPL_END
94 // 4 interfaces supported
95 #define XTYPEPROVIDER_IMPL_4( Class, I1,I2,I3,I4 ) \
96 XTYPEPROVIDER_COMMON_IMPL( Class ) \
97 GETTYPES_IMPL_START( Class ) \
98 CPPU_TYPE_REF( I1 ), \
99 CPPU_TYPE_REF( I2 ), \
100 CPPU_TYPE_REF( I3 ), \
101 CPPU_TYPE_REF( I4 ) \
102 GETTYPES_IMPL_END
104 // 5 interfaces supported
105 #define XTYPEPROVIDER_IMPL_5( Class, I1,I2,I3,I4,I5 ) \
106 XTYPEPROVIDER_COMMON_IMPL( Class ) \
107 GETTYPES_IMPL_START( Class ) \
108 CPPU_TYPE_REF( I1 ), \
109 CPPU_TYPE_REF( I2 ), \
110 CPPU_TYPE_REF( I3 ), \
111 CPPU_TYPE_REF( I4 ), \
112 CPPU_TYPE_REF( I5 ) \
113 GETTYPES_IMPL_END
115 // 6 interfaces supported
116 #define XTYPEPROVIDER_IMPL_6( Class, I1,I2,I3,I4,I5,I6 ) \
117 XTYPEPROVIDER_COMMON_IMPL( Class ) \
118 GETTYPES_IMPL_START( Class ) \
119 CPPU_TYPE_REF( I1 ), \
120 CPPU_TYPE_REF( I2 ), \
121 CPPU_TYPE_REF( I3 ), \
122 CPPU_TYPE_REF( I4 ), \
123 CPPU_TYPE_REF( I5 ), \
124 CPPU_TYPE_REF( I6 ) \
125 GETTYPES_IMPL_END
127 // 7 interfaces supported
128 #define XTYPEPROVIDER_IMPL_7( Class, I1,I2,I3,I4,I5,I6,I7 ) \
129 XTYPEPROVIDER_COMMON_IMPL( Class ) \
130 GETTYPES_IMPL_START( Class ) \
131 CPPU_TYPE_REF( I1 ), \
132 CPPU_TYPE_REF( I2 ), \
133 CPPU_TYPE_REF( I3 ), \
134 CPPU_TYPE_REF( I4 ), \
135 CPPU_TYPE_REF( I5 ), \
136 CPPU_TYPE_REF( I6 ), \
137 CPPU_TYPE_REF( I7 ) \
138 GETTYPES_IMPL_END
140 // 8 interfaces supported
141 #define XTYPEPROVIDER_IMPL_8( Class, I1,I2,I3,I4,I5,I6,I7,I8 ) \
142 XTYPEPROVIDER_COMMON_IMPL( Class ) \
143 GETTYPES_IMPL_START( Class ) \
144 CPPU_TYPE_REF( I1 ), \
145 CPPU_TYPE_REF( I2 ), \
146 CPPU_TYPE_REF( I3 ), \
147 CPPU_TYPE_REF( I4 ), \
148 CPPU_TYPE_REF( I5 ), \
149 CPPU_TYPE_REF( I6 ), \
150 CPPU_TYPE_REF( I7 ), \
151 CPPU_TYPE_REF( I8 ) \
152 GETTYPES_IMPL_END
154 // 9 interfaces supported
155 #define XTYPEPROVIDER_IMPL_9( Class, I1,I2,I3,I4,I5,I6,I7,I8,I9 ) \
156 XTYPEPROVIDER_COMMON_IMPL( Class ) \
157 GETTYPES_IMPL_START( Class ) \
158 CPPU_TYPE_REF( I1 ), \
159 CPPU_TYPE_REF( I2 ), \
160 CPPU_TYPE_REF( I3 ), \
161 CPPU_TYPE_REF( I4 ), \
162 CPPU_TYPE_REF( I5 ), \
163 CPPU_TYPE_REF( I6 ), \
164 CPPU_TYPE_REF( I7 ), \
165 CPPU_TYPE_REF( I8 ), \
166 CPPU_TYPE_REF( I9 ) \
167 GETTYPES_IMPL_END
169 // 10 interfaces supported
170 #define XTYPEPROVIDER_IMPL_10( Class, I1,I2,I3,I4,I5,I6,I7,I8,I9,I10 ) \
171 XTYPEPROVIDER_COMMON_IMPL( Class ) \
172 GETTYPES_IMPL_START( Class ) \
173 CPPU_TYPE_REF( I1 ), \
174 CPPU_TYPE_REF( I2 ), \
175 CPPU_TYPE_REF( I3 ), \
176 CPPU_TYPE_REF( I4 ), \
177 CPPU_TYPE_REF( I5 ), \
178 CPPU_TYPE_REF( I6 ), \
179 CPPU_TYPE_REF( I7 ), \
180 CPPU_TYPE_REF( I8 ), \
181 CPPU_TYPE_REF( I9 ), \
182 CPPU_TYPE_REF( I10 ) \
183 GETTYPES_IMPL_END
185 // 11 interfaces supported
186 #define XTYPEPROVIDER_IMPL_11( Class, I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11 ) \
187 XTYPEPROVIDER_COMMON_IMPL( Class ) \
188 GETTYPES_IMPL_START( Class ) \
189 CPPU_TYPE_REF( I1 ), \
190 CPPU_TYPE_REF( I2 ), \
191 CPPU_TYPE_REF( I3 ), \
192 CPPU_TYPE_REF( I4 ), \
193 CPPU_TYPE_REF( I5 ), \
194 CPPU_TYPE_REF( I6 ), \
195 CPPU_TYPE_REF( I7 ), \
196 CPPU_TYPE_REF( I8 ), \
197 CPPU_TYPE_REF( I9 ), \
198 CPPU_TYPE_REF( I10 ), \
199 CPPU_TYPE_REF( I11 ) \
200 GETTYPES_IMPL_END
202 // XServiceInfo impl. internals
206 #define XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
207 OUString SAL_CALL Class::getImplementationName() \
208 throw( com::sun::star::uno::RuntimeException, std::exception ) \
210 return getImplementationName_Static(); \
213 OUString Class::getImplementationName_Static() \
215 return ImplName; \
218 sal_Bool SAL_CALL \
219 Class::supportsService( const OUString& ServiceName ) \
220 throw( com::sun::star::uno::RuntimeException, std::exception ) \
222 return cppu::supportsService( this, ServiceName ); \
225 com::sun::star::uno::Sequence< OUString > SAL_CALL \
226 Class::getSupportedServiceNames() \
227 throw( com::sun::star::uno::RuntimeException, std::exception ) \
229 return getSupportedServiceNames_Static(); \
232 #define XSERVICEINFO_CREATE_INSTANCE_IMPL( Class ) \
233 static com::sun::star::uno::Reference< \
234 com::sun::star::uno::XInterface > SAL_CALL \
235 Class##_CreateInstance( const com::sun::star::uno::Reference< \
236 com::sun::star::lang::XMultiServiceFactory> & rSMgr ) \
237 throw( com::sun::star::uno::Exception ) \
239 com::sun::star::lang::XServiceInfo* pX = \
240 (com::sun::star::lang::XServiceInfo*)new Class( rSMgr ); \
241 return com::sun::star::uno::Reference< \
242 com::sun::star::uno::XInterface >::query( pX ); \
245 #define XSERVICEINFO_CREATE_INSTANCE_IMPL_CTX( Class ) \
246 static com::sun::star::uno::Reference< \
247 com::sun::star::uno::XInterface > SAL_CALL \
248 Class##_CreateInstance( const com::sun::star::uno::Reference< \
249 com::sun::star::lang::XMultiServiceFactory> & rSMgr ) \
250 throw( com::sun::star::uno::Exception ) \
252 com::sun::star::lang::XServiceInfo* pX = \
253 (com::sun::star::lang::XServiceInfo*)new Class( ucbhelper::getComponentContext(rSMgr) ); \
254 return com::sun::star::uno::Reference< \
255 com::sun::star::uno::XInterface >::query( pX ); \
260 // XServiceInfo impl.
264 #define ONE_INSTANCE_SERVICE_FACTORY_IMPL( Class ) \
265 com::sun::star::uno::Reference< \
266 com::sun::star::lang::XSingleServiceFactory > \
267 Class::createServiceFactory( const com::sun::star::uno::Reference< \
268 com::sun::star::lang::XMultiServiceFactory >& rxServiceMgr ) \
270 return com::sun::star::uno::Reference< \
271 com::sun::star::lang::XSingleServiceFactory >( \
272 cppu::createOneInstanceFactory( \
273 rxServiceMgr, \
274 Class::getImplementationName_Static(), \
275 Class##_CreateInstance, \
276 Class::getSupportedServiceNames_Static() ) ); \
279 // Service without service factory.
281 // Own implementation of getSupportedServiceNames_Static().
282 #define XSERVICEINFO_NOFACTORY_IMPL_0( Class, ImplName ) \
283 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
285 com::sun::star::uno::Sequence< OUString > \
286 Class::getSupportedServiceNames_Static()
288 // 1 service name
289 #define XSERVICEINFO_NOFACTORY_IMPL_1( Class, ImplName, Service1 ) \
290 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
292 com::sun::star::uno::Sequence< OUString > \
293 Class::getSupportedServiceNames_Static() \
295 com::sun::star::uno::Sequence< OUString > aSNS( 1 ); \
296 aSNS.getArray()[ 0 ] = Service1; \
297 return aSNS; \
300 // Service with service factory.
302 // Own implementation of getSupportedServiceNames_Static().
303 #define XSERVICEINFO_IMPL_0( Class, ImplName ) \
304 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
305 XSERVICEINFO_CREATE_INSTANCE_IMPL( Class ) \
307 com::sun::star::uno::Sequence< OUString > \
308 Class::getSupportedServiceNames_Static()
310 // Own implementation of getSupportedServiceNames_Static().
311 #define XSERVICEINFO_IMPL_0_CTX( Class, ImplName ) \
312 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
313 XSERVICEINFO_CREATE_INSTANCE_IMPL_CTX( Class ) \
315 com::sun::star::uno::Sequence< OUString > \
316 Class::getSupportedServiceNames_Static()
318 // 1 service name
319 #define XSERVICEINFO_IMPL_1( Class, ImplName, Service1 ) \
320 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
321 XSERVICEINFO_CREATE_INSTANCE_IMPL( Class ) \
323 com::sun::star::uno::Sequence< OUString > \
324 Class::getSupportedServiceNames_Static() \
326 com::sun::star::uno::Sequence< OUString > aSNS( 1 ); \
327 aSNS.getArray()[ 0 ] = Service1; \
328 return aSNS; \
331 // 1 service name
332 #define XSERVICEINFO_IMPL_1_CTX( Class, ImplName, Service1 ) \
333 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
334 XSERVICEINFO_CREATE_INSTANCE_IMPL_CTX( Class ) \
336 com::sun::star::uno::Sequence< OUString > \
337 Class::getSupportedServiceNames_Static() \
339 com::sun::star::uno::Sequence< OUString > aSNS( 1 ); \
340 aSNS.getArray()[ 0 ] = Service1; \
341 return aSNS; \
344 #endif /* ! INCLUDED_UCBHELPER_MACROS_HXX */
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */