LibreOffice Module oox (master) 1
binaryoutputstream.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_OOX_HELPER_BINARYOUTPUTSTREAM_HXX
21#define INCLUDED_OOX_HELPER_BINARYOUTPUTSTREAM_HXX
22
23#include <cstddef>
24#include <memory>
25
26#include <com/sun/star/uno/Reference.hxx>
27#include <oox/dllapi.h>
29#include <oox/helper/helper.hxx>
30#include <rtl/textenc.h>
31#include <rtl/ustring.hxx>
32#include <sal/types.h>
33
34namespace com::sun::star {
35 namespace io { class XOutputStream; }
36}
37
38namespace oox {
39
40
46{
47public:
55 virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ) = 0;
56
64 virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) = 0;
65
66 template< typename Type >
67 void writeArray( Type* opnArray, sal_Int32 nElemCount );
68
69 template< typename Type >
70 void writeArray( const Type* opnArray, sal_Int32 nElemCount );
71
75 template< typename Type >
76 void writeValue( Type nValue );
77
78 BinaryOutputStream& WriteInt16(sal_Int16 x) { writeValue(x); return *this; }
79 BinaryOutputStream& WriteUInt16(sal_uInt16 x) { writeValue(x); return *this; }
80 BinaryOutputStream& WriteInt32(sal_Int32 x) { writeValue(x); return *this; }
81 BinaryOutputStream& WriteUInt32(sal_uInt32 x) { writeValue(x); return *this; }
82 BinaryOutputStream& WriteInt64(sal_Int64 x) { writeValue(x); return *this; }
83
84 void writeCompressedUnicodeArray( const OUString& rString, bool bCompressed );
85
86 void writeCharArrayUC( std::u16string_view rString, rtl_TextEncoding eTextEnc );
87
88 void writeUnicodeArray( const OUString& rString );
89
90protected:
94
95private:
98};
99
100template< typename Type >
101void BinaryOutputStream::writeArray( Type* opnArray, sal_Int32 nElemCount )
102{
103 sal_Int32 nWriteSize = getLimitedValue< sal_Int32, sal_Int32 >( nElemCount, 0, SAL_MAX_INT32 / sizeof( Type ) ) * sizeof( Type );
104 ByteOrderConverter::convertLittleEndianArray( opnArray, static_cast< size_t >( nElemCount ) );
105 writeMemory( opnArray, nWriteSize, sizeof( Type ) );
106}
107
108template< typename Type >
109void BinaryOutputStream::writeArray( const Type* opnArray, sal_Int32 nElemCount )
110{
111 std::unique_ptr<Type[]> xArray(new Type[nElemCount]);
112 std::uninitialized_copy(opnArray, opnArray + nElemCount, xArray.get());
113 writeArray(xArray.get(), nElemCount);
114}
115
116template< typename Type >
118{
120 writeMemory( &nValue, static_cast< sal_Int32 >( sizeof( Type ) ), sizeof( Type ) );
121}
122
123
129{
130public:
141 explicit BinaryXOutputStream(
142 const css::uno::Reference< css::io::XOutputStream >& rxOutStrm,
143 bool bAutoClose );
144
145 virtual ~BinaryXOutputStream() override;
146
149 void close() override;
150
152 virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ) override;
153
155 virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
156
157private:
159 css::uno::Reference< css::io::XOutputStream >
162};
163
164
172{
173public:
182
184 virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ) override;
185
187 virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
188
190 virtual sal_Int64 size() const override;
192 virtual sal_Int64 tell() const override;
194 virtual void seek( sal_Int64 nPos ) override;
196 virtual void close() override;
197
198private:
200 sal_Int32 mnPos;
201};
202
203
204} // namespace oox
205
206#endif
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface for binary output stream classes.
void writeCharArrayUC(std::u16string_view rString, rtl_TextEncoding eTextEnc)
BinaryOutputStream & operator=(BinaryOutputStream const &)=delete
BinaryOutputStream(BinaryOutputStream const &)=delete
BinaryOutputStream()
This dummy default c'tor will never call the c'tor of the virtual base class BinaryStreamBase as this...
BinaryOutputStream & WriteUInt32(sal_uInt32 x)
virtual void writeMemory(const void *pMem, sal_Int32 nBytes, size_t nAtomSize=1)=0
Derived classes implement writing the contents of the (preallocated!) memory buffer pMem.
BinaryOutputStream & WriteInt32(sal_Int32 x)
BinaryOutputStream & WriteInt16(sal_Int16 x)
BinaryOutputStream & WriteUInt16(sal_uInt16 x)
void writeCompressedUnicodeArray(const OUString &rString, bool bCompressed)
BinaryOutputStream & WriteInt64(sal_Int64 x)
virtual void writeData(const StreamDataSequence &rData, size_t nAtomSize=1)=0
Derived classes implement writing the contents of the passed data sequence.
void writeArray(Type *opnArray, sal_Int32 nElemCount)
void writeUnicodeArray(const OUString &rString)
void writeValue(Type nValue)
Writes a value to the stream and converts it to platform byte order.
Base class for binary stream classes.
Wraps a UNO output stream and provides convenient access functions.
StreamDataSequence maBuffer
Data buffer used in writeMemory() function.
css::uno::Reference< css::io::XOutputStream > mxOutStrm
Reference to the output stream.
bool mbAutoClose
True = automatically close stream on destruction.
Base class for binary input and output streams wrapping a UNO stream, seekable via the com....
static void convertLittleEndianArray(Type *, size_t)
Definition: helper.hxx:217
static void convertLittleEndian(Type &)
Definition: helper.hxx:214
Wraps a StreamDataSequence and provides convenient access functions.
virtual sal_Int64 tell() const override
Returns the current stream position.
StreamDataSequence * mpData
Wrapped data sequence.
virtual void close() override
Releases the reference to the data sequence.
SequenceOutputStream(StreamDataSequence &rData)
Constructs the wrapper object for the passed data sequence.
virtual sal_Int64 size() const override
Returns the size of the wrapped data sequence.
virtual void seek(sal_Int64 nPos) override
Seeks the stream to the passed position.
sal_Int32 mnPos
Current position in the sequence.
virtual void writeData(const StreamDataSequence &rData, size_t nAtomSize=1) override
Writes the passed data sequence.
virtual void writeMemory(const void *pMem, sal_Int32 nBytes, size_t nAtomSize=1) override
Write nBytes bytes from the (preallocated!) buffer pMem.
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
bool close
float x
sal_Int16 nValue
sal_uInt16 nPos
const ContentProperties & rData
Type
css::uno::Sequence< sal_Int8 > StreamDataSequence
#define SAL_MAX_INT32