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

Generated by: LCOV version 1.10