LCOV - code coverage report
Current view: top level - libreoffice/io/source/stm - streamhelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 15 0.0 %
Date: 2012-12-27 Functions: 0 20 0.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             : 
      20             : // Save NDEBUG state
      21             : #ifdef NDEBUG
      22             : #define STREAMHELPER_HXX_HAD_NDEBUG
      23             : #undef NDEBUG
      24             : #endif
      25             : 
      26             : #if OSL_DEBUG_LEVEL == 0
      27             : #define NDEBUG
      28             : #endif
      29             : #include <assert.h>
      30             : 
      31             : #define Max( a, b )     (((a)>(b)) ? (a) : (b) )
      32             : #define Min( a, b )     (((a)<(b)) ? (a) : (b) )
      33             : 
      34             : namespace io_stm {
      35             : 
      36           0 : class I_FIFO_OutOfBoundsException :
      37             :                 public Exception
      38             : {};
      39             : 
      40           0 : class I_FIFO_OutOfMemoryException :
      41             :                 public Exception
      42             : {};
      43             : 
      44           0 : class I_FIFO
      45             : {
      46             : public:
      47             : 
      48             : 
      49             :     virtual void    write( const Sequence<sal_Int8> &) throw( I_FIFO_OutOfMemoryException,
      50             :                                                               I_FIFO_OutOfBoundsException )=0;
      51             : 
      52             :     virtual void    read( Sequence<sal_Int8> & , sal_Int32 nBytesToRead )
      53             :                                                        throw( I_FIFO_OutOfBoundsException )=0;
      54             :     virtual void    skip( sal_Int32 nBytesToSkip )
      55             :                                                        throw( I_FIFO_OutOfBoundsException )=0;
      56             :     virtual sal_Int32   getSize() const throw(  )  =0;
      57             :     virtual void    shrink() throw() = 0;
      58             : 
      59           0 :     virtual ~I_FIFO() {};
      60             : };
      61             : 
      62             : 
      63           0 : class IRingBuffer_OutOfBoundsException :
      64             :                 public Exception
      65             : {};
      66             : 
      67           0 : class IRingBuffer_OutOfMemoryException :
      68             :                 public Exception
      69             : {};
      70             : 
      71           0 : class IRingBuffer
      72             : {
      73             : public:
      74             :     /***
      75             :     * overwrites data at given position. Size is automatically extended, when
      76             :     * data is written beyond end.
      77             :     *
      78             :     ***/
      79             : 
      80             :     virtual void    writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &)
      81             :         throw( IRingBuffer_OutOfMemoryException,
      82             :                IRingBuffer_OutOfBoundsException )=0;
      83             :     virtual void    readAt( sal_Int32 nPos, Sequence<sal_Int8> & , sal_Int32 nBytesToRead ) const
      84             :         throw( IRingBuffer_OutOfBoundsException )=0;
      85             :     virtual sal_Int32   getSize() const throw(  )  =0;
      86             :     virtual void    forgetFromStart( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException)=0;
      87             :     virtual void    forgetFromEnd( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException)=0;
      88             :     virtual void    shrink() throw() = 0;
      89           0 :     virtual ~IRingBuffer() {};
      90             : };
      91             : 
      92             : 
      93             : class MemRingBuffer :
      94             :         public IRingBuffer
      95             : {
      96             : public:
      97             :     MemRingBuffer();
      98             :     virtual ~MemRingBuffer();
      99             : 
     100             :     virtual void    writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &)
     101             :                                                     throw(  IRingBuffer_OutOfMemoryException,
     102             :                                                                 IRingBuffer_OutOfBoundsException );
     103             :     virtual void    readAt( sal_Int32 nPos, Sequence<sal_Int8> & , sal_Int32 nBytesToRead ) const
     104             :                                                     throw( IRingBuffer_OutOfBoundsException );
     105             :     virtual sal_Int32   getSize() const throw(  );
     106             :     virtual void    forgetFromStart( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException);
     107             :     virtual void    forgetFromEnd( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException);
     108             : 
     109             :     virtual void shrink() throw();
     110             : 
     111             : private:
     112             : 
     113             :     void resizeBuffer( sal_Int32 nMinSize ) throw( IRingBuffer_OutOfMemoryException );
     114           0 :     inline void checkInvariants()
     115             :     {
     116             :         assert( m_nBufferLen >= 0 );
     117             :         assert( m_nOccupiedBuffer >= 0 );
     118             :         assert( m_nOccupiedBuffer <= m_nBufferLen );
     119             :         assert( m_nStart >= 0 );
     120             :         assert( 0 == m_nStart || m_nStart < m_nBufferLen );
     121           0 :     }
     122             : 
     123             :     sal_Int8    *m_p;
     124             :     sal_Int32   m_nBufferLen;
     125             :     sal_Int32   m_nStart;
     126             :     sal_Int32   m_nOccupiedBuffer;
     127             : };
     128             : 
     129             : 
     130           0 : class MemFIFO :
     131             :     public  I_FIFO,
     132             :     private MemRingBuffer
     133             : {
     134             : public:
     135             :     virtual void    write( const Sequence<sal_Int8> &) throw( I_FIFO_OutOfMemoryException,
     136             :                                                               I_FIFO_OutOfBoundsException );
     137             :     virtual void    read( Sequence<sal_Int8> & , sal_Int32 nBytesToRead )
     138             :                                                        throw( I_FIFO_OutOfBoundsException );
     139             :     virtual void    skip( sal_Int32 nBytesToSkip ) throw( I_FIFO_OutOfBoundsException );
     140           0 :     virtual sal_Int32   getSize()  const throw(  )
     141           0 :                         { return MemRingBuffer::getSize(); }
     142           0 :     virtual void    shrink() throw()
     143           0 :                         { MemRingBuffer::shrink(); }
     144             : 
     145             : };
     146             : 
     147             : // Restore NDEBUG state
     148             : #ifdef STREAMHELPER_HXX_HAD_NDEBUG
     149             : #define NDEBUG
     150             : #else
     151             : #undef NDEBUG
     152             : #endif
     153             : 
     154             : }
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10