Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / ucbhelper / macros.hxx
blob57de0edcc72544ab84b7f9f44ec97b0aadefac3d
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>
34 #define CPPU_TYPE( T ) cppu::UnoType<T>::get()
35 #define CPPU_TYPE_REF( T ) CPPU_TYPE( T )
37 // XTypeProvider impl. internals
40 #define XTYPEPROVIDER_COMMON_IMPL( Class ) \
41 css::uno::Sequence< sal_Int8 > SAL_CALL \
42 Class::getImplementationId() \
43 throw( css::uno::RuntimeException, std::exception ) \
44 { \
45 return css::uno::Sequence<sal_Int8>(); \
48 #define GETTYPES_IMPL_START( Class ) \
49 css::uno::Sequence< css::uno::Type > SAL_CALL \
50 Class::getTypes() \
51 throw( css::uno::RuntimeException, std::exception ) \
52 { \
53 static cppu::OTypeCollection* pCollection = nullptr; \
54 if ( !pCollection ) \
55 { \
56 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); \
57 if ( !pCollection ) \
58 { \
59 static cppu::OTypeCollection collection(
61 #define GETTYPES_IMPL_END \
62 ); \
63 pCollection = &collection; \
64 } \
65 } \
66 return (*pCollection).getTypes(); \
70 // XTypeProvider impl.
73 // 2 interfaces supported
74 #define XTYPEPROVIDER_IMPL_2( Class, I1,I2 ) \
75 XTYPEPROVIDER_COMMON_IMPL( Class ) \
76 GETTYPES_IMPL_START( Class ) \
77 CPPU_TYPE_REF( I1 ), \
78 CPPU_TYPE_REF( I2 ) \
79 GETTYPES_IMPL_END
81 // 3 interfaces supported
82 #define XTYPEPROVIDER_IMPL_3( Class, I1,I2,I3 ) \
83 XTYPEPROVIDER_COMMON_IMPL( Class ) \
84 GETTYPES_IMPL_START( Class ) \
85 CPPU_TYPE_REF( I1 ), \
86 CPPU_TYPE_REF( I2 ), \
87 CPPU_TYPE_REF( I3 ) \
88 GETTYPES_IMPL_END
90 // 4 interfaces supported
91 #define XTYPEPROVIDER_IMPL_4( Class, I1,I2,I3,I4 ) \
92 XTYPEPROVIDER_COMMON_IMPL( Class ) \
93 GETTYPES_IMPL_START( Class ) \
94 CPPU_TYPE_REF( I1 ), \
95 CPPU_TYPE_REF( I2 ), \
96 CPPU_TYPE_REF( I3 ), \
97 CPPU_TYPE_REF( I4 ) \
98 GETTYPES_IMPL_END
100 // 5 interfaces supported
101 #define XTYPEPROVIDER_IMPL_5( Class, I1,I2,I3,I4,I5 ) \
102 XTYPEPROVIDER_COMMON_IMPL( Class ) \
103 GETTYPES_IMPL_START( Class ) \
104 CPPU_TYPE_REF( I1 ), \
105 CPPU_TYPE_REF( I2 ), \
106 CPPU_TYPE_REF( I3 ), \
107 CPPU_TYPE_REF( I4 ), \
108 CPPU_TYPE_REF( I5 ) \
109 GETTYPES_IMPL_END
111 // 9 interfaces supported
112 #define XTYPEPROVIDER_IMPL_9( Class, I1,I2,I3,I4,I5,I6,I7,I8,I9 ) \
113 XTYPEPROVIDER_COMMON_IMPL( Class ) \
114 GETTYPES_IMPL_START( Class ) \
115 CPPU_TYPE_REF( I1 ), \
116 CPPU_TYPE_REF( I2 ), \
117 CPPU_TYPE_REF( I3 ), \
118 CPPU_TYPE_REF( I4 ), \
119 CPPU_TYPE_REF( I5 ), \
120 CPPU_TYPE_REF( I6 ), \
121 CPPU_TYPE_REF( I7 ), \
122 CPPU_TYPE_REF( I8 ), \
123 CPPU_TYPE_REF( I9 ) \
124 GETTYPES_IMPL_END
126 // 10 interfaces supported
127 #define XTYPEPROVIDER_IMPL_10( Class, I1,I2,I3,I4,I5,I6,I7,I8,I9,I10 ) \
128 XTYPEPROVIDER_COMMON_IMPL( Class ) \
129 GETTYPES_IMPL_START( Class ) \
130 CPPU_TYPE_REF( I1 ), \
131 CPPU_TYPE_REF( I2 ), \
132 CPPU_TYPE_REF( I3 ), \
133 CPPU_TYPE_REF( I4 ), \
134 CPPU_TYPE_REF( I5 ), \
135 CPPU_TYPE_REF( I6 ), \
136 CPPU_TYPE_REF( I7 ), \
137 CPPU_TYPE_REF( I8 ), \
138 CPPU_TYPE_REF( I9 ), \
139 CPPU_TYPE_REF( I10 ) \
140 GETTYPES_IMPL_END
142 // 11 interfaces supported
143 #define XTYPEPROVIDER_IMPL_11( Class, I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11 ) \
144 XTYPEPROVIDER_COMMON_IMPL( Class ) \
145 GETTYPES_IMPL_START( Class ) \
146 CPPU_TYPE_REF( I1 ), \
147 CPPU_TYPE_REF( I2 ), \
148 CPPU_TYPE_REF( I3 ), \
149 CPPU_TYPE_REF( I4 ), \
150 CPPU_TYPE_REF( I5 ), \
151 CPPU_TYPE_REF( I6 ), \
152 CPPU_TYPE_REF( I7 ), \
153 CPPU_TYPE_REF( I8 ), \
154 CPPU_TYPE_REF( I9 ), \
155 CPPU_TYPE_REF( I10 ), \
156 CPPU_TYPE_REF( I11 ) \
157 GETTYPES_IMPL_END
159 // XServiceInfo impl. internals
162 #define XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
163 OUString SAL_CALL Class::getImplementationName() \
164 throw( css::uno::RuntimeException, std::exception ) \
166 return getImplementationName_Static(); \
169 OUString Class::getImplementationName_Static() \
171 return ImplName; \
174 sal_Bool SAL_CALL \
175 Class::supportsService( const OUString& ServiceName ) \
176 throw( css::uno::RuntimeException, std::exception ) \
178 return cppu::supportsService( this, ServiceName ); \
181 css::uno::Sequence< OUString > SAL_CALL \
182 Class::getSupportedServiceNames() \
183 throw( css::uno::RuntimeException, std::exception ) \
185 return getSupportedServiceNames_Static(); \
188 #define XSERVICEINFO_CREATE_INSTANCE_IMPL_CTX( Class ) \
189 static css::uno::Reference< css::uno::XInterface > SAL_CALL \
190 Class##_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr ) \
191 throw( css::uno::Exception ) \
193 css::lang::XServiceInfo* pX = \
194 static_cast<css::lang::XServiceInfo*>(new Class( ucbhelper::getComponentContext(rSMgr) )); \
195 return css::uno::Reference< css::uno::XInterface >::query( pX ); \
199 // XServiceInfo impl.
202 #define ONE_INSTANCE_SERVICE_FACTORY_IMPL( Class ) \
203 css::uno::Reference< css::lang::XSingleServiceFactory > \
204 Class::createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& rxServiceMgr ) \
206 return css::uno::Reference< \
207 css::lang::XSingleServiceFactory >( \
208 cppu::createOneInstanceFactory( \
209 rxServiceMgr, \
210 Class::getImplementationName_Static(), \
211 Class##_CreateInstance, \
212 Class::getSupportedServiceNames_Static() ) ); \
215 // Service without service factory.
217 // Own implementation of getSupportedServiceNames_Static().
218 #define XSERVICEINFO_NOFACTORY_IMPL_0( Class, ImplName ) \
219 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
221 css::uno::Sequence< OUString > \
222 Class::getSupportedServiceNames_Static()
224 // 1 service name
225 #define XSERVICEINFO_NOFACTORY_IMPL_1( Class, ImplName, Service1 ) \
226 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
228 css::uno::Sequence< OUString > \
229 Class::getSupportedServiceNames_Static() \
231 css::uno::Sequence< OUString > aSNS { Service1 }; \
232 return aSNS; \
235 // Service with service factory.
237 // Own implementation of getSupportedServiceNames_Static().
238 #define XSERVICEINFO_IMPL_0_CTX( Class, ImplName ) \
239 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
240 XSERVICEINFO_CREATE_INSTANCE_IMPL_CTX( Class ) \
242 css::uno::Sequence< OUString > \
243 Class::getSupportedServiceNames_Static()
245 // 1 service name
246 #define XSERVICEINFO_IMPL_1( Class, ImplName, Service1 ) \
247 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
248 static css::uno::Reference< css::uno::XInterface > SAL_CALL \
249 Class##_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr ) \
250 throw( css::uno::Exception ) \
252 css::lang::XServiceInfo* pX = \
253 static_cast<css::lang::XServiceInfo*>(new Class( rSMgr )); \
254 return css::uno::Reference< css::uno::XInterface >::query( pX ); \
256 css::uno::Sequence< OUString > \
257 Class::getSupportedServiceNames_Static() \
259 return css::uno::Sequence< OUString > { Service1 }; \
262 // 1 service name
263 #define XSERVICEINFO_IMPL_1_CTX( Class, ImplName, Service1 ) \
264 XSERVICEINFO_COMMOM_IMPL( Class, ImplName ) \
265 XSERVICEINFO_CREATE_INSTANCE_IMPL_CTX( Class ) \
267 css::uno::Sequence< OUString > \
268 Class::getSupportedServiceNames_Static() \
270 css::uno::Sequence< OUString > aSNS { Service1 }; \
271 return aSNS; \
274 #endif /* ! INCLUDED_UCBHELPER_MACROS_HXX */
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */