LCOV - code coverage report
Current view: top level - include/unotools - streamwrap.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 7 7 100.0 %
Date: 2014-04-11 Functions: 7 7 100.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             : #include <unotools/unotoolsdllapi.h>
      20             : 
      21             : #ifndef INCLUDED_UNOTOOLS_STREAMWRAP_HXX
      22             : #define INCLUDED_UNOTOOLS_STREAMWRAP_HXX
      23             : 
      24             : #include <osl/mutex.hxx>
      25             : #include <com/sun/star/io/XOutputStream.hpp>
      26             : #include <com/sun/star/io/XInputStream.hpp>
      27             : #include <com/sun/star/io/XSeekable.hpp>
      28             : #include <com/sun/star/io/XTruncate.hpp>
      29             : #include <com/sun/star/io/XStream.hpp>
      30             : #include <cppuhelper/implbase3.hxx>
      31             : #include <cppuhelper/implbase1.hxx>
      32             : 
      33             : class SvStream;
      34             : 
      35             : namespace utl
      36             : {
      37             :     namespace stario    = ::com::sun::star::io;
      38             :     namespace staruno   = ::com::sun::star::uno;
      39             : 
      40             : //= OInputStreamWrapper
      41             : 
      42             : typedef ::cppu::WeakImplHelper1 <   stario::XInputStream
      43             :                                 > InputStreamWrapper_Base;
      44             : // needed for some compilers
      45             : /// helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
      46             : class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public InputStreamWrapper_Base
      47             : {
      48             : protected:
      49             :     ::osl::Mutex    m_aMutex;
      50             :     SvStream*       m_pSvStream;
      51             :     bool        m_bSvStreamOwner : 1;
      52         834 :     OInputStreamWrapper()
      53         834 :                     { m_pSvStream = 0; m_bSvStreamOwner = false; }
      54         834 :     void            SetStream(SvStream* _pStream, bool bOwner )
      55         834 :                     { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; }
      56             : 
      57             : public:
      58             :     OInputStreamWrapper(SvStream& _rStream);
      59             :     OInputStreamWrapper(SvStream* pStream, bool bOwner=false);
      60             :     virtual ~OInputStreamWrapper();
      61             : 
      62             : // stario::XInputStream
      63             :     virtual sal_Int32   SAL_CALL    readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             :     virtual sal_Int32   SAL_CALL    readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
      65             :     virtual void        SAL_CALL    skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             :     virtual sal_Int32   SAL_CALL    available() throw(stario::NotConnectedException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             :     virtual void        SAL_CALL    closeInput() throw(stario::NotConnectedException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
      68             : 
      69             : protected:
      70             :     /// throws a NotConnectedException if the object is not connected anymore
      71             :     void checkConnected() const;
      72             :     /// throws an exception according to the error flag of m_pSvStream
      73             :     void checkError() const;
      74             : };
      75             : 
      76             : //= OSeekableInputStreamWrapper
      77             : 
      78             : typedef ::cppu::ImplHelper1 <   ::com::sun::star::io::XSeekable
      79             :                             >   OSeekableInputStreamWrapper_Base;
      80             : /** helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
      81             :     which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
      82             : */
      83        1296 : class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper : public ::cppu::ImplInheritanceHelper1 < OInputStreamWrapper, com::sun::star::io::XSeekable >
      84             : {
      85             : protected:
      86         368 :     OSeekableInputStreamWrapper() {}
      87             : public:
      88             :     OSeekableInputStreamWrapper(SvStream& _rStream);
      89             :     OSeekableInputStreamWrapper(SvStream* _pStream, bool _bOwner = false);
      90             : 
      91             :     // XSeekable
      92             :     virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      93             :     virtual sal_Int64 SAL_CALL getPosition(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      94             :     virtual sal_Int64 SAL_CALL getLength(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      95             : };
      96             : 
      97             : //= OOutputStreamWrapper
      98             : 
      99             : typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base;
     100             :     // needed for some compilers
     101             : class OOutputStreamWrapper : public OutputStreamWrapper_Base
     102             : {
     103             : public:
     104             :     UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream& _rStream);
     105             : 
     106             : protected:
     107             :     virtual ~OOutputStreamWrapper();
     108             : 
     109             : // stario::XOutputStream
     110             :     virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
     111             :     virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
     112             :     virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
     113             : 
     114             :     /// throws an exception according to the error flag of m_pSvStream
     115             :     void checkError() const;
     116             : 
     117             :     // TODO: thread safety!
     118             :     SvStream&       rStream;
     119             : };
     120             : 
     121             : //= OSeekableOutputStreamWrapper
     122             : 
     123             : typedef ::cppu::ImplHelper1 <   ::com::sun::star::io::XSeekable
     124             :                             >   OSeekableOutputStreamWrapper_Base;
     125             : /** helper class for wrapping an SvStream into an com.sun.star.io::XOutputStream
     126             :     which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
     127             : */
     128             : class OSeekableOutputStreamWrapper
     129             :                 :public OOutputStreamWrapper
     130             :                 ,public OSeekableOutputStreamWrapper_Base
     131             : {
     132             : public:
     133             :     UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper(SvStream& _rStream);
     134             : 
     135             : private:
     136             :     virtual ~OSeekableOutputStreamWrapper();
     137             : 
     138             :     // disambiguate XInterface
     139             :     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     140             :     virtual void SAL_CALL acquire(  ) throw () SAL_OVERRIDE;
     141             :     virtual void SAL_CALL release(  ) throw () SAL_OVERRIDE;
     142             : 
     143             :     // XSeekable
     144             :     virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     145             :     virtual sal_Int64 SAL_CALL getPosition(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             :     virtual sal_Int64 SAL_CALL getLength(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     147             : };
     148             : 
     149         736 : class UNOTOOLS_DLLPUBLIC OStreamWrapper : public ::cppu::ImplInheritanceHelper3 < OSeekableInputStreamWrapper, com::sun::star::io::XStream, com::sun::star::io::XOutputStream, com::sun::star::io::XTruncate >
     150             : {
     151             : public:
     152             :     OStreamWrapper(SvStream& _rStream);
     153             : 
     154             : // stario::XStream
     155             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     156             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     157             : 
     158             : // stario::XOutputStream
     159             :     virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
     160             :     virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
     161             :     virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException, std::exception) SAL_OVERRIDE;
     162             :     virtual void SAL_CALL truncate() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     163             : };
     164             : 
     165             : }
     166             : // namespace utl
     167             : 
     168             : #endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10