UDK 3.2.7 C/C++ API Reference

com/sun/star/uno/Sequence.hxx

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*
00003  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
00020 #define _COM_SUN_STAR_UNO_SEQUENCE_HXX_
00021 
00022 #include "osl/diagnose.h"
00023 #include "osl/interlck.h"
00024 #include "com/sun/star/uno/Sequence.h"
00025 #include "typelib/typedescription.h"
00026 #include "uno/data.h"
00027 #include "com/sun/star/uno/genfunc.hxx"
00028 #include "cppu/unotype.hxx"
00029 
00030 namespace com
00031 {
00032 namespace sun
00033 {
00034 namespace star
00035 {
00036 namespace uno
00037 {
00038 
00040 template< class E >
00041 typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0;
00043 
00044 //______________________________________________________________________________
00045 template< class E >
00046 inline Sequence< E >::Sequence() SAL_THROW(())
00047 {
00048     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00049     ::uno_type_sequence_construct(
00050         &_pSequence, rType.getTypeLibType(),
00051         0, 0, (uno_AcquireFunc)cpp_acquire );
00052     // no bad_alloc, because empty sequence is statically allocated in cppu
00053 }
00054 
00055 //______________________________________________________________________________
00056 template< class E >
00057 inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(())
00058 {
00059     osl_atomic_increment( &rSeq._pSequence->nRefCount );
00060     _pSequence = rSeq._pSequence;
00061 }
00062 
00063 //______________________________________________________________________________
00064 template< class E >
00065 inline Sequence< E >::Sequence(
00066     uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
00067         : _pSequence( pSequence )
00068 {
00069 }
00070 
00071 //______________________________________________________________________________
00072 template< class E >
00073 inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
00074 {
00075     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00076 #if ! defined EXCEPTIONS_OFF
00077     sal_Bool success =
00078 #endif
00079     ::uno_type_sequence_construct(
00080         &_pSequence, rType.getTypeLibType(),
00081         const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
00082 #if ! defined EXCEPTIONS_OFF
00083     if (! success)
00084         throw ::std::bad_alloc();
00085 #endif
00086 }
00087 
00088 //______________________________________________________________________________
00089 template< class E >
00090 inline Sequence< E >::Sequence( sal_Int32 len )
00091 {
00092     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00093 #if ! defined EXCEPTIONS_OFF
00094     sal_Bool success =
00095 #endif
00096     ::uno_type_sequence_construct(
00097         &_pSequence, rType.getTypeLibType(),
00098         0, len, (uno_AcquireFunc)cpp_acquire );
00099 #if ! defined EXCEPTIONS_OFF
00100     if (! success)
00101         throw ::std::bad_alloc();
00102 #endif
00103 }
00104 
00105 //______________________________________________________________________________
00106 template< class E >
00107 inline Sequence< E >::~Sequence() SAL_THROW(())
00108 {
00109     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00110     ::uno_type_destructData(
00111         this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
00112 }
00113 
00114 //______________________________________________________________________________
00115 template< class E >
00116 inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(())
00117 {
00118     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00119     ::uno_type_sequence_assign(
00120         &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
00121     return *this;
00122 }
00123 
00124 //______________________________________________________________________________
00125 template< class E >
00126 inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const
00127     SAL_THROW(())
00128 {
00129     if (_pSequence == rSeq._pSequence)
00130         return sal_True;
00131     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00132     return ::uno_type_equalData(
00133         const_cast< Sequence< E > * >( this ), rType.getTypeLibType(),
00134         const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(),
00135         (uno_QueryInterfaceFunc)cpp_queryInterface,
00136         (uno_ReleaseFunc)cpp_release );
00137 }
00138 
00139 //______________________________________________________________________________
00140 template< class E >
00141 inline sal_Bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const
00142     SAL_THROW(())
00143 {
00144     return (! operator == ( rSeq ));
00145 }
00146 
00147 //______________________________________________________________________________
00148 template< class E >
00149 inline E * Sequence< E >::getArray()
00150 {
00151     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00152 #if ! defined EXCEPTIONS_OFF
00153     sal_Bool success =
00154 #endif
00155     ::uno_type_sequence_reference2One(
00156         &_pSequence, rType.getTypeLibType(),
00157         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
00158 #if ! defined EXCEPTIONS_OFF
00159     if (! success)
00160         throw ::std::bad_alloc();
00161 #endif
00162     return reinterpret_cast< E * >( _pSequence->elements );
00163 }
00164 
00165 //______________________________________________________________________________
00166 template< class E >
00167 inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
00168 {
00169     OSL_ENSURE(
00170         nIndex >= 0 && nIndex < getLength(),
00171         "### illegal index of sequence!" );
00172     return getArray()[ nIndex ];
00173 }
00174 
00175 //______________________________________________________________________________
00176 template< class E >
00177 inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const
00178     SAL_THROW(())
00179 {
00180     OSL_ENSURE(
00181         nIndex >= 0 && nIndex < getLength(),
00182         "### illegal index of sequence!" );
00183     return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
00184 }
00185 
00186 //______________________________________________________________________________
00187 template< class E >
00188 inline void Sequence< E >::realloc( sal_Int32 nSize )
00189 {
00190     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
00191 #if !defined EXCEPTIONS_OFF
00192     sal_Bool success =
00193 #endif
00194     ::uno_type_sequence_realloc(
00195         &_pSequence, rType.getTypeLibType(), nSize,
00196         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
00197 #if !defined EXCEPTIONS_OFF
00198     if (!success)
00199         throw ::std::bad_alloc();
00200 #endif
00201 }
00202 
00203 //------------------------------------------------------------------------------
00204 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
00205     const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(())
00206 {
00207     return ::com::sun::star::uno::Sequence< sal_Int8 >(
00208         * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) );
00209 }
00210 
00211 }
00212 }
00213 }
00214 }
00215 
00216 namespace cppu {
00217 
00218 template< typename T > inline ::com::sun::star::uno::Type const &
00219 getTypeFavourUnsigned(
00220     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
00221 {
00222     if (::com::sun::star::uno::Sequence< T >::s_pType == 0) {
00223         ::typelib_static_sequence_type_init(
00224             &::com::sun::star::uno::Sequence< T >::s_pType,
00225             (::cppu::getTypeFavourUnsigned(
00226                 static_cast<
00227                 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
00228                     0)).
00229              getTypeLibType()));
00230     }
00231     return detail::getTypeFromTypeDescriptionReference(
00232         &::com::sun::star::uno::Sequence< T >::s_pType);
00233 }
00234 
00235 template< typename T > inline ::com::sun::star::uno::Type const &
00236 getTypeFavourChar(
00237     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
00238 {
00239     //TODO  On certain platforms with weak memory models, the following code can
00240     // result in some threads observing that td points to garbage:
00241     static typelib_TypeDescriptionReference * td = 0;
00242     if (td == 0) {
00243         ::typelib_static_sequence_type_init(
00244             &td,
00245             (::cppu::getTypeFavourChar(
00246                 static_cast<
00247                 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
00248                     0)).
00249              getTypeLibType()));
00250     }
00251     return detail::getTypeFromTypeDescriptionReference(&td);
00252 }
00253 
00254 }
00255 
00256 // generic sequence template
00257 template< class E >
00258 inline const ::com::sun::star::uno::Type &
00259 SAL_CALL getCppuType(
00260     SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
00261     SAL_THROW(())
00262 {
00263     return ::cppu::getTypeFavourUnsigned(
00264         static_cast< ::com::sun::star::uno::Sequence< E > * >(0));
00265 }
00266 
00267 // generic sequence template for given element type (e.g. C++ arrays)
00268 template< class E >
00269 inline const ::com::sun::star::uno::Type &
00270 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
00271     SAL_THROW(())
00272 {
00273     if (! ::com::sun::star::uno::Sequence< E >::s_pType)
00274     {
00275         ::typelib_static_sequence_type_init(
00276             & ::com::sun::star::uno::Sequence< E >::s_pType,
00277             rElementType.getTypeLibType() );
00278     }
00279     return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
00280         & ::com::sun::star::uno::Sequence< E >::s_pType );
00281 }
00282 
00283 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
00284 static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
00285 #endif
00286 
00287 // char sequence
00288 inline const ::com::sun::star::uno::Type &
00289 SAL_CALL getCharSequenceCppuType() SAL_THROW(())
00290 {
00291 #if !( defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
00292     static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
00293 #endif
00294     if (! s_pType_com_sun_star_uno_Sequence_Char)
00295     {
00296         const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType();
00297         ::typelib_static_sequence_type_init(
00298             & s_pType_com_sun_star_uno_Sequence_Char,
00299             rElementType.getTypeLibType() );
00300     }
00301     return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
00302         & s_pType_com_sun_star_uno_Sequence_Char );
00303 }
00304 
00305 #endif
00306 
00307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines