bump product version to 4.2.0.1
[LibreOffice.git] / include / unotools / streamwrap.hxx
blob7060742afba90dc2d213e3101b44d252dc01af19
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <unotools/unotoolsdllapi.h>
21 #ifndef INCLUDED_UNOTOOLS_STREAMWRAP_HXX
22 #define INCLUDED_UNOTOOLS_STREAMWRAP_HXX
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>
33 class SvStream;
35 namespace utl
37 namespace stario = ::com::sun::star::io;
38 namespace staruno = ::com::sun::star::uno;
40 //==================================================================
41 //= OInputStreamWrapper
42 //==================================================================
43 typedef ::cppu::WeakImplHelper1 < stario::XInputStream
44 > InputStreamWrapper_Base;
45 // needed for some compilers
46 /// helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
47 class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public InputStreamWrapper_Base
49 protected:
50 ::osl::Mutex m_aMutex;
51 SvStream* m_pSvStream;
52 sal_Bool m_bSvStreamOwner : 1;
53 OInputStreamWrapper()
54 { m_pSvStream = 0; m_bSvStreamOwner = sal_False; }
55 void SetStream(SvStream* _pStream, sal_Bool bOwner )
56 { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; }
58 public:
59 OInputStreamWrapper(SvStream& _rStream);
60 OInputStreamWrapper(SvStream* pStream, sal_Bool bOwner=sal_False);
61 virtual ~OInputStreamWrapper();
63 // stario::XInputStream
64 virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
65 virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
66 virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
67 virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException);
68 virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException);
70 protected:
71 /// throws a NotConnectedException if the object is not connected anymore
72 void checkConnected() const;
73 /// throws an exception according to the error flag of m_pSvStream
74 void checkError() const;
77 //==================================================================
78 //= OSeekableInputStreamWrapper
79 //==================================================================
80 typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable
81 > OSeekableInputStreamWrapper_Base;
82 /** helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
83 which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
85 class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper : public ::cppu::ImplInheritanceHelper1 < OInputStreamWrapper, com::sun::star::io::XSeekable >
87 protected:
88 OSeekableInputStreamWrapper() {}
89 public:
90 OSeekableInputStreamWrapper(SvStream& _rStream);
91 OSeekableInputStreamWrapper(SvStream* _pStream, sal_Bool _bOwner = sal_False);
93 // XSeekable
94 virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
95 virtual sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
96 virtual sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
99 //==================================================================
100 //= OOutputStreamWrapper
101 //==================================================================
102 typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base;
103 // needed for some compilers
104 class OOutputStreamWrapper : public OutputStreamWrapper_Base
106 public:
107 UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream& _rStream);
109 protected:
110 virtual ~OOutputStreamWrapper();
112 // stario::XOutputStream
113 virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
114 virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
115 virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
117 /// throws an exception according to the error flag of m_pSvStream
118 void checkError() const;
120 // TODO: thread safety!
121 SvStream& rStream;
124 //==================================================================
125 //= OSeekableOutputStreamWrapper
126 //==================================================================
127 typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable
128 > OSeekableOutputStreamWrapper_Base;
129 /** helper class for wrapping an SvStream into an com.sun.star.io::XOutputStream
130 which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
132 class OSeekableOutputStreamWrapper
133 :public OOutputStreamWrapper
134 ,public OSeekableOutputStreamWrapper_Base
136 public:
137 UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper(SvStream& _rStream);
139 private:
140 virtual ~OSeekableOutputStreamWrapper();
142 // disambiguate XInterface
143 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
144 virtual void SAL_CALL acquire( ) throw ();
145 virtual void SAL_CALL release( ) throw ();
147 // XSeekable
148 virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
149 virtual sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
150 virtual sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
153 class UNOTOOLS_DLLPUBLIC OStreamWrapper : public ::cppu::ImplInheritanceHelper3 < OSeekableInputStreamWrapper, com::sun::star::io::XStream, com::sun::star::io::XOutputStream, com::sun::star::io::XTruncate >
155 public:
156 OStreamWrapper(SvStream& _rStream);
158 // stario::XStream
159 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException);
160 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException);
162 // stario::XOutputStream
163 virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
164 virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
165 virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
166 virtual void SAL_CALL truncate() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
170 // namespace utl
172 #endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */