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 <osl/mutex.hxx>
28 #include <cppuhelper/implbase.hxx>
30 
31 namespace comphelper
32 {
33 
34 
35 // SequenceInputStream
36 // stream for reading data from a sequence of bytes
37 
38 
40  : public ::cppu::WeakImplHelper< css::io::XInputStream, css::io::XSeekable >
41 {
42  ::osl::Mutex m_aMutex;
43  css::uno::Sequence<sal_Int8> const m_aData;
44  sal_Int32 m_nPos;
45 
46 public:
47  SequenceInputStream(css::uno::Sequence<sal_Int8> const & rData);
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 private:
65  inline sal_Int32 avail();
66 };
67 
68 // don't export to avoid duplicate WeakImplHelper definitions with MSVC
69 class SAL_DLLPUBLIC_TEMPLATE OSequenceOutputStream_Base
70  : public ::cppu::WeakImplHelper< css::io::XOutputStream >
71 {};
72 
73 class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OSequenceOutputStream final : public OSequenceOutputStream_Base
74 {
75 private:
76  void finalizeOutput();
77  css::uno::Sequence< sal_Int8 >& m_rSequence;
78  double m_nResizeFactor;
79  sal_Int32 const m_nMinimumResize;
80  sal_Int32 m_nSize;
81  // the size of the virtual stream. This is not the size of the sequence, but the number of bytes written
82  // into the stream at a given moment.
83 
84  bool m_bConnected;
85  // closeOutput has been called ?
86 
87  ::osl::Mutex m_aMutex;
88 
89  virtual ~OSequenceOutputStream() override { if (m_bConnected) finalizeOutput(); }
90 
91 public:
104  OSequenceOutputStream(
105  css::uno::Sequence< sal_Int8 >& _rSeq,
106  double _nResizeFactor = 1.3,
107  sal_Int32 _nMinimumResize = 128
108  );
109 
111  virtual void SAL_CALL writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
113  virtual void SAL_CALL flush( ) override;
118  virtual void SAL_CALL closeOutput( ) override;
119 };
120 
121 } // namespace comphelper
122 
123 #endif // INCLUDED_COMPHELPER_SEQSTREAM_HXX
124 
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aMutex
css::uno::Sequence< sal_Int8 > const m_aData
Definition: seqstream.hxx:43
double getLength(const B2DPolygon &rCandidate)
#define COMPHELPER_DLLPUBLIC
sal_uInt32 m_nSize