My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _CPPUHELPER_IMPLBASE_HXX_
29 #define _CPPUHELPER_IMPLBASE_HXX_
30 
31 #include <osl/mutex.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <cppuhelper/weakagg.hxx>
34 #include <rtl/instance.hxx>
35 
36 #include <com/sun/star/lang/XTypeProvider.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include "cppuhelperdllapi.h"
39 
40 /* This header should not be used anymore.
41  @deprecated
42 */
43 
45 
46 namespace cppu
47 {
48 
52 struct Type_Offset
53 {
56  sal_Int32 nOffset;
60 };
64 struct CPPUHELPER_DLLPUBLIC ClassDataBase
65 {
68  sal_Bool bOffsetsInit;
71  sal_Int32 nType2Offset;
72 
81  sal_Int32 nClassCode;
82 
89 
92  ClassDataBase() SAL_THROW(());
97  ClassDataBase( sal_Int32 nClassCode ) SAL_THROW(());
100  ~ClassDataBase() SAL_THROW(());
101 };
108 struct CPPUHELPER_DLLPUBLIC ClassData : public ClassDataBase
109 {
112  Type_Offset arType2Offset[1];
113 
116  void SAL_CALL initTypeProvider() SAL_THROW(());
122  void SAL_CALL writeTypeOffset( const ::com::sun::star::uno::Type & rType, sal_Int32 nOffset )
123  SAL_THROW(());
124 
131  ::com::sun::star::uno::Any SAL_CALL query(
132  const ::com::sun::star::uno::Type & rType, ::com::sun::star::lang::XTypeProvider * pBase )
133  SAL_THROW(());
138  ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
139  SAL_THROW(());
144  ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
145  SAL_THROW(());
146 };
147 
151 CPPUHELPER_DLLPUBLIC ::osl::Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW(());
152 }
153 
154 //
155 // settle down beavis, here comes the macro template hell :]
156 //
157 
158 //==================================================================================================
159 
160 #if defined _MSC_VER // public -> protected changes mangled names there
161 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED public
162 #else
163 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED protected
164 #endif
165 
179 #define __DEF_IMPLHELPER_PRE( N ) \
180 namespace cppu \
181 { \
182 struct ClassData##N : public ClassDataBase \
183 { \
184  Type_Offset arType2Offset[ N ]; \
185  ClassData##N( sal_Int32 nInClassCode ) SAL_THROW(()) \
186  : ClassDataBase( nInClassCode ) \
187  {} \
188 }; \
189 template< __CLASS_IFC##N > \
190 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelperBase##N \
191  : public ::com::sun::star::lang::XTypeProvider \
192  , __PUBLIC_IFC##N \
193 { \
194 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
195  ~ImplHelperBase##N() throw () {} \
196 protected: \
197  ClassData & SAL_CALL getClassData( ClassDataBase & s_aCD ) SAL_THROW(()) \
198  { \
199  ClassData & rCD = * static_cast< ClassData * >( &s_aCD ); \
200  if (! rCD.bOffsetsInit) \
201  { \
202  ::osl::MutexGuard aGuard( getImplHelperInitMutex() ); \
203  if (! rCD.bOffsetsInit) \
204  { \
205  char * pBase = (char *)this;
206 
208 #define __IFC_WRITEOFFSET( N ) \
209  rCD.writeTypeOffset( ::getCppuType( (const ::com::sun::star::uno::Reference< Ifc##N > *)0 ), \
210  (char *)(Ifc##N *)this - pBase );
211 
213 #define __DEF_IMPLHELPER_POST_A( N ) \
214  rCD.bOffsetsInit = sal_True; \
215  } \
216  } \
217  return rCD; \
218  } \
219 }; \
220 template< __CLASS_IFC##N > \
221 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelper##N \
222  : public ImplHelperBase##N< __IFC##N > \
223 { \
224  static ClassData##N s_aCD; \
225 public: \
226  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
227  { return this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ); } \
228  virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
229  { return this->getClassData( s_aCD ).getTypes(); } \
230  virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
231  { return this->getClassData( s_aCD ).getImplementationId(); } \
232 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
233  ~ImplHelper##N() throw () {} \
234 }; \
235 template< __CLASS_IFC##N > \
236 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper##N \
237  : public ::cppu::OWeakObject \
238  , public ImplHelperBase##N< __IFC##N > \
239 { \
240  static ClassData##N s_aCD; \
241 public: \
242  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
243  { \
244  ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
245  return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); \
246  } \
247  virtual void SAL_CALL acquire() throw () \
248  { OWeakObject::acquire(); } \
249  virtual void SAL_CALL release() throw () \
250  { OWeakObject::release(); } \
251  virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
252  { return this->getClassData( s_aCD ).getTypes(); } \
253  virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
254  { return this->getClassData( s_aCD ).getImplementationId(); } \
255 }; \
256 template< __CLASS_IFC##N > \
257 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakAggImplHelper##N \
258  : public ::cppu::OWeakAggObject \
259  , public ImplHelperBase##N< __IFC##N > \
260 { \
261  static ClassData##N s_aCD; \
262 public: \
263  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
264  { return OWeakAggObject::queryInterface( rType ); } \
265  virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
266  { \
267  ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
268  return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); \
269  } \
270  virtual void SAL_CALL acquire() throw () \
271  { OWeakAggObject::acquire(); } \
272  virtual void SAL_CALL release() throw () \
273  { OWeakAggObject::release(); } \
274  virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
275  { return this->getClassData( s_aCD ).getTypes(); } \
276  virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
277  { return this->getClassData( s_aCD ).getImplementationId(); } \
278 };
279 
282 #define __DEF_IMPLHELPER_POST_B( N ) \
283 template< __CLASS_IFC##N > \
284 ClassData##N ImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 0 ); \
285 template< __CLASS_IFC##N > \
286 ClassData##N WeakImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 1 ); \
287 template< __CLASS_IFC##N > \
288 ClassData##N WeakAggImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 2 );
289 
291 #define __DEF_IMPLHELPER_POST_C( N ) \
292 }
293 //==================================================================================================
296 #define __DEF_IMPLHELPER_POST( N ) \
297 __DEF_IMPLHELPER_POST_A( N ) \
298 __DEF_IMPLHELPER_POST_B( N ) \
299 __DEF_IMPLHELPER_POST_C( N )
300 
302 
303 #endif
304 
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */