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
38 : public ::cppu::WeakImplHelper< css::io::XInputStream, css::io::XSeekable >,
39 public comphelper::ByteReader
40{
44 sal_Int32 m_nPos;
45
46public:
47 MemoryInputStream(const sal_Int8* pData, sal_Int32 nDataLength);
48
49// css::io::XInputStream
50 virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead ) override;
51
52 virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead ) override;
53
54 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override;
55
56 virtual sal_Int32 SAL_CALL available( ) override;
57
58 virtual void SAL_CALL closeInput( ) override;
59
60 virtual void SAL_CALL seek( sal_Int64 location ) override;
61 virtual sal_Int64 SAL_CALL getPosition( ) override;
62 virtual sal_Int64 SAL_CALL getLength( ) override;
63
64// comphelper::ByteReader
65 virtual sal_Int32 readSomeBytes( sal_Int8* pData, sal_Int32 nBytesToRead ) override;
66
67private:
68 sal_Int32 avail();
69};
70
71
72// Stream for reading data from a sequence of bytes
74 : public MemoryInputStream
75{
76 css::uno::Sequence<sal_Int8> const m_aData;
77
78public:
79 SequenceInputStream(css::uno::Sequence<sal_Int8> const & rData);
80};
81
82// don't export to avoid duplicate WeakImplHelper definitions with MSVC
83class SAL_DLLPUBLIC_TEMPLATE OSequenceOutputStream_Base
84 : public ::cppu::WeakImplHelper< css::io::XOutputStream >
85{};
86
87class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OSequenceOutputStream final : public OSequenceOutputStream_Base
88{
89private:
90 css::uno::Sequence< sal_Int8 >& m_rSequence;
91 double m_nResizeFactor;
92 sal_Int32 const m_nMinimumResize;
93 sal_Int32 m_nSize;
94 // the size of the virtual stream. This is not the size of the sequence, but the number of bytes written
95 // into the stream at a given moment.
96
97 bool m_bConnected;
98 // closeOutput has been called ?
99
101
102 void finalizeOutput();
103 virtual ~OSequenceOutputStream() override { if (m_bConnected) finalizeOutput(); }
104
105public:
118 OSequenceOutputStream(
119 css::uno::Sequence< sal_Int8 >& _rSeq,
120 double _nResizeFactor = 1.3,
121 sal_Int32 _nMinimumResize = 128
122 );
123
125 virtual void SAL_CALL writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
127 virtual void SAL_CALL flush( ) override;
132 virtual void SAL_CALL closeOutput( ) override;
133};
134
135} // namespace comphelper
136
137#endif // INCLUDED_COMPHELPER_SEQSTREAM_HXX
138
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for wrappers around memory data that want to be exposed as an XInputStream.
Definition: seqstream.hxx:40
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
const sal_Int8 * m_pMemoryData
Definition: seqstream.hxx:42
css::uno::Sequence< sal_Int8 > const m_aData
Definition: seqstream.hxx:76
#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