LibreOffice Module oox (master) 1
axbinarywriter.cxx
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 */
10
11namespace oox::ole {
12
13namespace {
14
15const sal_uInt32 AX_STRING_COMPRESSED = 0x80000000;
16
17} // namespace
18
20 BinaryStreamBase( false ),
21 mpOutStrm( &rOutStrm ),
22 mnStrmPos( 0 ),
23 mnStrmSize( rOutStrm.getRemaining() ),
24 mnWrappedBeginPos( rOutStrm.tell() )
25{
26 mbEof = mbEof || rOutStrm.isEof();
27}
28
30{
31 return mpOutStrm ? mnStrmSize : -1;
32}
33
35{
36 return mpOutStrm ? mnStrmPos : -1;
37}
38
39void AxAlignedOutputStream::seek( sal_Int64 nPos )
40{
41 mbEof = (nPos < 0);
42 if( !mbEof )
43 {
44 mpOutStrm->seek( static_cast< sal_Int32 >( mnWrappedBeginPos + nPos ) );
46 }
47}
48
50{
51 mpOutStrm = nullptr;
52 mbEof = true;
53}
54
55void AxAlignedOutputStream::writeData( const StreamDataSequence& orData, size_t nAtomSize )
56{
57 mpOutStrm->writeData( orData, nAtomSize );
59}
60
61void AxAlignedOutputStream::writeMemory( const void* opMem, sal_Int32 nBytes, size_t nAtomSize )
62{
63 mpOutStrm->writeMemory( opMem, nBytes, nAtomSize );
65}
66
67void AxAlignedOutputStream::pad( sal_Int32 nBytes )
68{
69 //PRESUMABLY we need to pad with 0's here as appropriate
70 css::uno::Sequence< sal_Int8 > aData( nBytes );
71 // ok we could be padding with rubbish here, but really that shouldn't matter
72 // set to 0(s), easier to not get fooled by 0's when looking at
73 // binary content...
74 memset( static_cast<void*>( aData.getArray() ), 0, nBytes );
77}
78
79void AxAlignedOutputStream::align( size_t nSize )
80{
81 pad( static_cast< sal_Int32 >( (nSize - (mnStrmPos % nSize)) % nSize ) );
82}
83
84namespace {
85
86void lclWriteString( AxAlignedOutputStream& rOutStrm, OUString const & rValue, sal_uInt32 nSize )
87{
88 bool bCompressed = getFlag( nSize, AX_STRING_COMPRESSED );
89 rOutStrm.writeCompressedUnicodeArray( rValue, bCompressed );
90}
91
92} // namespace
93
95{
96}
97
99{
100 rOutStrm.WriteInt32(mrPairData.first).WriteInt32(mrPairData.second);
101 return true;
102}
103
105{
106 lclWriteString( rOutStrm, mrValue, mnSize );
107 return true;
108}
109
111 maOutStrm( rOutStrm ),
112 mnPropFlags( 0x0 ),
113 mbValid( true ),
114 mb64BitPropFlags( b64BitPropFlags )
115{
116 sal_uInt16 nId( 0x0200 );
118 mnBlockSize = 0; // will be filled in the finalize method
119
122
123 if( mb64BitPropFlags )
125 else
127 mnNextProp = 1;
128}
129
131{
132 // orbValue == bReverse false then we want to set the bit, e.g. don't skip
133 startNextProperty( !orbValue );
134}
135
137{
139 maLargeProps.push_back( ComplexPropVector::value_type( std::make_shared<PairProperty>( orPairData ) ) );
140}
141
143{
144 sal_uInt32 nSize = orValue.getLength() * 2;
145 setFlag( nSize, AX_STRING_COMPRESSED, false );
146 maOutStrm.writeAligned< sal_uInt32 >( nSize );
147 maLargeProps.push_back( ComplexPropVector::value_type( std::make_shared<StringProperty>( orValue, nSize ) ) );
149}
150
152{
153 // write large properties
154 maOutStrm.align( 4 );
155 for (auto const& largeProp : maLargeProps)
156 {
157 if (!ensureValid())
158 break;
159 largeProp->writeProperty( maOutStrm );
160 maOutStrm.align( 4 );
161 }
162
164
165 // write stream properties (no stream alignment between properties!)
166 for (auto const& streamProp : maStreamProps)
167 {
168 if (!ensureValid())
169 break;
170 streamProp->writeProperty( maOutStrm );
171 }
172
173 sal_Int64 nPos = maOutStrm.tell();
175
177
178 if( mb64BitPropFlags )
180 else
182
184}
185
187{
189 return mbValid;
190}
191
193{
194 // if we are skipping then we clear the flag
195 setFlag( mnPropFlags, mnNextProp, !bSkip );
196 mnNextProp <<= 1;
197}
198
199} // namespace oox::ole
200
201/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface for binary output stream classes.
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.
Base class for binary stream classes.
bool isEof() const
Returns true, if the stream position is invalid (EOF).
virtual sal_Int64 tell() const =0
Implementations return the current stream position, if possible.
virtual void seek(sal_Int64 nPos)=0
Implementations seek the stream to the passed position, if the stream is seekable.
bool mbEof
End of stream flag.
container_type::value_type value_type
Definition: refvector.hxx:46
A wrapper for a binary output stream that supports aligned write operations.
void align(size_t nSize)
Aligns the stream to a multiple of the passed size (relative to the position of the wrapped stream at...
void pad(sal_Int32 nBytes)
virtual void writeMemory(const void *pMem, sal_Int32 nBytes, size_t nAtomSize=1) override
Reads nBytes bytes to the (existing) buffer opMem.
BinaryOutputStream * mpOutStrm
The wrapped input stream.
virtual void close() override
Closes the input stream but not the wrapped stream.
sal_Int64 mnStrmPos
Tracks relative position in the stream.
virtual sal_Int64 tell() const override
Return the current relative stream position (relative to position of the wrapped stream at constructi...
void writeAligned(Type nVal)
Aligns the stream according to the passed type and reads a value.
virtual void writeData(const StreamDataSequence &orData, size_t nAtomSize=1) override
Reads nBytes bytes to the passed sequence.
AxAlignedOutputStream(BinaryOutputStream &rOutStrm)
sal_Int64 mnStrmSize
Size of the wrapped stream data.
sal_Int64 mnWrappedBeginPos
starting pos or wrapped stream
virtual sal_Int64 size() const override
Returns the size of the data this stream represents, if the wrapped stream supports the size() operat...
virtual void seek(sal_Int64 nPos) override
Seeks the stream to the passed relative position, if it is behind the current position.
ComplexPropVector maStreamProps
Stores info for all used stream data properties.
void finalizeExport()
Final processing, write contents of all complex properties, writes record size.
void writeBoolProperty(bool orbValue)
Write a boolean property value to the stream, the respective flag in the property mask is set.
sal_Int64 mnPropFlagsStart
pos of Prop flags
ComplexPropVector maLargeProps
Stores info for all used large properties.
void writePairProperty(AxPairData &orPairData)
Write a pair property the stream, the respective flag in the property mask is set.
bool mbValid
True = stream still valid.
AxBinaryPropertyWriter(BinaryOutputStream &rOutStrm, bool b64BitPropFlags=false)
AxAlignedOutputStream maOutStrm
The input stream to read from.
sal_Int64 mnPropFlags
Flags specifying existing properties.
void startNextProperty(bool bSkip=false)
void writeStringProperty(OUString &orValue)
Write a string property to the stream, the respective flag in the property mask is set.
sal_Int64 mnNextProp
Next property to read.
sal_uInt32 mnSize
Definition: dffdumper.cxx:164
sal_uInt16 nPos
::std::pair< sal_Int32, sal_Int32 > AxPairData
A pair of integer values as a property.
void setFlag(Type &ornBitField, Type nMask, bool bSet=true)
Sets or clears (according to bSet) all set bits of nMask in ornBitField.
Definition: helper.hxx:167
css::uno::Sequence< sal_Int8 > StreamDataSequence
bool getFlag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
Definition: helper.hxx:137
sal_Int16 nId
Definition: olehelper.cxx:98
GUIDCNamePair aData
Definition: olehelper.cxx:99
virtual bool writeProperty(AxAlignedOutputStream &rOutStrm) override
virtual bool writeProperty(AxAlignedOutputStream &rOutStrm) override