LibreOffice Module comphelper (master) 1
seqstream.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#ifndef INCLUDED_COMPHELPER_SEQSTREAM_HXX
20#define INCLUDED_COMPHELPER_SEQSTREAM_HXX
21
22#include <config_options.h>
23#include <com/sun/star/uno/Sequence.hxx>
24#include <com/sun/star/io/XInputStream.hpp>
25#include <com/sun/star/io/XOutputStream.hpp>
26#include <com/sun/star/io/XSeekable.hpp>
27#include <com/sun/star/lang/XUnoTunnel.hpp>
31#include <mutex>
32
33namespace comphelper
34{
35
36
37// SequenceInputStream
38// stream for reading data from a sequence of bytes
39
40
42 : public ::cppu::WeakImplHelper< css::io::XInputStream, css::io::XSeekable, css::lang::XUnoTunnel >,
44{
46 css::uno::Sequence<sal_Int8> const m_aData;
47 sal_Int32 m_nPos;
48
49public:
50 SequenceInputStream(css::uno::Sequence<sal_Int8> const & rData);
51
52// css::io::XInputStream
53 virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead ) override;
54
55 virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead ) override;
56
57 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override;
58
59 virtual sal_Int32 SAL_CALL available( ) override;
60
61 virtual void SAL_CALL closeInput( ) override;
62
63 virtual void SAL_CALL seek( sal_Int64 location ) override;
64 virtual sal_Int64 SAL_CALL getPosition( ) override;
65 virtual sal_Int64 SAL_CALL getLength( ) override;
66
67// css::lang::XUnoTunnel
68 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
69
70// comphelper::ByteReader
71 virtual sal_Int32 readSomeBytes( sal_Int8* pData, sal_Int32 nBytesToRead ) override;
72
73private:
74 sal_Int32 avail();
75};
76
77// don't export to avoid duplicate WeakImplHelper definitions with MSVC
78class SAL_DLLPUBLIC_TEMPLATE OSequenceOutputStream_Base
79 : public ::cppu::WeakImplHelper< css::io::XOutputStream >
80{};
81
82class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OSequenceOutputStream final : public OSequenceOutputStream_Base
83{
84private:
85 css::uno::Sequence< sal_Int8 >& m_rSequence;
86 double m_nResizeFactor;
87 sal_Int32 const m_nMinimumResize;
88 sal_Int32 m_nSize;
89 // the size of the virtual stream. This is not the size of the sequence, but the number of bytes written
90 // into the stream at a given moment.
91
92 bool m_bConnected;
93 // closeOutput has been called ?
94
96
97 void finalizeOutput();
98 virtual ~OSequenceOutputStream() override { if (m_bConnected) finalizeOutput(); }
99
100public:
113 OSequenceOutputStream(
114 css::uno::Sequence< sal_Int8 >& _rSeq,
115 double _nResizeFactor = 1.3,
116 sal_Int32 _nMinimumResize = 128
117 );
118
120 virtual void SAL_CALL writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
122 virtual void SAL_CALL flush( ) override;
127 virtual void SAL_CALL closeOutput( ) override;
128};
129
130} // namespace comphelper
131
132#endif // INCLUDED_COMPHELPER_SEQSTREAM_HXX
133
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface that we can cast to, to bypass the inefficiency of using Sequence<sal_Int8> when reading vi...
Definition: bytereader.hxx:21
css::uno::Sequence< sal_Int8 > const m_aData
Definition: seqstream.hxx:46
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
#define COMPHELPER_DLLPUBLIC
::osl::Mutex m_aMutex
sal_uInt32 m_nSize
double getLength(const B2DPolygon &rCandidate)
std::mutex mutex
Definition: random.cxx:41
signed char sal_Int8