bump product version to 5.0.4.1
[LibreOffice.git] / include / unotools / streamwrap.hxx
blob8efc22732220f66f41895b6b81ca89d44f7763b2
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
38 //= OInputStreamWrapper
40 typedef ::cppu::WeakImplHelper1 < css::io::XInputStream
41 > InputStreamWrapper_Base;
42 // needed for some compilers
43 /// helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
44 class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public InputStreamWrapper_Base
46 protected:
47 ::osl::Mutex m_aMutex;
48 SvStream* m_pSvStream;
49 bool m_bSvStreamOwner : 1;
50 OInputStreamWrapper()
51 { m_pSvStream = 0; m_bSvStreamOwner = false; }
52 void SetStream(SvStream* _pStream, bool bOwner )
53 { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; }
55 public:
56 OInputStreamWrapper(SvStream& _rStream);
57 OInputStreamWrapper(SvStream* pStream, bool bOwner=false);
58 virtual ~OInputStreamWrapper();
60 // css::io::XInputStream
61 virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
62 virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 virtual sal_Int32 SAL_CALL available() throw(css::io::NotConnectedException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
65 virtual void SAL_CALL closeInput() throw(css::io::NotConnectedException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
67 protected:
68 /// throws a NotConnectedException if the object is not connected anymore
69 void checkConnected() const;
70 /// throws an exception according to the error flag of m_pSvStream
71 void checkError() const;
74 //= OSeekableInputStreamWrapper
76 typedef ::cppu::ImplHelper1 < css::io::XSeekable
77 > OSeekableInputStreamWrapper_Base;
78 /** helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
79 which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
81 class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper : public ::cppu::ImplInheritanceHelper1 < OInputStreamWrapper, css::io::XSeekable >
83 protected:
84 OSeekableInputStreamWrapper() {}
85 public:
86 OSeekableInputStreamWrapper(SvStream& _rStream);
87 OSeekableInputStreamWrapper(SvStream* _pStream, bool _bOwner = false);
89 // XSeekable
90 virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (css::lang::IllegalArgumentException, css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
91 virtual sal_Int64 SAL_CALL getPosition( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
92 virtual sal_Int64 SAL_CALL getLength( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
95 //= OOutputStreamWrapper
97 typedef ::cppu::WeakImplHelper1<css::io::XOutputStream> OutputStreamWrapper_Base;
98 // needed for some compilers
99 class OOutputStreamWrapper : public OutputStreamWrapper_Base
101 public:
102 UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream& _rStream);
104 protected:
105 virtual ~OOutputStreamWrapper();
107 // css::io::XOutputStream
108 virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
109 virtual void SAL_CALL flush() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 virtual void SAL_CALL closeOutput() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 /// throws an exception according to the error flag of m_pSvStream
113 void checkError() const;
115 // TODO: thread safety!
116 SvStream& rStream;
119 //= OSeekableOutputStreamWrapper
121 typedef ::cppu::ImplHelper1 < css::io::XSeekable
122 > OSeekableOutputStreamWrapper_Base;
123 /** helper class for wrapping an SvStream into an com.sun.star.io::XOutputStream
124 which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
126 class UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper
127 :public OOutputStreamWrapper
128 ,public OSeekableOutputStreamWrapper_Base
130 public:
131 OSeekableOutputStreamWrapper(SvStream& _rStream);
133 private:
134 virtual ~OSeekableOutputStreamWrapper();
136 // disambiguate XInterface
137 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 virtual void SAL_CALL acquire( ) throw () SAL_OVERRIDE;
139 virtual void SAL_CALL release( ) throw () SAL_OVERRIDE;
141 // XSeekable
142 virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (css::lang::IllegalArgumentException, css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 virtual sal_Int64 SAL_CALL getPosition( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 virtual sal_Int64 SAL_CALL getLength( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 class UNOTOOLS_DLLPUBLIC OStreamWrapper : public ::cppu::ImplInheritanceHelper3 < OSeekableInputStreamWrapper, css::io::XStream, css::io::XOutputStream, css::io::XTruncate >
149 public:
150 OStreamWrapper(SvStream& _rStream);
152 // css::io::XStream
153 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 // css::io::XOutputStream
157 virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 virtual void SAL_CALL flush() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 virtual void SAL_CALL closeOutput() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 virtual void SAL_CALL truncate() throw(css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 // namespace utl
166 #endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */