LCOV - code coverage report
Current view: top level - include/com/sun/star/uno - Sequence.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 75 79 94.9 %
Date: 2014-04-11 Functions: 1492 2072 72.0 %
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    11626712 : inline Sequence< E >::Sequence() SAL_THROW(())
      49             : {
      50    11626712 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      51    11626712 :     ::uno_type_sequence_construct(
      52             :         &_pSequence, rType.getTypeLibType(),
      53    11626712 :         0, 0, (uno_AcquireFunc)cpp_acquire );
      54             :     // no bad_alloc, because empty sequence is statically allocated in cppu
      55    11626712 : }
      56             : 
      57             : template< class E >
      58     8105391 : inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(())
      59             : {
      60     8105391 :     osl_atomic_increment( &rSeq._pSequence->nRefCount );
      61     8105391 :     _pSequence = rSeq._pSequence;
      62     8105391 : }
      63             : 
      64             : template< class E >
      65          15 : inline Sequence< E >::Sequence(
      66             :     uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
      67          15 :         : _pSequence( pSequence )
      68             : {
      69          15 : }
      70             : 
      71             : template< class E >
      72     1699787 : inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
      73             : {
      74     1699787 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      75             :     bool success =
      76             :     ::uno_type_sequence_construct(
      77             :         &_pSequence, rType.getTypeLibType(),
      78     1699787 :         const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
      79     1699787 :     if (! success)
      80           0 :         throw ::std::bad_alloc();
      81     1699787 : }
      82             : 
      83             : template< class E >
      84     9276655 : inline Sequence< E >::Sequence( sal_Int32 len )
      85             : {
      86     9276655 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      87             :     bool success =
      88             :     ::uno_type_sequence_construct(
      89             :         &_pSequence, rType.getTypeLibType(),
      90     9276655 :         0, len, (uno_AcquireFunc)cpp_acquire );
      91     9276655 :     if (! success)
      92           0 :         throw ::std::bad_alloc();
      93     9276655 : }
      94             : 
      95             : template< class E >
      96    30616240 : inline Sequence< E >::~Sequence() SAL_THROW(())
      97             : {
      98    30616240 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
      99    30616240 :     ::uno_type_destructData(
     100    30616240 :         this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
     101    30616240 : }
     102             : 
     103             : template< class E >
     104     4388695 : inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(())
     105             : {
     106     4388695 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     107     4388695 :     ::uno_type_sequence_assign(
     108     4388695 :         &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
     109     4388695 :     return *this;
     110             : }
     111             : 
     112             : template< class E >
     113      197321 : inline bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const
     114             :     SAL_THROW(())
     115             : {
     116      197321 :     if (_pSequence == rSeq._pSequence)
     117      100171 :         return true;
     118       97150 :     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       97150 :         (uno_ReleaseFunc)cpp_release );
     124             : }
     125             : 
     126             : template< class E >
     127         277 : inline bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const
     128             :     SAL_THROW(())
     129             : {
     130         277 :     return (! operator == ( rSeq ));
     131             : }
     132             : 
     133             : template< class E >
     134    64181400 : inline E * Sequence< E >::getArray()
     135             : {
     136    64181400 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     137             :     bool success =
     138             :     ::uno_type_sequence_reference2One(
     139             :         &_pSequence, rType.getTypeLibType(),
     140    64181400 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     141    64181400 :     if (! success)
     142           0 :         throw ::std::bad_alloc();
     143    64181400 :     return reinterpret_cast< E * >( _pSequence->elements );
     144             : }
     145             : 
     146         125 : template<class E> E * Sequence<E>::begin() { return getArray(); }
     147             : 
     148        3740 : template<class E> E const * Sequence<E>::begin() const
     149        3740 : { return getConstArray(); }
     150             : 
     151          39 : template<class E> E * Sequence<E>::end() { return begin() + getLength(); }
     152             : 
     153        2366 : template<class E> E const * Sequence<E>::end() const
     154        2366 : { return begin() + getLength(); }
     155             : 
     156             : template< class E >
     157    52151395 : inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
     158             : {
     159             :     assert( nIndex >= 0 && nIndex < getLength() );
     160    52151395 :     return getArray()[ nIndex ];
     161             : }
     162             : 
     163             : template< class E >
     164    21213469 : inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const
     165             :     SAL_THROW(())
     166             : {
     167             :     assert( nIndex >= 0 && nIndex < getLength() );
     168    21213469 :     return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
     169             : }
     170             : 
     171             : template< class E >
     172     8466460 : inline void Sequence< E >::realloc( sal_Int32 nSize )
     173             : {
     174     8466460 :     const Type & rType = ::cppu::getTypeFavourUnsigned( this );
     175             :     bool success =
     176             :     ::uno_type_sequence_realloc(
     177             :         &_pSequence, rType.getTypeLibType(), nSize,
     178     8466460 :         (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
     179     8466460 :     if (!success)
     180           0 :         throw ::std::bad_alloc();
     181     8466460 : }
     182             : 
     183     2621109 : 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     2621109 :         * 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   133700920 : getTypeFavourUnsigned(
     199             :     SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
     200             : {
     201   133700920 :     if (::com::sun::star::uno::Sequence< T >::s_pType == 0) {
     202       25528 :         ::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       25528 :                     0)).
     208       25528 :              getTypeLibType()));
     209             :     }
     210             :     return detail::getTypeFromTypeDescriptionReference(
     211   133700920 :         &::com::sun::star::uno::Sequence< T >::s_pType);
     212             : }
     213             : 
     214             : template< typename T > inline ::com::sun::star::uno::Type const &
     215          45 : 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          45 :     if (td == 0) {
     222          36 :         ::typelib_static_sequence_type_init(
     223             :             &td,
     224             :             (::cppu::getTypeFavourChar(
     225             :                 static_cast<
     226             :                 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
     227          36 :                     0)).
     228          36 :              getTypeLibType()));
     229             :     }
     230          45 :     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      155144 : SAL_CALL getCppuType(
     239             :     SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
     240             :     SAL_THROW(())
     241             : {
     242             :     return ::cppu::getTypeFavourUnsigned(
     243      155144 :         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