LibreOffice
LibreOffice 4.3 SDK C/C++ API Reference
implbase.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_CPPUHELPER_IMPLBASE_HXX
20 #define INCLUDED_CPPUHELPER_IMPLBASE_HXX
21 
22 #include <osl/mutex.hxx>
23 #include <cppuhelper/weak.hxx>
24 #include <cppuhelper/weakagg.hxx>
25 #include <rtl/instance.hxx>
26 
27 #include <com/sun/star/lang/XTypeProvider.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 
31 /* This header should not be used anymore.
32  @deprecated
33 */
34 
36 
37 namespace cppu
38 {
39 
43 struct Type_Offset
44 {
47  sal_Int32 nOffset;
51 };
55 struct CPPUHELPER_DLLPUBLIC ClassDataBase
56 {
59  sal_Bool bOffsetsInit;
62  sal_Int32 nType2Offset;
63 
72  sal_Int32 nClassCode;
73 
81 
84  ClassDataBase() SAL_THROW(());
89  ClassDataBase( sal_Int32 nClassCode ) SAL_THROW(());
92  ~ClassDataBase() SAL_THROW(());
93 };
100 struct CPPUHELPER_DLLPUBLIC ClassData : public ClassDataBase
101 {
104  Type_Offset arType2Offset[1];
105 
108  void SAL_CALL initTypeProvider() SAL_THROW(());
114  void SAL_CALL writeTypeOffset( const ::com::sun::star::uno::Type & rType, sal_Int32 nOffset )
115  SAL_THROW(());
116 
123  ::com::sun::star::uno::Any SAL_CALL query(
124  const ::com::sun::star::uno::Type & rType, ::com::sun::star::lang::XTypeProvider * pBase )
125  SAL_THROW(());
130  ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
131  SAL_THROW(());
136  ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
137  SAL_THROW(());
138 };
139 
143 CPPUHELPER_DLLPUBLIC ::osl::Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW(());
144 }
145 
146 
147 // settle down beavis, here comes the macro template hell :]
148 
149 
150 
151 
152 #if defined _MSC_VER // public -> protected changes mangled names there
153 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED public
154 #else
155 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED protected
156 #endif
157 
171 #define __DEF_IMPLHELPER_PRE( N ) \
172 namespace cppu \
173 { \
174 struct ClassData##N : public ClassDataBase \
175 { \
176  Type_Offset arType2Offset[ N ]; \
177  ClassData##N( sal_Int32 nInClassCode ) SAL_THROW(()) \
178  : ClassDataBase( nInClassCode ) \
179  {} \
180 }; \
181 template< __CLASS_IFC##N > \
182 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelperBase##N \
183  : public ::com::sun::star::lang::XTypeProvider \
184  , __PUBLIC_IFC##N \
185 { \
186 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
187  ~ImplHelperBase##N() throw () {} \
188 protected: \
189  ClassData & SAL_CALL getClassData( ClassDataBase & s_aCD ) SAL_THROW(()) \
190  { \
191  ClassData & rCD = * static_cast< ClassData * >( &s_aCD ); \
192  if (! rCD.bOffsetsInit) \
193  { \
194  ::osl::MutexGuard aGuard( getImplHelperInitMutex() ); \
195  if (! rCD.bOffsetsInit) \
196  { \
197  char * pBase = (char *)this;
198 
200 #define __IFC_WRITEOFFSET( N ) \
201  rCD.writeTypeOffset( ::getCppuType( (const ::com::sun::star::uno::Reference< Ifc##N > *)0 ), \
202  (char *)(Ifc##N *)this - pBase );
203 
205 #define __DEF_IMPLHELPER_POST_A( N ) \
206  rCD.bOffsetsInit = sal_True; \
207  } \
208  } \
209  return rCD; \
210  } \
211 }; \
212 template< __CLASS_IFC##N > \
213 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelper##N \
214  : public ImplHelperBase##N< __IFC##N > \
215 { \
216  static ClassData##N s_aCD; \
217 public: \
218  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
219  { return this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ); } \
220  virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
221  { return this->getClassData( s_aCD ).getTypes(); } \
222  virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
223  { return this->getClassData( s_aCD ).getImplementationId(); } \
224 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
225  ~ImplHelper##N() throw () {} \
226 }; \
227 template< __CLASS_IFC##N > \
228 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper##N \
229  : public ::cppu::OWeakObject \
230  , public ImplHelperBase##N< __IFC##N > \
231 { \
232  static ClassData##N s_aCD; \
233 public: \
234  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
235  { \
236  ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
237  return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); \
238  } \
239  virtual void SAL_CALL acquire() throw () \
240  { OWeakObject::acquire(); } \
241  virtual void SAL_CALL release() throw () \
242  { OWeakObject::release(); } \
243  virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
244  { return this->getClassData( s_aCD ).getTypes(); } \
245  virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
246  { return this->getClassData( s_aCD ).getImplementationId(); } \
247 }; \
248 template< __CLASS_IFC##N > \
249 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakAggImplHelper##N \
250  : public ::cppu::OWeakAggObject \
251  , public ImplHelperBase##N< __IFC##N > \
252 { \
253  static ClassData##N s_aCD; \
254 public: \
255  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
256  { return OWeakAggObject::queryInterface( rType ); } \
257  virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
258  { \
259  ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
260  return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); \
261  } \
262  virtual void SAL_CALL acquire() throw () \
263  { OWeakAggObject::acquire(); } \
264  virtual void SAL_CALL release() throw () \
265  { OWeakAggObject::release(); } \
266  virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
267  { return this->getClassData( s_aCD ).getTypes(); } \
268  virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
269  { return this->getClassData( s_aCD ).getImplementationId(); } \
270 };
271 
274 #define __DEF_IMPLHELPER_POST_B( N ) \
275 template< __CLASS_IFC##N > \
276 ClassData##N ImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 0 ); \
277 template< __CLASS_IFC##N > \
278 ClassData##N WeakImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 1 ); \
279 template< __CLASS_IFC##N > \
280 ClassData##N WeakAggImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 2 );
281 
283 #define __DEF_IMPLHELPER_POST_C( N ) \
284 }
285 
288 #define __DEF_IMPLHELPER_POST( N ) \
289 __DEF_IMPLHELPER_POST_A( N ) \
290 __DEF_IMPLHELPER_POST_B( N ) \
291 __DEF_IMPLHELPER_POST_C( N )
292 
294 
295 #endif
296 
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unsigned char sal_Bool
Definition: types.h:46
signed char sal_Int8
Definition: types.h:51
Definition: conditn.hxx:30
Definition: Enterable.hxx:26
Type description of an interface.
Definition: typedescription.h:370
#define SAL_THROW(x)
Exception specification documentation.
Definition: types.h:361
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
Definition: types.h:391