00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _CPPUHELPER_IMPLBASE_HXX_
00020 #define _CPPUHELPER_IMPLBASE_HXX_
00021
00022 #include <osl/mutex.hxx>
00023 #include <cppuhelper/weak.hxx>
00024 #include <cppuhelper/weakagg.hxx>
00025 #include <rtl/instance.hxx>
00026
00027 #include <com/sun/star/lang/XTypeProvider.hpp>
00028 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
00029 #include "cppuhelperdllapi.h"
00030
00031
00032
00033
00034
00036
00037 namespace cppu
00038 {
00039
00043 struct Type_Offset
00044 {
00047 sal_Int32 nOffset;
00050 typelib_InterfaceTypeDescription * pTD;
00051 };
00055 struct CPPUHELPER_DLLPUBLIC ClassDataBase
00056 {
00059 sal_Bool bOffsetsInit;
00062 sal_Int32 nType2Offset;
00063
00072 sal_Int32 nClassCode;
00073
00076 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > * pTypes;
00079 ::com::sun::star::uno::Sequence< sal_Int8 > * pId;
00080
00083 ClassDataBase() SAL_THROW(());
00088 ClassDataBase( sal_Int32 nClassCode ) SAL_THROW(());
00091 ~ClassDataBase() SAL_THROW(());
00092 };
00099 struct CPPUHELPER_DLLPUBLIC ClassData : public ClassDataBase
00100 {
00103 Type_Offset arType2Offset[1];
00104
00107 void SAL_CALL initTypeProvider() SAL_THROW(());
00113 void SAL_CALL writeTypeOffset( const ::com::sun::star::uno::Type & rType, sal_Int32 nOffset )
00114 SAL_THROW(());
00115
00122 ::com::sun::star::uno::Any SAL_CALL query(
00123 const ::com::sun::star::uno::Type & rType, ::com::sun::star::lang::XTypeProvider * pBase )
00124 SAL_THROW(());
00129 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
00130 SAL_THROW(());
00135 ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
00136 SAL_THROW(());
00137 };
00138
00142 CPPUHELPER_DLLPUBLIC ::osl::Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW(());
00143 }
00144
00145
00146
00147
00148
00149
00150
00151 #if defined _MSC_VER // public -> protected changes mangled names there
00152 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED public
00153 #else
00154 #define CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED protected
00155 #endif
00156
00170 #define __DEF_IMPLHELPER_PRE( N ) \
00171 namespace cppu \
00172 { \
00173 struct ClassData##N : public ClassDataBase \
00174 { \
00175 Type_Offset arType2Offset[ N ]; \
00176 ClassData##N( sal_Int32 nInClassCode ) SAL_THROW(()) \
00177 : ClassDataBase( nInClassCode ) \
00178 {} \
00179 }; \
00180 template< __CLASS_IFC##N > \
00181 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelperBase##N \
00182 : public ::com::sun::star::lang::XTypeProvider \
00183 , __PUBLIC_IFC##N \
00184 { \
00185 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
00186 ~ImplHelperBase##N() throw () {} \
00187 protected: \
00188 ClassData & SAL_CALL getClassData( ClassDataBase & s_aCD ) SAL_THROW(()) \
00189 { \
00190 ClassData & rCD = * static_cast< ClassData * >( &s_aCD ); \
00191 if (! rCD.bOffsetsInit) \
00192 { \
00193 ::osl::MutexGuard aGuard( getImplHelperInitMutex() ); \
00194 if (! rCD.bOffsetsInit) \
00195 { \
00196 char * pBase = (char *)this;
00197
00199 #define __IFC_WRITEOFFSET( N ) \
00200 rCD.writeTypeOffset( ::getCppuType( (const ::com::sun::star::uno::Reference< Ifc##N > *)0 ), \
00201 (char *)(Ifc##N *)this - pBase );
00202
00204 #define __DEF_IMPLHELPER_POST_A( N ) \
00205 rCD.bOffsetsInit = sal_True; \
00206 } \
00207 } \
00208 return rCD; \
00209 } \
00210 }; \
00211 template< __CLASS_IFC##N > \
00212 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplHelper##N \
00213 : public ImplHelperBase##N< __IFC##N > \
00214 { \
00215 static ClassData##N s_aCD; \
00216 public: \
00217 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00218 { return this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ); } \
00219 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
00220 { return this->getClassData( s_aCD ).getTypes(); } \
00221 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
00222 { return this->getClassData( s_aCD ).getImplementationId(); } \
00223 CPPUHELPER_DETAIL_IMPLHELPER_PROTECTED: \
00224 ~ImplHelper##N() throw () {} \
00225 }; \
00226 template< __CLASS_IFC##N > \
00227 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper##N \
00228 : public ::cppu::OWeakObject \
00229 , public ImplHelperBase##N< __IFC##N > \
00230 { \
00231 static ClassData##N s_aCD; \
00232 public: \
00233 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00234 { \
00235 ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
00236 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); \
00237 } \
00238 virtual void SAL_CALL acquire() throw () \
00239 { OWeakObject::acquire(); } \
00240 virtual void SAL_CALL release() throw () \
00241 { OWeakObject::release(); } \
00242 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
00243 { return this->getClassData( s_aCD ).getTypes(); } \
00244 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
00245 { return this->getClassData( s_aCD ).getImplementationId(); } \
00246 }; \
00247 template< __CLASS_IFC##N > \
00248 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakAggImplHelper##N \
00249 : public ::cppu::OWeakAggObject \
00250 , public ImplHelperBase##N< __IFC##N > \
00251 { \
00252 static ClassData##N s_aCD; \
00253 public: \
00254 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00255 { return OWeakAggObject::queryInterface( rType ); } \
00256 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) throw (::com::sun::star::uno::RuntimeException) \
00257 { \
00258 ::com::sun::star::uno::Any aRet( this->getClassData( s_aCD ).query( rType, (ImplHelperBase##N< __IFC##N > *)this ) ); \
00259 return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); \
00260 } \
00261 virtual void SAL_CALL acquire() throw () \
00262 { OWeakAggObject::acquire(); } \
00263 virtual void SAL_CALL release() throw () \
00264 { OWeakAggObject::release(); } \
00265 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException) \
00266 { return this->getClassData( s_aCD ).getTypes(); } \
00267 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException) \
00268 { return this->getClassData( s_aCD ).getImplementationId(); } \
00269 };
00270
00273 #define __DEF_IMPLHELPER_POST_B( N ) \
00274 template< __CLASS_IFC##N > \
00275 ClassData##N ImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 0 ); \
00276 template< __CLASS_IFC##N > \
00277 ClassData##N WeakImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 1 ); \
00278 template< __CLASS_IFC##N > \
00279 ClassData##N WeakAggImplHelper##N< __IFC##N >::s_aCD = ClassData##N( 2 );
00280
00282 #define __DEF_IMPLHELPER_POST_C( N ) \
00283 }
00284
00287 #define __DEF_IMPLHELPER_POST( N ) \
00288 __DEF_IMPLHELPER_POST_A( N ) \
00289 __DEF_IMPLHELPER_POST_B( N ) \
00290 __DEF_IMPLHELPER_POST_C( N )
00291
00293
00294 #endif
00295
00296