Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / inc / apitools.hxx
blobbf3302337036b85e4b129c2cc511789ba4423f96
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_DBACCESS_SOURCE_INC_APITOOLS_HXX
21 #define INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
23 #include <sal/config.h>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <cppuhelper/component.hxx>
27 #include <osl/mutex.hxx>
28 #include <cppuhelper/interfacecontainer.hxx>
29 #include <osl/diagnose.h>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <connectivity/CommonTools.hxx>
34 // OSubComponent - a component which holds a hard ref to its parent
35 // and is been hold itself (by the parent) with a weak ref
36 class OSubComponent : public ::cppu::OComponentHelper
38 protected:
39 // the parent must support the tunnel implementation
40 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xParent;
41 virtual ~OSubComponent();
43 public:
44 OSubComponent(::osl::Mutex& _rMutex,
45 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParent);
47 // ::com::sun::star::lang::XTypeProvider
48 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
50 // ::com::sun::star::uno::XInterface
51 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType )
52 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
53 virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
54 virtual void SAL_CALL release() throw() SAL_OVERRIDE;
56 inline operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > () const
57 { return (::com::sun::star::uno::XWeak *)this; }
61 // helper for implementing the XServiceInfo interface
63 // (internal - not to be used outside - usually)
64 #define IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
65 OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
66 { \
67 return OUString(implasciiname); \
68 } \
70 #define IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
71 OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
72 { \
73 return getImplementationName_Static(); \
74 } \
75 OUString SAL_CALL classname::getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException) \
76 { \
77 return OUString(implasciiname); \
78 } \
80 #define IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
81 sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
82 { \
83 ::com::sun::star::uno::Sequence< OUString > aSupported(getSupportedServiceNames()); \
84 const OUString* pSupported = aSupported.getConstArray(); \
85 for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) \
86 if (pSupported->equals(_rServiceName)) \
87 return sal_True; \
89 return sal_False; \
90 } \
92 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
93 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
94 { \
95 ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
96 aSupported[0] = serviceasciiname; \
97 return aSupported; \
98 } \
100 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
101 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
103 return getSupportedServiceNames_Static(); \
105 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
107 ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
108 aSupported[0] = serviceasciiname; \
109 return aSupported; \
112 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1, serviceasciiname2) \
113 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
115 return getSupportedServiceNames_Static(); \
117 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException) \
119 ::com::sun::star::uno::Sequence< OUString > aSupported(2); \
120 aSupported[0] = serviceasciiname1; \
121 aSupported[1] = serviceasciiname2; \
122 return aSupported; \
125 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
126 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
128 ::com::sun::star::uno::Sequence< OUString > aSupported(2); \
129 aSupported[0] = serviceasciiname1; \
130 aSupported[1] = serviceasciiname2; \
131 return aSupported; \
134 #define IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
135 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
137 ::com::sun::star::uno::Sequence< OUString > aSupported(3); \
138 aSupported[0] = serviceasciiname1; \
139 aSupported[1] = serviceasciiname2; \
140 aSupported[2] = serviceasciiname3; \
141 return aSupported; \
144 #define IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
145 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
146 SAL_CALL classname::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) \
148 return static_cast< XServiceInfo* >(new classname(_rxORB)); \
151 #define DECLARE_SERVICE_INFO_STATIC() \
152 DECLARE_SERVICE_INFO(); \
153 static OUString SAL_CALL getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); \
154 static ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); \
155 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > \
156 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&) \
158 #define IMPLEMENT_SERVICE_INFO1(classname, implasciiname, serviceasciiname) \
159 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
160 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
161 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
163 #define IMPLEMENT_SERVICE_INFO1_STATIC(classname, implasciiname, serviceasciiname) \
164 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
165 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
166 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(classname, serviceasciiname) \
167 IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
169 #define IMPLEMENT_SERVICE_INFO2(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
170 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
171 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
172 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2)
174 #define IMPLEMENT_SERVICE_INFO2_STATIC(classname, implasciiname, serviceasciiname1, serviceasciiname2) \
175 IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(classname, implasciiname) \
176 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
177 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2_STATIC(classname, serviceasciiname1,serviceasciiname2) \
178 IMPLEMENT_SERVICE_INFO_CREATE_STATIC(classname) \
180 #define IMPLEMENT_SERVICE_INFO3(classname, implasciiname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
181 IMPLEMENT_SERVICE_INFO_IMPLNAME(classname, implasciiname) \
182 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
183 IMPLEMENT_SERVICE_INFO_GETSUPPORTED3(classname, serviceasciiname1, serviceasciiname2, serviceasciiname3) \
185 #define IMPLEMENT_SERVICE_INFO1_ABSTRACT(classname, serviceasciiname) \
186 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
187 IMPLEMENT_SERVICE_INFO_GETSUPPORTED1(classname, serviceasciiname) \
189 #define IMPLEMENT_SERVICE_INFO2_ABSTRACT(classname, serviceasciiname1, serviceasciiname2) \
190 IMPLEMENT_SERVICE_INFO_SUPPORTS(classname) \
191 IMPLEMENT_SERVICE_INFO_GETSUPPORTED2(classname, serviceasciiname1, serviceasciiname2) \
193 // XTypeProvider helpers
195 #define DECLARE_IMPLEMENTATION_ID( ) \
196 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
197 static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId() \
199 #define DECLARE_GETTYPES( ) \
200 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException, std::exception);
202 #define DECLARE_TYPEPROVIDER( ) \
203 DECLARE_GETTYPES( ) \
204 DECLARE_IMPLEMENTATION_ID( )
206 #define IMPLEMENT_IMPLEMENTATION_ID( classname ) \
207 ::com::sun::star::uno::Sequence< sal_Int8 > classname::getUnoTunnelImplementationId() \
209 static ::cppu::OImplementationId* pId = 0; \
210 if ( !pId ) \
212 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); \
213 if ( !pId ) \
215 static ::cppu::OImplementationId aId; \
216 pId = &aId; \
219 return pId->getImplementationId(); \
221 ::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId() throw (::com::sun::star::uno::RuntimeException, std::exception) \
223 return css::uno::Sequence<sal_Int8>(); \
226 #define IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 ) \
227 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) \
229 return ::comphelper::concatSequences( \
230 baseclass1::getTypes( ), \
231 baseclass2::getTypes( ) \
232 ); \
235 #define IMPLEMENT_GETTYPES3( classname, baseclass1, baseclass2, baseclass3 ) \
236 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > classname::getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) \
238 return ::comphelper::concatSequences( \
239 baseclass1::getTypes( ), \
240 baseclass2::getTypes( ), \
241 baseclass3::getTypes( ) \
242 ); \
245 #define IMPLEMENT_TYPEPROVIDER2( classname, baseclass1, baseclass2 ) \
246 IMPLEMENT_IMPLEMENTATION_ID( classname) \
247 IMPLEMENT_GETTYPES2( classname, baseclass1, baseclass2 )
249 #define IMPLEMENT_TYPEPROVIDER3( classname, baseclass1, baseclass2, baseclass3 ) \
250 IMPLEMENT_IMPLEMENTATION_ID( classname) \
251 IMPLEMENT_GETTYPES3(classname, baseclass1, baseclass2, baseclass3 )
253 // helper for declaring/implementing classes based on the OPropertyContainer and an OPropertyArrayUsageHelper
254 #define DECLARE_PROPERTYCONTAINER_DEFAULTS( ) \
255 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
256 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE; \
257 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE
259 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname , baseclass1) \
260 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL classname::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException, std::exception) \
262 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); \
263 return xInfo; \
265 ::cppu::IPropertyArrayHelper& classname::getInfoHelper() \
267 return *baseclass1::getArrayHelper(); \
269 ::cppu::IPropertyArrayHelper* classname::createArrayHelper( ) const \
271 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; \
272 describeProperties(aProps); \
273 return new ::cppu::OPropertyArrayHelper(aProps); \
275 #define IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( classname ) \
276 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS2( classname, classname )
278 // helper for implementing the createArrayHelper
279 #define BEGIN_PROPERTY_SEQUENCE(count) \
280 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aDescriptor(count); \
281 ::com::sun::star::beans::Property* pDesc = aDescriptor.getArray(); \
282 sal_Int32 nPos = 0; \
284 #define BEGIN_PROPERTY_HELPER(count) \
285 BEGIN_PROPERTY_SEQUENCE(count)
287 #define DECL_PROP_IMPL(varname, cpputype) \
288 pDesc[nPos++] = ::com::sun::star::beans::Property(PROPERTY_##varname, PROPERTY_ID_##varname, cpputype,
290 #define DECL_PROP0(varname, type) \
291 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) 0)
293 #define DECL_PROP0_BOOL(varname) \
294 DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) 0)
296 #define DECL_PROP0_IFACE(varname, iface) \
297 DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) 0)
299 #define DECL_PROP1(varname, type, attrib1) \
300 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1)
302 #define DECL_PROP1_BOOL(varname, attrib1) \
303 DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1)
305 #define DECL_PROP1_IFACE(varname, iface, attrib1) \
306 DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1)
308 #define DECL_PROP2_IFACE(varname, iface, attrib1, attrib2) \
309 DECL_PROP_IMPL(varname, cppu::UnoType<iface>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
311 #define DECL_PROP2(varname, type, attrib1, attrib2) \
312 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
314 #define DECL_PROP2_BOOL(varname, attrib1, attrib2) \
315 DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2)
317 #define DECL_PROP3(varname, type, attrib1, attrib2, attrib3) \
318 DECL_PROP_IMPL(varname, cppu::UnoType<type>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
320 #define DECL_PROP3_BOOL(varname, attrib1, attrib2, attrib3) \
321 DECL_PROP_IMPL(varname, cppu::UnoType<bool>::get()) ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3)
323 #define END_PROPERTY_SEQUENCE() \
324 OSL_ENSURE(nPos == aDescriptor.getLength(), "forgot to adjust the count ?"); \
326 #define END_PROPERTY_HELPER() \
327 END_PROPERTY_SEQUENCE() \
328 return new ::cppu::OPropertyArrayHelper(aDescriptor);
330 #define NOTIFY_LISTERNERS(_rListeners,T,method) \
331 Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
333 const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
334 const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
336 _rGuard.clear(); \
337 while( pxInt > pxIntBegin ) \
339 try \
341 while( pxInt > pxIntBegin ) \
343 --pxInt; \
344 static_cast< T* >( pxInt->get() )->method(aEvt); \
347 catch( RuntimeException& ) \
351 _rGuard.reset();
353 #endif // INCLUDED_DBACCESS_SOURCE_INC_APITOOLS_HXX
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */