Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / include / unotools / streamwrap.hxx
blob5eddbd6ffcffd88702701103d1a3d3febd09953e
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 .
20 #ifndef INCLUDED_UNOTOOLS_STREAMWRAP_HXX
21 #define INCLUDED_UNOTOOLS_STREAMWRAP_HXX
23 #include <unotools/unotoolsdllapi.h>
24 #include <com/sun/star/io/XOutputStream.hpp>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/io/XSeekable.hpp>
27 #include <com/sun/star/io/XTruncate.hpp>
28 #include <com/sun/star/io/XStream.hpp>
29 #include <comphelper/bytereader.hxx>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/implbase1.hxx>
32 #include <memory>
33 #include <mutex>
35 class SvStream;
37 namespace utl
40 // workaround for incremental linking bugs in MSVC2015
41 class SAL_DLLPUBLIC_TEMPLATE OInputStreamWrapper_Base : public cppu::WeakImplHelper< css::io::XInputStream > {};
43 /// helper class for wrapping an SvStream into a com.sun.star.io::XInputStream
44 class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public OInputStreamWrapper_Base, public comphelper::ByteReader
46 protected:
47 std::mutex m_aMutex;
48 SvStream* m_pSvStream;
49 bool m_bSvStreamOwner : 1;
50 OInputStreamWrapper()
51 { m_pSvStream = nullptr; 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 OInputStreamWrapper(std::unique_ptr<SvStream> pStream);
59 virtual ~OInputStreamWrapper() override;
61 // css::io::XInputStream
62 virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) override final;
63 virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) override final;
64 virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override final;
65 virtual sal_Int32 SAL_CALL available() override final;
66 virtual void SAL_CALL closeInput() override final;
68 // utl::ByteReader
69 virtual sal_Int32 readSomeBytes( sal_Int8* aData, sal_Int32 nMaxBytesToRead ) final override;
71 protected:
72 /// throws a NotConnectedException if the object is not connected anymore
73 void checkConnected() const;
74 /// throws an exception according to the error flag of m_pSvStream
75 void checkError() const;
78 //= OSeekableInputStreamWrapper
80 /** helper class for wrapping an SvStream into a com.sun.star.io::XInputStream
81 which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
83 class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper
84 : public cppu::ImplInheritanceHelper< OInputStreamWrapper, css::io::XSeekable >
86 protected:
87 OSeekableInputStreamWrapper() {}
88 ~OSeekableInputStreamWrapper() override;
90 public:
91 OSeekableInputStreamWrapper(SvStream& _rStream);
92 OSeekableInputStreamWrapper(SvStream* _pStream, bool _bOwner = false);
94 // XSeekable
95 virtual void SAL_CALL seek( sal_Int64 _nLocation ) override final;
96 virtual sal_Int64 SAL_CALL getPosition( ) override final;
97 virtual sal_Int64 SAL_CALL getLength( ) override final;
100 //= OOutputStreamWrapper
102 class UNOTOOLS_DLLPUBLIC OOutputStreamWrapper : public cppu::WeakImplHelper<css::io::XOutputStream>
104 public:
105 OOutputStreamWrapper(SvStream& _rStream);
107 // css::io::XOutputStream
108 virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) override final;
109 virtual void SAL_CALL flush() override final;
110 virtual void SAL_CALL closeOutput() override final;
112 protected:
113 virtual ~OOutputStreamWrapper() override;
115 /// throws an exception according to the error flag of m_pSvStream
116 void checkError() const;
118 // TODO: thread safety!
119 SvStream& rStream;
122 //= OSeekableOutputStreamWrapper
124 typedef ::cppu::ImplHelper1 < css::io::XSeekable
125 > OSeekableOutputStreamWrapper_Base;
126 /** helper class for wrapping an SvStream into a com.sun.star.io::XOutputStream
127 which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
129 class UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper final
130 :public OOutputStreamWrapper
131 ,public OSeekableOutputStreamWrapper_Base
133 public:
134 OSeekableOutputStreamWrapper(SvStream& _rStream);
136 private:
137 virtual ~OSeekableOutputStreamWrapper() override;
139 // disambiguate XInterface
140 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override;
141 virtual void SAL_CALL acquire( ) noexcept override
142 { OOutputStreamWrapper::acquire(); }
143 virtual void SAL_CALL release( ) noexcept override
144 { OOutputStreamWrapper::release(); }
146 // XSeekable
147 virtual void SAL_CALL seek( sal_Int64 _nLocation ) override;
148 virtual sal_Int64 SAL_CALL getPosition( ) override;
149 virtual sal_Int64 SAL_CALL getLength( ) override;
152 class UNOTOOLS_DLLPUBLIC OStreamWrapper final
153 : public cppu::ImplInheritanceHelper<OSeekableInputStreamWrapper,
154 css::io::XStream,
155 css::io::XOutputStream,
156 css::io::XTruncate>
158 ~OStreamWrapper() override;
160 public:
161 OStreamWrapper(SvStream& _rStream);
162 OStreamWrapper(std::unique_ptr<SvStream> _rStream);
163 OStreamWrapper(SvStream* _pStream, bool _bOwner = false);
165 // css::io::XStream
166 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
167 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) override;
169 // css::io::XOutputStream
170 virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) override;
171 virtual void SAL_CALL flush() override;
172 virtual void SAL_CALL closeOutput() override;
173 virtual void SAL_CALL truncate() override;
177 // namespace utl
179 #endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */