LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/rtl - byteseq.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 12 100.0 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #ifndef _RTL_BYTESEQ_H_
      29                 :            : #define _RTL_BYTESEQ_H_
      30                 :            : 
      31                 :            : #include <sal/types.h>
      32                 :            : #include <rtl/alloc.h>
      33                 :            : 
      34                 :            : #ifdef __cplusplus
      35                 :            : extern "C"
      36                 :            : {
      37                 :            : #endif
      38                 :            : 
      39                 :            : /** Assures that the reference count of the given byte sequence is one. Otherwise a new copy
      40                 :            :     of the sequence is created with a reference count of one.
      41                 :            : 
      42                 :            :     @param ppSequence sequence
      43                 :            : */
      44                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_reference2One(
      45                 :            :     sal_Sequence ** ppSequence )
      46                 :            :     SAL_THROW_EXTERN_C();
      47                 :            : 
      48                 :            : /** Reallocates length of byte sequence.
      49                 :            : 
      50                 :            :     @param ppSequence sequence
      51                 :            :     @param nSize new size of sequence
      52                 :            : */
      53                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_realloc(
      54                 :            :     sal_Sequence ** ppSequence, sal_Int32 nSize )
      55                 :            :     SAL_THROW_EXTERN_C();
      56                 :            : 
      57                 :            : /** Acquires the byte sequence
      58                 :            : 
      59                 :            :     @param pSequence sequence, that is to be acquired
      60                 :            : */
      61                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_acquire(
      62                 :            :     sal_Sequence *pSequence )
      63                 :            :     SAL_THROW_EXTERN_C();
      64                 :            : 
      65                 :            : /** Releases the byte sequence. If the refcount drops to zero, the sequence is freed.
      66                 :            : 
      67                 :            :     @param pSequence sequence, that is to be released; invalid after call
      68                 :            : */
      69                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_release(
      70                 :            :     sal_Sequence *pSequence )
      71                 :            :     SAL_THROW_EXTERN_C();
      72                 :            : 
      73                 :            : /** Constructs a bytes sequence with length nLength. All bytes are set to zero.
      74                 :            : 
      75                 :            :     @param ppSequence inout sequence; on entry *ppSequence may be null, otherwise it is released;
      76                 :            :                       after the call, *ppSequence contains the newly constructed sequence
      77                 :            :     @param nLength    length of new sequence
      78                 :            : */
      79                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_construct(
      80                 :            :     sal_Sequence **ppSequence , sal_Int32 nLength )
      81                 :            :     SAL_THROW_EXTERN_C();
      82                 :            : 
      83                 :            : /** Constructs a bytes sequence with length nLength. The data is not initialized.
      84                 :            : 
      85                 :            :     @param ppSequence inout sequence; on entry *ppSequence may be null, otherwise it is released;
      86                 :            :                       after the call, *ppSequence contains the newly constructed sequence
      87                 :            :     @param nLength    length of new sequence
      88                 :            : */
      89                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_constructNoDefault(
      90                 :            :     sal_Sequence **ppSequence , sal_Int32 nLength )
      91                 :            :     SAL_THROW_EXTERN_C();
      92                 :            : 
      93                 :            : /** Constructs a byte sequence with length nLength and copies nLength bytes from pData.
      94                 :            : 
      95                 :            :     @param ppSequence inout sequence; on entry *ppSequence may be null, otherwise it is released;
      96                 :            :                       after the call, *ppSequence contains the newly constructed sequence
      97                 :            :     @param pData      initial data
      98                 :            :     @param nLength    length of new sequence
      99                 :            : */
     100                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_constructFromArray(
     101                 :            :     sal_Sequence **ppSequence, const sal_Int8 *pData , sal_Int32 nLength )
     102                 :            :     SAL_THROW_EXTERN_C();
     103                 :            : 
     104                 :            : /** Assigns the byte sequence pSequence to *ppSequence.
     105                 :            : 
     106                 :            :     @param ppSequence inout sequence; on entry *ppSequence may be null, otherwise it is released;
     107                 :            :                       after the call, *ppSequence references pSequence
     108                 :            :     @param pSequence  the source sequence
     109                 :            : */
     110                 :            : SAL_DLLPUBLIC void SAL_CALL rtl_byte_sequence_assign(
     111                 :            :     sal_Sequence **ppSequence , sal_Sequence *pSequence )
     112                 :            :     SAL_THROW_EXTERN_C();
     113                 :            : 
     114                 :            : /** Compares two byte sequences.
     115                 :            : 
     116                 :            :     @return true, if the data within the sequences are identical; false otherwise
     117                 :            : */
     118                 :            : SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_byte_sequence_equals(
     119                 :            :     sal_Sequence *pSequence1 , sal_Sequence *pSequence2 )
     120                 :            :     SAL_THROW_EXTERN_C();
     121                 :            : 
     122                 :            : /** Returns the data array pointer of the sequence.
     123                 :            : 
     124                 :            :     @return read-pointer to the data array of the sequence. If rtl_byte_sequence_reference2One()
     125                 :            :             has been called before, the pointer may be casted to a non const pointer and
     126                 :            :             the sequence may be modified
     127                 :            : */
     128                 :            : SAL_DLLPUBLIC const sal_Int8 *SAL_CALL rtl_byte_sequence_getConstArray(
     129                 :            :     sal_Sequence *pSequence )
     130                 :            :     SAL_THROW_EXTERN_C();
     131                 :            : 
     132                 :            : /** Returns the length of the sequence
     133                 :            : 
     134                 :            :     @param pSequence sequence handle
     135                 :            :     @return length of the sequence
     136                 :            : */
     137                 :            : SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_byte_sequence_getLength(
     138                 :            :     sal_Sequence *pSequence )
     139                 :            :     SAL_THROW_EXTERN_C();
     140                 :            : 
     141                 :            : #ifdef __cplusplus
     142                 :            : }
     143                 :            : namespace rtl
     144                 :            : {
     145                 :            : 
     146                 :            : enum __ByteSequence_NoDefault
     147                 :            : {
     148                 :            :     /** This enum value can be used to create a bytesequence with uninitalized data
     149                 :            :     */
     150                 :            :     BYTESEQ_NODEFAULT = 0xcafe
     151                 :            : };
     152                 :            : 
     153                 :            : enum __ByteSequence_NoAcquire
     154                 :            : {
     155                 :            :     /** This enum value can be used to create a bytesequence from a C-Handle without
     156                 :            :         acquiring the handle.
     157                 :            :     */
     158                 :            :     BYTESEQ_NOACQUIRE = 0xcafebabe
     159                 :            : };
     160                 :            : 
     161                 :            : /** C++ class representing a SAL byte sequence.
     162                 :            :     C++ Sequences are reference counted and shared, so the sequence keeps a handle to its data.
     163                 :            :     To keep value semantics, copies are only generated if the sequence is to be modified
     164                 :            :     (new handle).
     165                 :            : */
     166                 :            : class ByteSequence
     167                 :            : {
     168                 :            :     /** sequence handle
     169                 :            :     */
     170                 :            :     sal_Sequence * _pSequence;
     171                 :            : 
     172                 :            : public:
     173                 :            :     /// @cond INTERNAL
     174                 :            :     // these are here to force memory de/allocation to sal lib.
     175                 :            :     inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
     176                 :            :         { return ::rtl_allocateMemory( nSize ); }
     177                 :            :     inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
     178                 :            :         { ::rtl_freeMemory( pMem ); }
     179                 :     308041 :     inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
     180                 :     308041 :         { return pMem; }
     181                 :            :     inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
     182                 :            :         {}
     183                 :            :     /// @endcond
     184                 :            : 
     185                 :            :     /** Default constructor: Creates an empty sequence.
     186                 :            :     */
     187                 :            :     inline ByteSequence() SAL_THROW(());
     188                 :            :     /** Copy constructor: Creates a copy of given sequence.
     189                 :            : 
     190                 :            :         @param rSeq another byte sequence
     191                 :            :     */
     192                 :            :     inline ByteSequence( const ByteSequence & rSeq ) SAL_THROW(());
     193                 :            :     /** Copy constructor Creates a copy from the C-Handle.
     194                 :            : 
     195                 :            :         @param pSequence another byte sequence handle
     196                 :            :     */
     197                 :            :     inline ByteSequence( sal_Sequence *pSequence ) SAL_THROW(());
     198                 :            :     /** Constructor: Creates a copy of given data bytes.
     199                 :            : 
     200                 :            :         @param pElements an array of bytes
     201                 :            :         @param len number of bytes
     202                 :            :     */
     203                 :            :     inline ByteSequence( const sal_Int8 * pElements, sal_Int32 len );
     204                 :            :     /** Constructor: Creates sequence of given length and initializes all bytes to 0.
     205                 :            : 
     206                 :            :         @param len initial sequence length
     207                 :            :     */
     208                 :            :     inline ByteSequence( sal_Int32 len );
     209                 :            :     /** Constructor: Creates sequence of given length and does NOT initialize data.
     210                 :            :                      Use this ctor for performance optimization only.
     211                 :            : 
     212                 :            :         @param len initial sequence length
     213                 :            :         @param nodefault dummy parameter forcing explicit BYTESEQ_NODEFAULT
     214                 :            :     */
     215                 :            :     inline ByteSequence( sal_Int32 len , enum __ByteSequence_NoDefault nodefault );
     216                 :            :     /** Constructor:
     217                 :            :         Creates a sequence from a C-Handle without acquiring the handle, thus taking
     218                 :            :         over owenership. Eitherway the handle is release by the destructor.
     219                 :            :         This ctor is useful, when working with a c-interface (it safes a pair of
     220                 :            :         acquire and release call and is thus a performance optimization only).
     221                 :            : 
     222                 :            :         @param pSequence sequence handle to be taken over
     223                 :            :         @param noacquire dummy parameter forcing explicit BYTESEQ_NOACQUIRE
     224                 :            :     */
     225                 :            :     inline ByteSequence( sal_Sequence *pSequence , enum __ByteSequence_NoAcquire noacquire ) SAL_THROW(());
     226                 :            :     /** Destructor: Releases sequence handle. Last handle will free memory.
     227                 :            :     */
     228                 :            :     inline ~ByteSequence() SAL_THROW(());
     229                 :            : 
     230                 :            :     /** Assignment operator: Acquires given sequence handle and releases a previously set handle.
     231                 :            : 
     232                 :            :         @param rSeq another byte sequence
     233                 :            :         @return this sequence
     234                 :            :     */
     235                 :            :     inline ByteSequence & SAL_CALL operator = ( const ByteSequence & rSeq ) SAL_THROW(());
     236                 :            : 
     237                 :            :     /** Gets the length of sequence.
     238                 :            : 
     239                 :            :         @return length of sequence
     240                 :            :     */
     241                 :    9286302 :     inline sal_Int32 SAL_CALL getLength() const SAL_THROW(())
     242                 :    9286302 :         { return _pSequence->nElements; }
     243                 :            : 
     244                 :            :     /** Gets a pointer to byte array for READING. If the sequence has a length of 0, then the
     245                 :            :         returned pointer is undefined.
     246                 :            : 
     247                 :            :         @return pointer to byte array
     248                 :            :     */
     249                 :   15325074 :     inline const sal_Int8 * SAL_CALL getConstArray() const SAL_THROW(())
     250                 :   15325074 :         { return (const sal_Int8 *)_pSequence->elements; }
     251                 :            :     /** Gets a pointer to elements array for READING AND WRITING. In general if the sequence
     252                 :            :         has a handle acquired by other sequences (reference count > 1), then a new sequence is
     253                 :            :         created copying all bytes to keep value semantics!
     254                 :            :         If the sequence has a length of 0, then the returned pointer is undefined.
     255                 :            : 
     256                 :            :         @return pointer to elements array
     257                 :            :     */
     258                 :            :     inline sal_Int8 * SAL_CALL getArray();
     259                 :            : 
     260                 :            :     /** Non-const index operator:
     261                 :            :         Obtains a reference to byte indexed at given position.
     262                 :            :         In general if the sequence has a handle acquired by other
     263                 :            :         sequences (reference count > 1), then a new sequence is created
     264                 :            :         copying all bytes to keep value semantics!
     265                 :            : 
     266                 :            :         @attention
     267                 :            :         The implementation does NOT check for array bounds!
     268                 :            : 
     269                 :            :         @param nIndex index
     270                 :            :         @return non-const C++ reference to element at index nIndex
     271                 :            :     */
     272                 :            :     inline sal_Int8 & SAL_CALL operator [] ( sal_Int32 nIndex );
     273                 :            : 
     274                 :            :     /** Const index operator: Obtains a reference to byte indexed at given position.
     275                 :            :                               The implementation does NOT check for array bounds!
     276                 :            : 
     277                 :            :         @param nIndex index
     278                 :            :         @return const C++ reference to byte at element of indenx nIndex
     279                 :            :     */
     280                 :   13927196 :     inline const sal_Int8 & SAL_CALL operator [] ( sal_Int32 nIndex ) const SAL_THROW(())
     281                 :   13927196 :         { return getConstArray()[ nIndex ]; }
     282                 :            : 
     283                 :            :     /** Equality operator: Compares two sequences.
     284                 :            : 
     285                 :            :         @param rSeq another byte sequence (right side)
     286                 :            :         @return true if both sequences are equal, false otherwise
     287                 :            :     */
     288                 :            :     inline sal_Bool SAL_CALL operator == ( const ByteSequence & rSeq ) const SAL_THROW(());
     289                 :            :     /** Unequality operator: Compares two sequences.
     290                 :            : 
     291                 :            :         @param rSeq another byte sequence (right side)
     292                 :            :         @return false if both sequences are equal, true otherwise
     293                 :            :     */
     294                 :            :     inline sal_Bool SAL_CALL operator != ( const ByteSequence & rSeq ) const SAL_THROW(());
     295                 :            : 
     296                 :            :     /** Reallocates sequence to new length. If the sequence has a handle acquired by other sequences
     297                 :            :         (reference count > 1), then the remaining elements are copied to a new sequence handle to
     298                 :            :         keep value semantics!
     299                 :            : 
     300                 :            :         @param nSize new size of sequence
     301                 :            :     */
     302                 :            :     inline void SAL_CALL realloc( sal_Int32 nSize );
     303                 :            : 
     304                 :            :     /** Returns the UNnacquired C handle of the sequence
     305                 :            : 
     306                 :            :         @return UNacquired handle of the sequence
     307                 :            :     */
     308                 :     734620 :     inline sal_Sequence * SAL_CALL getHandle() const SAL_THROW(())
     309                 :     734620 :         { return _pSequence; }
     310                 :            :     /** Returns the UNnacquired C handle of the sequence (for compatibility reasons)
     311                 :            : 
     312                 :            :         @return UNacquired handle of the sequence
     313                 :            :     */
     314                 :          6 :     inline sal_Sequence * SAL_CALL get() const SAL_THROW(())
     315                 :          6 :         { return _pSequence; }
     316                 :            : };
     317                 :            : 
     318                 :            : }
     319                 :            : #endif
     320                 :            : #endif
     321                 :            : 
     322                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10