UDK 3.2.7 C/C++ API Reference
|
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 _COM_SUN_STAR_UNO_SEQUENCE_HXX_ 00029 #define _COM_SUN_STAR_UNO_SEQUENCE_HXX_ 00030 00031 #include "osl/diagnose.h" 00032 #include "osl/interlck.h" 00033 #include "com/sun/star/uno/Sequence.h" 00034 #include "typelib/typedescription.h" 00035 #include "uno/data.h" 00036 #include "com/sun/star/uno/genfunc.hxx" 00037 #include "cppu/unotype.hxx" 00038 00039 namespace com 00040 { 00041 namespace sun 00042 { 00043 namespace star 00044 { 00045 namespace uno 00046 { 00047 00049 template< class E > 00050 typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0; 00052 00053 //______________________________________________________________________________ 00054 template< class E > 00055 inline Sequence< E >::Sequence() SAL_THROW(()) 00056 { 00057 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00058 ::uno_type_sequence_construct( 00059 &_pSequence, rType.getTypeLibType(), 00060 0, 0, (uno_AcquireFunc)cpp_acquire ); 00061 // no bad_alloc, because empty sequence is statically allocated in cppu 00062 } 00063 00064 //______________________________________________________________________________ 00065 template< class E > 00066 inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(()) 00067 { 00068 ::osl_incrementInterlockedCount( &rSeq._pSequence->nRefCount ); 00069 _pSequence = rSeq._pSequence; 00070 } 00071 00072 //______________________________________________________________________________ 00073 template< class E > 00074 inline Sequence< E >::Sequence( 00075 uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(()) 00076 : _pSequence( pSequence ) 00077 { 00078 } 00079 00080 //______________________________________________________________________________ 00081 template< class E > 00082 inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len ) 00083 { 00084 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00085 #if ! defined EXCEPTIONS_OFF 00086 sal_Bool success = 00087 #endif 00088 ::uno_type_sequence_construct( 00089 &_pSequence, rType.getTypeLibType(), 00090 const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire ); 00091 #if ! defined EXCEPTIONS_OFF 00092 if (! success) 00093 throw ::std::bad_alloc(); 00094 #endif 00095 } 00096 00097 //______________________________________________________________________________ 00098 template< class E > 00099 inline Sequence< E >::Sequence( sal_Int32 len ) 00100 { 00101 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00102 #if ! defined EXCEPTIONS_OFF 00103 sal_Bool success = 00104 #endif 00105 ::uno_type_sequence_construct( 00106 &_pSequence, rType.getTypeLibType(), 00107 0, len, (uno_AcquireFunc)cpp_acquire ); 00108 #if ! defined EXCEPTIONS_OFF 00109 if (! success) 00110 throw ::std::bad_alloc(); 00111 #endif 00112 } 00113 00114 //______________________________________________________________________________ 00115 template< class E > 00116 inline Sequence< E >::~Sequence() SAL_THROW(()) 00117 { 00118 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00119 ::uno_type_destructData( 00120 this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release ); 00121 } 00122 00123 //______________________________________________________________________________ 00124 template< class E > 00125 inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(()) 00126 { 00127 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00128 ::uno_type_sequence_assign( 00129 &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release ); 00130 return *this; 00131 } 00132 00133 //______________________________________________________________________________ 00134 template< class E > 00135 inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const 00136 SAL_THROW(()) 00137 { 00138 if (_pSequence == rSeq._pSequence) 00139 return sal_True; 00140 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00141 return ::uno_type_equalData( 00142 const_cast< Sequence< E > * >( this ), rType.getTypeLibType(), 00143 const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(), 00144 (uno_QueryInterfaceFunc)cpp_queryInterface, 00145 (uno_ReleaseFunc)cpp_release ); 00146 } 00147 00148 //______________________________________________________________________________ 00149 template< class E > 00150 inline sal_Bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const 00151 SAL_THROW(()) 00152 { 00153 return (! operator == ( rSeq )); 00154 } 00155 00156 //______________________________________________________________________________ 00157 template< class E > 00158 inline E * Sequence< E >::getArray() 00159 { 00160 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00161 #if ! defined EXCEPTIONS_OFF 00162 sal_Bool success = 00163 #endif 00164 ::uno_type_sequence_reference2One( 00165 &_pSequence, rType.getTypeLibType(), 00166 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); 00167 #if ! defined EXCEPTIONS_OFF 00168 if (! success) 00169 throw ::std::bad_alloc(); 00170 #endif 00171 return reinterpret_cast< E * >( _pSequence->elements ); 00172 } 00173 00174 //______________________________________________________________________________ 00175 template< class E > 00176 inline E & Sequence< E >::operator [] ( sal_Int32 nIndex ) 00177 { 00178 OSL_ENSURE( 00179 nIndex >= 0 && nIndex < getLength(), 00180 "### illegal index of sequence!" ); 00181 return getArray()[ nIndex ]; 00182 } 00183 00184 //______________________________________________________________________________ 00185 template< class E > 00186 inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const 00187 SAL_THROW(()) 00188 { 00189 OSL_ENSURE( 00190 nIndex >= 0 && nIndex < getLength(), 00191 "### illegal index of sequence!" ); 00192 return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ]; 00193 } 00194 00195 //______________________________________________________________________________ 00196 template< class E > 00197 inline void Sequence< E >::realloc( sal_Int32 nSize ) 00198 { 00199 const Type & rType = ::cppu::getTypeFavourUnsigned( this ); 00200 #if !defined EXCEPTIONS_OFF 00201 sal_Bool success = 00202 #endif 00203 ::uno_type_sequence_realloc( 00204 &_pSequence, rType.getTypeLibType(), nSize, 00205 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release ); 00206 #if !defined EXCEPTIONS_OFF 00207 if (!success) 00208 throw ::std::bad_alloc(); 00209 #endif 00210 } 00211 00212 //------------------------------------------------------------------------------ 00213 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence( 00214 const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(()) 00215 { 00216 return ::com::sun::star::uno::Sequence< sal_Int8 >( 00217 * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) ); 00218 } 00219 00220 } 00221 } 00222 } 00223 } 00224 00225 namespace cppu { 00226 00227 template< typename T > inline ::com::sun::star::uno::Type const & 00228 getTypeFavourUnsigned( 00229 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *) 00230 { 00231 if (::com::sun::star::uno::Sequence< T >::s_pType == 0) { 00232 ::typelib_static_sequence_type_init( 00233 &::com::sun::star::uno::Sequence< T >::s_pType, 00234 (::cppu::getTypeFavourUnsigned( 00235 static_cast< 00236 typename ::com::sun::star::uno::Sequence< T >::ElementType * >( 00237 0)). 00238 getTypeLibType())); 00239 } 00240 return detail::getTypeFromTypeDescriptionReference( 00241 &::com::sun::star::uno::Sequence< T >::s_pType); 00242 } 00243 00244 template< typename T > inline ::com::sun::star::uno::Type const & 00245 getTypeFavourChar( 00246 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *) 00247 { 00248 //TODO On certain platforms with weak memory models, the following code can 00249 // result in some threads observing that td points to garbage: 00250 static typelib_TypeDescriptionReference * td = 0; 00251 if (td == 0) { 00252 ::typelib_static_sequence_type_init( 00253 &td, 00254 (::cppu::getTypeFavourChar( 00255 static_cast< 00256 typename ::com::sun::star::uno::Sequence< T >::ElementType * >( 00257 0)). 00258 getTypeLibType())); 00259 } 00260 return detail::getTypeFromTypeDescriptionReference(&td); 00261 } 00262 00263 } 00264 00265 // generic sequence template 00266 template< class E > 00267 inline const ::com::sun::star::uno::Type & 00268 SAL_CALL getCppuType( 00269 SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * ) 00270 SAL_THROW(()) 00271 { 00272 return ::cppu::getTypeFavourUnsigned( 00273 static_cast< ::com::sun::star::uno::Sequence< E > * >(0)); 00274 } 00275 00276 // generic sequence template for given element type (e.g. C++ arrays) 00277 template< class E > 00278 inline const ::com::sun::star::uno::Type & 00279 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType ) 00280 SAL_THROW(()) 00281 { 00282 if (! ::com::sun::star::uno::Sequence< E >::s_pType) 00283 { 00284 ::typelib_static_sequence_type_init( 00285 & ::com::sun::star::uno::Sequence< E >::s_pType, 00286 rElementType.getTypeLibType() ); 00287 } 00288 return * reinterpret_cast< const ::com::sun::star::uno::Type * >( 00289 & ::com::sun::star::uno::Sequence< E >::s_pType ); 00290 } 00291 00292 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) 00293 static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0; 00294 #endif 00295 00296 // char sequence 00297 inline const ::com::sun::star::uno::Type & 00298 SAL_CALL getCharSequenceCppuType() SAL_THROW(()) 00299 { 00300 #if !( defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) 00301 static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0; 00302 #endif 00303 if (! s_pType_com_sun_star_uno_Sequence_Char) 00304 { 00305 const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType(); 00306 ::typelib_static_sequence_type_init( 00307 & s_pType_com_sun_star_uno_Sequence_Char, 00308 rElementType.getTypeLibType() ); 00309 } 00310 return * reinterpret_cast< const ::com::sun::star::uno::Type * >( 00311 & s_pType_com_sun_star_uno_Sequence_Char ); 00312 } 00313 00314 #endif 00315 00316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */