LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/helper - binarystreambase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 56 64.3 %
Date: 2013-07-09 Functions: 10 19 52.6 %
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             : #include "oox/helper/binarystreambase.hxx"
      21             : 
      22             : #include <com/sun/star/io/XSeekable.hpp>
      23             : #include <osl/diagnose.h>
      24             : 
      25             : namespace oox {
      26             : 
      27             : // ============================================================================
      28             : 
      29             : using namespace ::com::sun::star::io;
      30             : using namespace ::com::sun::star::uno;
      31             : 
      32             : // ============================================================================
      33             : 
      34        3949 : BinaryStreamBase::~BinaryStreamBase()
      35             : {
      36        3949 : }
      37             : 
      38          82 : sal_Int64 BinaryStreamBase::getRemaining() const
      39             : {
      40             :     // do not use isSeekable(), implementations may provide stream position and size even if not seekable
      41          82 :     sal_Int64 nPos = tell();
      42          82 :     sal_Int64 nLen = size();
      43          82 :     return ((nPos >= 0) && (nLen >= 0)) ? ::std::max< sal_Int64 >( nLen - nPos, 0 ) : -1;
      44             : }
      45             : 
      46           2 : void BinaryStreamBase::alignToBlock( sal_Int32 nBlockSize, sal_Int64 nAnchorPos )
      47             : {
      48           2 :     sal_Int64 nStrmPos = tell();
      49             :     // nothing to do, if stream is at anchor position
      50           2 :     if( mbSeekable && (0 <= nAnchorPos) && (nAnchorPos != nStrmPos) && (nBlockSize > 1) )
      51             :     {
      52             :         // prevent modulo with negative arguments...
      53             :         sal_Int64 nSkipSize = (nAnchorPos < nStrmPos) ?
      54           2 :             (nBlockSize - ((nStrmPos - nAnchorPos - 1) % nBlockSize) - 1) :
      55           4 :             ((nAnchorPos - nStrmPos) % nBlockSize);
      56           2 :         seek( nStrmPos + nSkipSize );
      57             :     }
      58           2 : }
      59             : 
      60             : // ============================================================================
      61             : 
      62        1477 : BinaryXSeekableStream::BinaryXSeekableStream( const Reference< XSeekable >& rxSeekable ) :
      63           0 :     BinaryStreamBase( mxSeekable.is() ),
      64        1477 :     mxSeekable( rxSeekable )
      65             : {
      66        1477 : }
      67             : 
      68        1477 : BinaryXSeekableStream::~BinaryXSeekableStream()
      69             : {
      70        1477 : }
      71             : 
      72          97 : sal_Int64 BinaryXSeekableStream::size() const
      73             : {
      74          97 :     if( mxSeekable.is() ) try
      75             :     {
      76          97 :         return mxSeekable->getLength();
      77             :     }
      78           0 :     catch( Exception& )
      79             :     {
      80             :         OSL_FAIL( "BinaryXSeekableStream::size - exception caught" );
      81             :     }
      82           0 :     return -1;
      83             : }
      84             : 
      85         353 : sal_Int64 BinaryXSeekableStream::tell() const
      86             : {
      87         353 :     if( mxSeekable.is() ) try
      88             :     {
      89         353 :         return mxSeekable->getPosition();
      90             :     }
      91           0 :     catch( Exception& )
      92             :     {
      93             :         OSL_FAIL( "BinaryXSeekableStream::tell - exception caught" );
      94             :     }
      95           0 :     return -1;
      96             : }
      97             : 
      98         397 : void BinaryXSeekableStream::seek( sal_Int64 nPos )
      99             : {
     100         397 :     if( mxSeekable.is() ) try
     101             :     {
     102         397 :         mbEof = false;
     103         397 :         mxSeekable->seek( nPos );
     104             :     }
     105           0 :     catch( Exception& )
     106             :     {
     107           0 :         mbEof = true;
     108             :     }
     109         397 : }
     110             : 
     111        1477 : void BinaryXSeekableStream::close()
     112             : {
     113        1477 :     mxSeekable.clear();
     114        1477 :     mbEof = true;
     115        1477 : }
     116             : 
     117             : // ============================================================================
     118             : 
     119        2218 : SequenceSeekableStream::SequenceSeekableStream( const StreamDataSequence& rData ) :
     120             :     BinaryStreamBase( true ),
     121             :     mpData( &rData ),
     122        2218 :     mnPos( 0 )
     123             : {
     124        2218 : }
     125             : 
     126           0 : sal_Int64 SequenceSeekableStream::size() const
     127             : {
     128           0 :     return mpData ? mpData->getLength() : -1;
     129             : }
     130             : 
     131           0 : sal_Int64 SequenceSeekableStream::tell() const
     132             : {
     133           0 :     return mpData ? mnPos : -1;
     134             : }
     135             : 
     136           0 : void SequenceSeekableStream::seek( sal_Int64 nPos )
     137             : {
     138           0 :     if( mpData )
     139             :     {
     140           0 :         mnPos = getLimitedValue< sal_Int32, sal_Int64 >( nPos, 0, mpData->getLength() );
     141           0 :         mbEof = mnPos != nPos;
     142             :     }
     143           0 : }
     144             : 
     145           0 : void SequenceSeekableStream::close()
     146             : {
     147           0 :     mpData = 0;
     148           0 :     mbEof = true;
     149           0 : }
     150             : 
     151             : // ============================================================================
     152             : 
     153             : } // namespace oox
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10