LibreOffice Module unotools (master) 1
streamwrap.hxx
Go to the documentation of this file.
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_UNOTOOLS_STREAMWRAP_HXX
21#define INCLUDED_UNOTOOLS_STREAMWRAP_HXX
22
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 <com/sun/star/lang/XUnoTunnel.hpp>
33#include <memory>
34#include <mutex>
35
36class SvStream;
37
38namespace utl
39{
40
41// workaround for incremental linking bugs in MSVC2015
42class SAL_DLLPUBLIC_TEMPLATE OInputStreamWrapper_Base : public cppu::WeakImplHelper< css::io::XInputStream > {};
43
45class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public OInputStreamWrapper_Base, public comphelper::ByteReader
46{
47protected:
52 { m_pSvStream = nullptr; m_bSvStreamOwner = false; }
53 void SetStream(SvStream* _pStream, bool bOwner )
54 { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; }
55
56public:
58 OInputStreamWrapper(SvStream* pStream, bool bOwner=false);
59 OInputStreamWrapper(std::unique_ptr<SvStream> pStream);
60 virtual ~OInputStreamWrapper() override;
61
62// css::io::XInputStream
63 virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) override;
64 virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) override;
65 virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override;
66 virtual sal_Int32 SAL_CALL available() override;
67 virtual void SAL_CALL closeInput() override;
68
69// utl::ByteReader
70 virtual sal_Int32 readSomeBytes( sal_Int8* aData, sal_Int32 nMaxBytesToRead ) final override;
71
72protected:
74 void checkConnected() const;
76 void checkError() const;
77};
78
79//= OSeekableInputStreamWrapper
80
85 : public cppu::ImplInheritanceHelper< OInputStreamWrapper, css::io::XSeekable >
86{
87protected:
90
91public:
93 OSeekableInputStreamWrapper(SvStream* _pStream, bool _bOwner = false);
94
95 // XSeekable
96 virtual void SAL_CALL seek( sal_Int64 _nLocation ) override;
97 virtual sal_Int64 SAL_CALL getPosition( ) override;
98 virtual sal_Int64 SAL_CALL getLength( ) override;
99};
100
101//= OOutputStreamWrapper
102
103class OOutputStreamWrapper : public cppu::WeakImplHelper<css::io::XOutputStream>
104{
105public:
107
108protected:
109 virtual ~OOutputStreamWrapper() override;
110
111// css::io::XOutputStream
112 virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) override;
113 virtual void SAL_CALL flush() override;
114 virtual void SAL_CALL closeOutput() override;
115
117 void checkError() const;
118
119 // TODO: thread safety!
121};
122
123//= OSeekableOutputStreamWrapper
124
125typedef ::cppu::ImplHelper1 < css::io::XSeekable
133{
134public:
136
137private:
138 virtual ~OSeekableOutputStreamWrapper() override;
139
140 // disambiguate XInterface
141 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override;
142 virtual void SAL_CALL acquire( ) noexcept override
143 { OOutputStreamWrapper::acquire(); }
144 virtual void SAL_CALL release( ) noexcept override
145 { OOutputStreamWrapper::release(); }
146
147 // XSeekable
148 virtual void SAL_CALL seek( sal_Int64 _nLocation ) override;
149 virtual sal_Int64 SAL_CALL getPosition( ) override;
150 virtual sal_Int64 SAL_CALL getLength( ) override;
151};
152
154 : public cppu::ImplInheritanceHelper<OSeekableInputStreamWrapper,
155 css::io::XStream,
156 css::io::XOutputStream,
157 css::io::XTruncate>
158{
159 ~OStreamWrapper() override;
160
161public:
162 OStreamWrapper(SvStream& _rStream);
163 OStreamWrapper(std::unique_ptr<SvStream> _rStream);
164 OStreamWrapper(SvStream* _pStream, bool _bOwner = false);
165
166// css::io::XStream
167 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
168 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) override;
169
170// css::io::XOutputStream
171 virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) override;
172 virtual void SAL_CALL flush() override;
173 virtual void SAL_CALL closeOutput() override;
174 virtual void SAL_CALL truncate() override;
175};
176
177}
178// namespace utl
179
180#endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
helper class for wrapping an SvStream into a com.sun.star.io::XInputStream
Definition: streamwrap.hxx:46
void SetStream(SvStream *_pStream, bool bOwner)
Definition: streamwrap.hxx:53
UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream &_rStream)
Definition: streamwrap.cxx:207
void checkError() const
throws an exception according to the error flag of m_pSvStream
Definition: streamwrap.cxx:235
virtual void SAL_CALL closeOutput() override
Definition: streamwrap.cxx:231
virtual ~OOutputStreamWrapper() override
Definition: streamwrap.cxx:211
virtual void SAL_CALL flush() override
Definition: streamwrap.cxx:225
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
Definition: streamwrap.cxx:213
helper class for wrapping an SvStream into a com.sun.star.io::XInputStream which is seekable (i....
Definition: streamwrap.hxx:86
helper class for wrapping an SvStream into a com.sun.star.io::XOutputStream which is seekable (i....
Definition: streamwrap.hxx:133
virtual void SAL_CALL release() noexcept override
Definition: streamwrap.hxx:144
virtual void SAL_CALL acquire() noexcept override
Definition: streamwrap.hxx:142
~OStreamWrapper() override
constexpr OUStringLiteral aData
double getLength(const B2DPolygon &rCandidate)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool getOutputStream(ProgramOptions const &options, OString const &extension, std::ostream **ppOutputStream, OString &targetSourceFileName, OString &tmpSourceFileName)
::cppu::ImplHelper1< css::io::XSeekable > OSeekableOutputStreamWrapper_Base
Definition: streamwrap.hxx:126
std::mutex mutex
Definition: textsearch.cxx:94
signed char sal_Int8
#define UNOTOOLS_DLLPUBLIC