LCOV - code coverage report
Current view: top level - include/com/sun/star/uno - Sequence.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 35 79 44.3 %
Date: 2014-04-14 Functions: 26 2053 1.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_HXX
      20             : #define INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_HXX
      21             : 
      22             : #include <sal/config.h>
      23             : 
      24             : #include <cassert>
      25             : 
      26             : #include <osl/interlck.h>
      27             : #include <com/sun/star/uno/Sequence.h>
      28             : #include <typelib/typedescription.h>
      29             : #include <uno/data.h>
      30             : #include <com/sun/star/uno/genfunc.hxx>
      31             : #include <cppu/unotype.hxx>
      32             : 
      33             : namespace com
      34             : {
      35             : namespace sun
      36             : {
      37             : namespace star
      38             : {
      39             : namespace uno
      40             : {
      41             : 
      42             : /// @cond INTERNAL
      43             : template< class E >
      44             : typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0;
      45             : /// @endcond
      46             : 
      47             : template< class E >
      48           8 : inline Sequence< E >::Sequence() SAL_THROW(())
      49             : {
      50           8 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      51           8 :     ::uno_type_sequence_construct(
      52             :         &_pSequence, rType.getTypeLibType(),
      53           8 :         0, 0, (uno_AcquireFunc)cpp_acquire );
      54             :     // no bad_alloc, because empty sequence is statically allocated in cppu
      55           8 : }
      56             : 
      57             : template< class E >
      58           0 : inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(())
      59             : {
      60           0 :     osl_atomic_increment( &rSeq._pSequence->nRefCount );
      61           0 :     _pSequence = rSeq._pSequence;
      62           0 : }
      63             : 
      64             : template< class E >
      65           0 : inline Sequence< E >::Sequence(
      66             :     uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
      67           0 :         : _pSequence( pSequence )
      68             : {
      69           0 : }
      70             : 
      71             : template< class E >
      72           0 : inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
      73             : {
      74           0 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      75             :     bool success =
      76             :     ::uno_type_sequence_construct(
      77             :         &_pSequence, rType.getTypeLibType(),
      78           0 :         const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
      79           0 :     if (! success)
      80           0 :         throw ::std::bad_alloc();
      81           0 : }
      82             : 
      83             : template< class E >
      84          34 : inline Sequence< E >::Sequence( sal_Int32 len )
      85             : {
      86          34 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      87             :     bool success =
      88             :     ::uno_type_sequence_construct(
      89             :         &_pSequence, rType.getTypeLibType(),
      90          34 :         0, len, (uno_AcquireFunc)cpp_acquire );
      91          34 :     if (! success)
      92           0 :         throw ::std::bad_alloc();
      93          34 : }
      94             : 
      95             : template< class E >
      96          47 : inline Sequence< E >::~Sequence() SAL_THROW(())
      97             : {
      98          47 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      99          47 :     ::uno_type_destructData(
     100          47 :         this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
     101          47 : }
     102             : 
     103             : template< class E >
     104           6 : inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(())
     105             : {
     106           6 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     107           6 :     ::uno_type_sequence_assign(
     108           6 :         &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
     109           6 :     return *this;
     110             : }
     111             : 
     112             : template< class E >
     113           0 : inline bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const
     114             :     SAL_THROW(())
     115             : {
     116           0 :     if (_pSequence == rSeq._pSequence)
     117           0 :         return true;
     118           0 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     119             :     return ::uno_type_equalData(
     120             :         const_cast< Sequence< E > * >( this ), rType.getTypeLibType(),
     121             :         const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(),
     122             :         (uno_QueryInterfaceFunc)cpp_queryInterface,
     123           0 :         (uno_ReleaseFunc)cpp_release );
     124             : }
     125             : 
     126             : template< class E >
     127           0 : inline bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const
     128             :     SAL_THROW(())
     129             : {
     130           0 :     return (! operator == ( rSeq ));
     131             : }
     132             : 
     133             : template< class E >
     134          51 : inline E * Sequence< E >::getArray()
     135             : {
     136          51 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     137             :     bool success =
     138             :     ::uno_type_sequence_reference2One(
     139             :         &_pSequence, rType.getTypeLibType(),
     140          51 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     141          51 :     if (! success)
     142           0 :         throw ::std::bad_alloc();
     143          51 :     return reinterpret_cast< E * >( _pSequence->elements );
     144             : }
     145             : 
     146           0 : template<class E> E * Sequence<E>::begin() { return getArray(); }
     147             : 
     148           0 : template<class E> E const * Sequence<E>::begin() const
     149           0 : { return getConstArray(); }
     150             : 
     151           0 : template<class E> E * Sequence<E>::end() { return begin() + getLength(); }
     152             : 
     153           0 : template<class E> E const * Sequence<E>::end() const
     154           0 : { return begin() + getLength(); }
     155             : 
     156             : template< class E >
     157          51 : inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
     158             : {
     159             :     assert( nIndex >= 0 && nIndex < getLength() );
     160          51 :     return getArray()[ nIndex ];
     161             : }
     162             : 
     163             : template< class E >
     164           2 : inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const
     165             :     SAL_THROW(())
     166             : {
     167             :     assert( nIndex >= 0 && nIndex < getLength() );
     168           2 :     return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
     169             : }
     170             : 
     171             : template< class E >
     172           0 : inline void Sequence< E >::realloc( sal_Int32 nSize )
     173             : {
     174           0 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     175             :     bool success =
     176             :     ::uno_type_sequence_realloc(
     177             :         &_pSequence, rType.getTypeLibType(), nSize,
     178           0 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     179           0 :     if (!success)
     180           0 :         throw ::std::bad_alloc();
     181           0 : }
     182             : 
     183           0 : inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
     184             :     const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(())
     185             : {
     186             :     return ::com::sun::star::uno::Sequence< sal_Int8 >(
     187           0 :         * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) );
     188             : }
     189             : 
     190             : }
     191             : }
     192             : }
     193             : }
     194             : 
     195             : namespace cppu {
     196             : 
     197             : template< typename T > inline ::com::sun::star::uno::Type const &
     198         146 : getTypeFavourUnsigned(
     199             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
     200             : {
     201         146 :     if (::com::sun::star::uno::Sequence< T >::s_pType == 0) {
     202           6 :         ::typelib_static_sequence_type_init(
     203             :             &::com::sun::star::uno::Sequence< T >::s_pType,
     204             :             (::cppu::getTypeFavourUnsigned(
     205             :                 static_cast<
     206             :                 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
     207           6 :                     0)).
     208           6 :              getTypeLibType()));
     209             :     }
     210             :     return detail::getTypeFromTypeDescriptionReference(
     211         146 :         &::com::sun::star::uno::Sequence< T >::s_pType);
     212             : }
     213             : 
     214             : template< typename T > inline ::com::sun::star::uno::Type const &
     215           0 : getTypeFavourChar(
     216             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
     217             : {
     218             :     //TODO  On certain platforms with weak memory models, the following code can
     219             :     // result in some threads observing that td points to garbage:
     220             :     static typelib_TypeDescriptionReference * td = 0;
     221           0 :     if (td == 0) {
     222           0 :         ::typelib_static_sequence_type_init(
     223             :             &td,
     224             :             (::cppu::getTypeFavourChar(
     225             :                 static_cast<
     226             :                 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
     227           0 :                     0)).
     228           0 :              getTypeLibType()));
     229             :     }
     230           0 :     return detail::getTypeFromTypeDescriptionReference(&td);
     231             : }
     232             : 
     233             : }
     234             : 
     235             : // generic sequence template
     236             : template< class E >
     237             : inline const ::com::sun::star::uno::Type &
     238           0 : SAL_CALL getCppuType(
     239             :     SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
     240             :     SAL_THROW(())
     241             : {
     242             :     return ::cppu::getTypeFavourUnsigned(
     243           0 :         static_cast< ::com::sun::star::uno::Sequence< E > * >(0));
     244             : }
     245             : 
     246             : // generic sequence template for given element type (e.g. C++ arrays)
     247             : template< class E >
     248             : inline const ::com::sun::star::uno::Type &
     249             : SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
     250             :     SAL_THROW(())
     251             : {
     252             :     if (! ::com::sun::star::uno::Sequence< E >::s_pType)
     253             :     {
     254             :         ::typelib_static_sequence_type_init(
     255             :             & ::com::sun::star::uno::Sequence< E >::s_pType,
     256             :             rElementType.getTypeLibType() );
     257             :     }
     258             :     return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
     259             :         & ::com::sun::star::uno::Sequence< E >::s_pType );
     260             : }
     261             : 
     262             : // char sequence
     263             : inline const ::com::sun::star::uno::Type &
     264             : SAL_CALL getCharSequenceCppuType() SAL_THROW(())
     265             : {
     266             :     static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
     267             :     if (! s_pType_com_sun_star_uno_Sequence_Char)
     268             :     {
     269             :         const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType();
     270             :         ::typelib_static_sequence_type_init(
     271             :             & s_pType_com_sun_star_uno_Sequence_Char,
     272             :             rElementType.getTypeLibType() );
     273             :     }
     274             :     return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
     275             :         & s_pType_com_sun_star_uno_Sequence_Char );
     276             : }
     277             : 
     278             : #endif
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10