LCOV - code coverage report
Current view: top level - include/com/sun/star/uno - Sequence.h (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 12 12 100.0 %
Date: 2014-11-03 Functions: 328 448 73.2 %
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_H
      20             : #define INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_H
      21             : 
      22             : #include <typelib/typedescription.h>
      23             : #include <uno/sequence2.h>
      24             : #include <com/sun/star/uno/Type.h>
      25             : #include <rtl/alloc.h>
      26             : 
      27             : #include <new>
      28             : 
      29             : namespace rtl
      30             : {
      31             : class ByteSequence;
      32             : }
      33             : 
      34             : namespace com
      35             : {
      36             : namespace sun
      37             : {
      38             : namespace star
      39             : {
      40             : namespace uno
      41             : {
      42             : 
      43             : /** Template C++ class representing an IDL sequence. Template argument is the
      44             :     sequence element type.  C++ Sequences are reference counted and shared,
      45             :     so the sequence keeps a handle to its data.  To keep value semantics,
      46             :     copies are only generated if the sequence is to be modified (new handle).
      47             : 
      48             :     @tparam E element type of sequence
      49             : */
      50             : template< class E >
      51             : class SAL_WARN_UNUSED Sequence
      52             : {
      53             :     /** sequence handle
      54             :     */
      55             :     uno_Sequence * _pSequence;
      56             : 
      57             : public:
      58             :     /// @cond INTERNAL
      59             : 
      60             :     // these are here to force memory de/allocation to sal lib.
      61     3151491 :     inline static void * SAL_CALL operator new ( ::size_t nSize )
      62     3151491 :         { return ::rtl_allocateMemory( nSize ); }
      63     3144646 :     inline static void SAL_CALL operator delete ( void * pMem )
      64     3144646 :         { ::rtl_freeMemory( pMem ); }
      65             :     inline static void * SAL_CALL operator new ( ::size_t, void * pMem )
      66             :         { return pMem; }
      67             :     inline static void SAL_CALL operator delete ( void *, void * )
      68             :         {}
      69             : 
      70             :     /** Static pointer to typelib type of sequence.
      71             :         Don't use directly, call getCppuType().
      72             :     */
      73             :     static typelib_TypeDescriptionReference * s_pType;
      74             : 
      75             :     /// @endcond
      76             : 
      77             :     /** typedefs the element type of the sequence
      78             :     */
      79             :     typedef E ElementType;
      80             : 
      81             :     /** Default constructor: Creates an empty sequence.
      82             :     */
      83             :     inline Sequence();
      84             : 
      85             :     /** Copy constructor: Creates a copy of given sequence.
      86             : 
      87             :         @param rSeq another sequence of same type
      88             :     */
      89             :     inline Sequence( const Sequence< E > & rSeq );
      90             : 
      91             :     /** Constructor: Takes over ownership of given sequence.
      92             : 
      93             :         @param pSequence a sequence
      94             :         @param dummy SAL_NO_ACQUIRE to force obvious distinction to other
      95             :         constructors
      96             :     */
      97             :     inline Sequence( uno_Sequence * pSequence, __sal_NoAcquire dummy );
      98             : 
      99             :     /** Constructor: Creates a copy of given elements.
     100             : 
     101             :         @param pElements an array of elements
     102             :         @param len length of array
     103             :     */
     104             :     inline Sequence( const E * pElements, sal_Int32 len );
     105             : 
     106             :     /** Constructor: Creates a default constructed sequence of given length.
     107             : 
     108             :         @param len initial sequence length
     109             :     */
     110             :     inline explicit Sequence( sal_Int32 len );
     111             : 
     112             :     /** Destructor: Releases sequence handle. Last handle will destruct
     113             :         elements and free memory.
     114             :     */
     115             :     inline ~Sequence();
     116             : 
     117             :     /** Assignment operator: Acquires given sequence handle and releases
     118             :         previously set handle.
     119             : 
     120             :         @param rSeq another sequence of same type
     121             :         @return this sequence
     122             :     */
     123             :     inline Sequence< E > & SAL_CALL operator = ( const Sequence< E > & rSeq );
     124             : 
     125             :     /** Gets length of the sequence.
     126             : 
     127             :         @return length of sequence
     128             :     */
     129   204309553 :     inline sal_Int32 SAL_CALL getLength() const
     130   204309553 :         { return _pSequence->nElements; }
     131             : 
     132             :     /** Tests whether the sequence has elements, i.e. elements count is
     133             :         greater than zero.
     134             : 
     135             :         @return true, if elements count is greater than zero
     136             :     */
     137     3797501 :     inline bool SAL_CALL hasElements() const
     138     3797501 :         { return (_pSequence->nElements > 0); }
     139             : 
     140             :     /** Gets a pointer to elements array for reading.
     141             :         If the sequence has a length of 0, then the returned pointer is
     142             :         undefined.
     143             : 
     144             :         @return pointer to elements array
     145             :     */
     146    63782990 :     inline const E * SAL_CALL getConstArray() const
     147    63782990 :         { return reinterpret_cast< const E * >( _pSequence->elements ); }
     148             : 
     149             :     /** Gets a pointer to elements array for reading and writing.
     150             :         In general if the sequence has a handle acquired by other sequences
     151             :         (reference count > 1), then a new sequence is created copy constructing
     152             :         all elements to keep value semantics!
     153             :         If the sequence has a length of 0, then the returned pointer is
     154             :         undefined.
     155             : 
     156             :         @return pointer to elements array
     157             :     */
     158             :     inline E * SAL_CALL getArray();
     159             : 
     160             :     /** This function allows to use Sequence in standard algorightms, like std::find
     161             :         and others.
     162             : 
     163             :         @since LibreOffice 4.2
     164             :     */
     165             :     inline E * begin();
     166             : 
     167             :     /** This function allows to use Sequence in standard algorightms, like std::find
     168             :         and others.
     169             : 
     170             :         @since LibreOffice 4.2
     171             :     */
     172             :     inline E const * begin() const;
     173             : 
     174             :     /** This function allows to use Sequence in standard algorightms, like std::find
     175             :         and others.
     176             : 
     177             :         @since LibreOffice 4.2
     178             :     */
     179             :     inline E * end();
     180             : 
     181             :     /** This function allows to use Sequence in standard algorightms, like std::find
     182             :         and others.
     183             : 
     184             :         @since LibreOffice 4.2
     185             :     */
     186             :     inline E const * end() const;
     187             : 
     188             :     /** Non-const index operator: Obtains a reference to element indexed at
     189             :         given position.
     190             :         The implementation does not check for array bounds!
     191             :         In general if the sequence has a handle acquired by other sequences
     192             :         (reference count > 1), then a new sequence is created copy constructing
     193             :         all elements to keep value semantics!
     194             : 
     195             :         @param nIndex index
     196             :         @return non-const C++ reference to element
     197             :     */
     198             :     inline E & SAL_CALL operator [] ( sal_Int32 nIndex );
     199             : 
     200             :     /** Const index operator: Obtains a reference to element indexed at
     201             :         given position.  The implementation does not check for array bounds!
     202             : 
     203             :         @param nIndex index
     204             :         @return const C++ reference to element
     205             :     */
     206             :     inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const;
     207             : 
     208             :     /** Equality operator: Compares two sequences.
     209             : 
     210             :         @param rSeq another sequence of same type (right side)
     211             :         @return true if both sequences are equal, false otherwise
     212             :     */
     213             :     inline bool SAL_CALL operator == ( const Sequence< E > & rSeq ) const;
     214             : 
     215             :     /** Unequality operator: Compares two sequences.
     216             : 
     217             :         @param rSeq another sequence of same type (right side)
     218             :         @return false if both sequences are equal, true otherwise
     219             :     */
     220             :     inline bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const;
     221             : 
     222             :     /** Reallocates sequence to new length.
     223             :         If the new length is smaller than the former, then upper elements will
     224             :         be destructed (and their memory freed).  If the new length is greater
     225             :         than the former, then upper (new) elements are default constructed.
     226             :         If the sequence has a handle acquired by other sequences
     227             :         (reference count > 1), then the remaining elements are copy constructed
     228             :         to a new sequence handle to keep value semantics!
     229             : 
     230             :         @param nSize new size of sequence
     231             :     */
     232             :     inline void SAL_CALL realloc( sal_Int32 nSize );
     233             : 
     234             :     /** Provides UNacquired sequence handle.
     235             : 
     236             :         @return UNacquired sequence handle
     237             :     */
     238        7476 :     inline uno_Sequence * SAL_CALL get() const
     239        7476 :         { return _pSequence; }
     240             : };
     241             : 
     242             : // Find uses of illegal Sequence<bool> (instead of Sequence<sal_Bool>) during
     243             : // compilation:
     244             : template<> class Sequence<bool> {
     245             :     Sequence(Sequence<bool> const &) SAL_DELETED_FUNCTION;
     246             : };
     247             : 
     248             : /** Creates a UNO byte sequence from a SAL byte sequence.
     249             : 
     250             :     @param rByteSequence a byte sequence
     251             :     @return a UNO byte sequence
     252             : */
     253             : inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
     254             :     const ::rtl::ByteSequence & rByteSequence );
     255             : 
     256             : }
     257             : }
     258             : }
     259             : }
     260             : 
     261             : /** Gets the meta type of IDL sequence.
     262             : 
     263             :     There are cases (involving templates) where uses of getCppuType are known to
     264             :     not compile.  Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
     265             : 
     266             :     The dummy parameter is just a typed pointer for function signature.
     267             : 
     268             :     @tparam E element type of sequence
     269             :     @return type of IDL sequence
     270             : */
     271             : template< class E >
     272             : inline const ::com::sun::star::uno::Type &
     273             : SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * );
     274             : 
     275             : /** Gets the meta type of IDL sequence.
     276             :     This function has been introduced, because one cannot get the (templated)
     277             :     cppu type out of C++ array types.
     278             : 
     279             :     @attention
     280             :     the given element type must be the same as the template argument type!
     281             :     @tparam E element type of sequence
     282             :     @param rElementType element type of sequence
     283             :     @return type of IDL sequence
     284             : */
     285             : template< class E >
     286             : inline const ::com::sun::star::uno::Type &
     287             : SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType );
     288             : 
     289             : /** Gets the meta type of IDL sequence< char >.
     290             :     This function has been introduced due to ambiguities with unsigned short.
     291             : 
     292             :     The dummy parameter is just a typed pointer for function signature.
     293             : 
     294             :     @return type of IDL sequence< char >
     295             : */
     296             : inline const ::com::sun::star::uno::Type &
     297             : SAL_CALL getCharSequenceCppuType();
     298             : 
     299             : #endif
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10