LCOV - code coverage report
Current view: top level - include/oox/helper - binarystreambase.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 5 0.0 %
Date: 2014-04-14 Functions: 0 7 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             : #ifndef INCLUDED_OOX_HELPER_BINARYSTREAMBASE_HXX
      21             : #define INCLUDED_OOX_HELPER_BINARYSTREAMBASE_HXX
      22             : 
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <boost/shared_ptr.hpp>
      25             : #include <oox/helper/helper.hxx>
      26             : #include <oox/dllapi.h>
      27             : 
      28             : namespace com { namespace sun { namespace star {
      29             :     namespace io { class XSeekable; }
      30             : } } }
      31             : 
      32             : namespace oox {
      33             : 
      34             : typedef ::com::sun::star::uno::Sequence< sal_Int8 > StreamDataSequence;
      35             : 
      36             : 
      37             : 
      38             : /** Base class for binary stream classes.
      39             :  */
      40             : class OOX_DLLPUBLIC BinaryStreamBase
      41             : {
      42             : public:
      43             :     virtual             ~BinaryStreamBase();
      44             : 
      45             :     /** Implementations return the size of the stream, if possible.
      46             : 
      47             :         This function may be implemented for some types of unseekable streams,
      48             :         and MUST be implemented for all seekable streams.
      49             : 
      50             :         @return
      51             :             The size of the stream in bytes, or -1, if not implemented.
      52             :      */
      53             :     virtual sal_Int64   size() const = 0;
      54             : 
      55             :     /** Implementations return the current stream position, if possible.
      56             : 
      57             :         This function may be implemented for some types of unseekable streams,
      58             :         and MUST be implemented for all seekable streams.
      59             : 
      60             :         @return
      61             :             The current position in the stream, or -1, if not implemented.
      62             :      */
      63             :     virtual sal_Int64   tell() const = 0;
      64             : 
      65             :     /** Implementations seek the stream to the passed position, if
      66             :         the stream is seekable.
      67             :      */
      68             :     virtual void        seek( sal_Int64 nPos ) = 0;
      69             : 
      70             :     /** Implementations close the stream.
      71             :      */
      72             :     virtual void        close() = 0;
      73             : 
      74             :     /** Returns true, if the implementation supports the seek() operation.
      75             : 
      76             :         Implementations may still implement size() and tell() even if the
      77             :         stream is not seekable.
      78             :      */
      79           0 :     bool         isSeekable() const { return mbSeekable; }
      80             : 
      81             :     /** Returns true, if the stream position is invalid (EOF). This flag turns
      82             :         true *after* the first attempt to seek/read beyond the stream end.
      83             :      */
      84           0 :     bool         isEof() const { return mbEof; }
      85             : 
      86             :     /** Returns the size of the remaining data available in the stream, if
      87             :         stream supports size() and tell(), otherwise -1.
      88             :      */
      89             :     sal_Int64           getRemaining() const;
      90             : 
      91             :     /** Seeks the stream to the beginning, if stream is seekable.
      92             :      */
      93           0 :     void         seekToStart() { seek( 0 ); }
      94             : 
      95             :     /** Seeks the stream to the end, if stream is seekable.
      96             :      */
      97             :     void         seekToEnd() { seek( size() ); }
      98             : 
      99             :     /** Seeks the stream forward to a position that is a multiple of the passed
     100             :         block size, if stream is seekable.
     101             : 
     102             :         @param nBlockSize
     103             :             The size of the data blocks the streams needs to be aligned to.
     104             : 
     105             :         @param nAnchorPos
     106             :             Position in the stream the data blocks are aligned to.
     107             :      */
     108             :     void                alignToBlock( sal_Int32 nBlockSize, sal_Int64 nAnchorPos = 0 );
     109             : 
     110             : protected:
     111           0 :     explicit            BinaryStreamBase( bool bSeekable ) : mbEof( false ), mbSeekable( bSeekable ) {}
     112             : 
     113             : private:
     114             :                         BinaryStreamBase( const BinaryStreamBase& );
     115             :     BinaryStreamBase&   operator=( const BinaryStreamBase& );
     116             : 
     117             : protected:
     118             :     bool                mbEof;          ///< End of stream flag.
     119             : 
     120             : private:
     121             :     const bool          mbSeekable;     ///< True = implementation supports seeking.
     122             : };
     123             : 
     124             : 
     125             : 
     126             : /** Base class for binary input and output streams wrapping a UNO stream,
     127             :     seekable via the com.sun.star.io.XSeekable interface.
     128             :  */
     129             : class OOX_DLLPUBLIC BinaryXSeekableStream : public virtual BinaryStreamBase
     130             : {
     131             : public:
     132             :     virtual             ~BinaryXSeekableStream();
     133             : 
     134             :     /** Returns the size of the stream, if wrapped stream is seekable, otherwise -1. */
     135             :     virtual sal_Int64   size() const SAL_OVERRIDE;
     136             :     /** Returns the current stream position, if wrapped stream is seekable, otherwise -1. */
     137             :     virtual sal_Int64   tell() const SAL_OVERRIDE;
     138             :     /** Seeks the stream to the passed position, if wrapped stream is seekable. */
     139             :     virtual void        seek( sal_Int64 nPos ) SAL_OVERRIDE;
     140             :     /** Releases the reference to the UNO XSeekable interface. */
     141             :     virtual void        close() SAL_OVERRIDE;
     142             : 
     143             : protected:
     144             :     explicit            BinaryXSeekableStream(
     145             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable >& rxSeekable );
     146             : 
     147             : private:
     148             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable >
     149             :                         mxSeekable;     ///< Stream seeking interface.
     150             : };
     151             : 
     152             : 
     153             : 
     154             : /** Base class for binary input and output streams wrapping a
     155             :     StreamDataSequence, which is always seekable.
     156             : 
     157             :     The wrapped data sequence MUST live at least as long as this stream
     158             :     wrapper. The data sequence MUST NOT be changed from outside as long as this
     159             :     stream wrapper is used to modify it.
     160             :  */
     161           0 : class OOX_DLLPUBLIC SequenceSeekableStream : public virtual BinaryStreamBase
     162             : {
     163             : public:
     164             :     /** Returns the size of the wrapped data sequence. */
     165             :     virtual sal_Int64   size() const SAL_OVERRIDE;
     166             :     /** Returns the current stream position. */
     167             :     virtual sal_Int64   tell() const SAL_OVERRIDE;
     168             :     /** Seeks the stream to the passed position. */
     169             :     virtual void        seek( sal_Int64 nPos ) SAL_OVERRIDE;
     170             :     /** Releases the reference to the data sequence. */
     171             :     virtual void        close() SAL_OVERRIDE;
     172             : 
     173             : protected:
     174             :     explicit            SequenceSeekableStream( const StreamDataSequence& rData );
     175             : 
     176             : protected:
     177             :     const StreamDataSequence* mpData;   ///< Wrapped data sequence.
     178             :     sal_Int32           mnPos;          ///< Current position in the sequence.
     179             : };
     180             : 
     181             : 
     182             : 
     183             : } // namespace oox
     184             : 
     185             : #endif
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10