UDK 3.2.7 C/C++ API Reference
cppuhelper/implbase.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 #ifndef _CPPUHELPER_IMPLBASE_HXX_
00029 #define _CPPUHELPER_IMPLBASE_HXX_
00030 
00031 #include <osl/mutex.hxx>
00032 #include <cppuhelper/weak.hxx>
00033 #include <cppuhelper/weakagg.hxx>
00034 #include <rtl/instance.hxx>
00035 
00036 #include <com/sun/star/lang/XTypeProvider.hpp>
00037 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
00038 #include "cppuhelperdllapi.h"
00039 
00040 /* This header should not be used anymore.
00041    @deprecated
00042 */
00043 
00045 
00046 namespace cppu
00047 {
00048 
00052 struct Type_Offset
00053 {
00056     sal_Int32 nOffset;
00059     typelib_InterfaceTypeDescription * pTD;
00060 };
00064 struct CPPUHELPER_DLLPUBLIC ClassDataBase
00065 {
00068     sal_Bool  bOffsetsInit;
00071     sal_Int32 nType2Offset;
00072 
00081     sal_Int32 nClassCode;
00082 
00085     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > * pTypes;
00088     ::com::sun::star::uno::Sequence< sal_Int8 > * pId;
00089 
00092     ClassDataBase() SAL_THROW(());
00097     ClassDataBase( sal_Int32 nClassCode ) SAL_THROW(());
00100     ~ClassDataBase() SAL_THROW(());
00101 };
00108 struct CPPUHELPER_DLLPUBLIC ClassData : public ClassDataBase
00109 {
00112     Type_Offset arType2Offset[1];
00113 
00116     void SAL_CALL initTypeProvider() SAL_THROW(());
00122     void SAL_CALL writeTypeOffset( const ::com::sun::star::uno::Type & rType, sal_Int32 nOffset )
00123         SAL_THROW(());
00124 
00131     ::com::sun::star::uno::Any SAL_CALL query(
00132         const ::com::sun::star::uno::Type & rType, ::com::sun::star::lang::XTypeProvider * pBase )
00133         SAL_THROW(());
00138     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
00139         SAL_THROW(());
00144     ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
00145         SAL_THROW(());
00146 };
00147 
00151 CPPUHELPER_DLLPUBLIC ::osl::Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW(());
00152 }
00153 
00154 //
00155 // settle down beavis, here comes the macro template hell :]
00156 //
00157 
00158 //==================================================================================================
00159 
00160 #if defined _MSC_VER // public -> protected changes mangled names there
00161 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED public
00162 #else
00163 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED protected
00164 #endif
00165 
00179 #define __DEF_IMPLHELPER_PRE( N ) \
00180 namespace cppu \
00181 { \
00182 struct ClassData##N : public ClassDataBase \
00183 { \
00184     Type_Offset arType2Offset[ N ]; \
00185     ClassData##N( sal_Int32 nInClassCode ) SAL_THROW(()) \
00186         : ClassDataBase( nInClassCode ) \
00187         {} \
00188 }; \
00189 template< __CLASS_IFC##N > \
00190 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelperBase##N \
00191     : public ::com::sun::star::lang::XTypeProvider \
00192     , __PUBLIC_IFC##N \
00193 { \
00194 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
00195     ~ImplHelperBase##N() throw () {} \
00196 protected: \
00197     ClassData & SAL_CALL getClassData( ClassDataBase & s_aCD ) SAL_THROW(()) \
00198     { \
00199         ClassData & rCD = * static_cast< ClassData * >( &s_aCD ); \
00200         if (! rCD.bOffsetsInit) \
00201         { \
00202             ::osl::MutexGuard aGuard( getImplHelperInitMutex() ); \
00203             if (! rCD.bOffsetsInit) \
00204             { \
00205                 char * pBase = (char *)this;
00206 
00208 #define __IFC_WRITEOFFSET( N ) \
00209                 rCD.writeTypeOffset( ::getCppuType( (const ::com::sun::star::uno::Reference< Ifc##N > *)0 ), \
00210                                      (char *)(Ifc##N *)this - pBase );
00211 
00213 #define __DEF_IMPLHELPER_POST_A( N ) \
00214                 rCD.bOffsetsInit = sal_True; \
00215             } \
00216         } \
00217         return rCD; \
00218     } \
00219 }; \
00220 template< __CLASS_IFC##N > \
00221 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelper##N \
00222     : public ImplHelperBase##N< __IFC##N > \
00223 { \
00224     static ClassData##N s_aCD; \
00225 public: \
00226     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00227         { return this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ); } \
00228     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
00229         { return this->getClassData( s_aCD ).getTypes(); } \
00230     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
00231         { return this->getClassData( s_aCD ).getImplementationId(); } \
00232 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
00233     ~ImplHelper##N() throw () {} \
00234 }; \
00235 template< __CLASS_IFC##N > \
00236 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper##N \
00237     : public ::cppu::OWeakObject \
00238     , public ImplHelperBase##N< __IFC##N > \
00239 { \
00240     static ClassData##N s_aCD; \
00241 public: \
00242     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00243     { \
00244         ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
00245         return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); \
00246     } \
00247     virtual void SAL_CALL acquire() throw () \
00248         { OWeakObject::acquire(); } \
00249     virtual void SAL_CALL release() throw () \
00250         { OWeakObject::release(); } \
00251     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
00252         { return this->getClassData( s_aCD ).getTypes(); } \
00253     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
00254         { return this->getClassData( s_aCD ).getImplementationId(); } \
00255 }; \
00256 template< __CLASS_IFC##N > \
00257 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakAggImplHelper##N \
00258     : public ::cppu::OWeakAggObject \
00259     , public ImplHelperBase##N< __IFC##N > \
00260 { \
00261     static ClassData##N s_aCD; \
00262 public: \
00263     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00264         { return OWeakAggObject::queryInterface( rType ); } \
00265     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00266     { \
00267         ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
00268         return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); \
00269     } \
00270     virtual void SAL_CALL acquire() throw () \
00271         { OWeakAggObject::acquire(); } \
00272     virtual void SAL_CALL release() throw () \
00273         { OWeakAggObject::release(); } \
00274     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
00275         { return this->getClassData( s_aCD ).getTypes(); } \
00276     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
00277         { return this->getClassData( s_aCD ).getImplementationId(); } \
00278 };
00279 
00282 #define __DEF_IMPLHELPER_POST_B( N ) \
00283 template< __CLASS_IFC##N > \
00284 ClassData##N ImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 0 ); \
00285 template< __CLASS_IFC##N > \
00286 ClassData##N WeakImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 1 ); \
00287 template< __CLASS_IFC##N > \
00288 ClassData##N WeakAggImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 2 );
00289 
00291 #define __DEF_IMPLHELPER_POST_C( N ) \
00292 }
00293 //==================================================================================================
00296 #define __DEF_IMPLHELPER_POST( N ) \
00297 __DEF_IMPLHELPER_POST_A( N ) \
00298 __DEF_IMPLHELPER_POST_B( N ) \
00299 __DEF_IMPLHELPER_POST_C( N )
00300 
00302 
00303 #endif
00304 
00305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines