LibreOffice Module oox (master) 1
axbinaryreader.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_OLE_AXBINARYREADER_HXX
21#define INCLUDED_OOX_OLE_AXBINARYREADER_HXX
22
23#include <cstddef>
24#include <utility>
25#include <vector>
26
30#include <rtl/ustring.hxx>
31#include <sal/types.h>
32
33namespace oox::ole { struct AxFontData; }
34
35namespace oox::ole {
36
37
47{
48public:
49 explicit AxAlignedInputStream( BinaryInputStream& rInStrm );
50
53 virtual sal_Int64 size() const override;
56 virtual sal_Int64 tell() const override;
59 virtual void seek( sal_Int64 nPos ) override;
61 virtual void close() override;
62
65 virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
68 virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
70 virtual void skip( sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
71
74 void align( size_t nSize );
75
77 template< typename Type >
78 [[nodiscard]]
79 Type readAligned() { align( sizeof( Type ) ); return readValue< Type >(); }
81 template< typename Type >
82 void skipAligned() { align( sizeof( Type ) ); skip( sizeof( Type ) ); }
83
84private:
86 sal_Int64 mnStrmPos;
87 sal_Int64 mnStrmSize;
88};
89
90
92typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
93
95typedef ::std::vector< OUString > AxArrayString;
96
97
101{
102public:
103 explicit AxBinaryPropertyReader( BinaryInputStream& rInStrm, bool b64BitPropFlags = false );
104
107 template< typename StreamType, typename DataType >
108 void readIntProperty( DataType& ornValue )
109 { if( startNextProperty() ) ornValue = maInStrm.readAligned< StreamType >(); }
112 void readBoolProperty( bool& orbValue, bool bReverse = false );
115 void readPairProperty( AxPairData& orPairData );
118 void readStringProperty( OUString& orValue );
121 void readArrayStringProperty( std::vector< OUString >& rStrings );
124 void readGuidProperty( OUString& orGuid );
127 void readFontProperty( AxFontData& orFontData );
130 void readPictureProperty( StreamDataSequence& orPicData );
131
134 template< typename StreamType >
135 void skipIntProperty() { if( startNextProperty() ) maInStrm.skipAligned< StreamType >(); }
154
156 bool finalizeImport();
157
158private:
159 bool ensureValid( bool bCondition = true );
160 bool startNextProperty();
161
162private:
165 {
166 virtual ~ComplexProperty();
167 virtual bool readProperty( AxAlignedInputStream& rInStrm ) = 0;
168 };
169
171 struct PairProperty final : public ComplexProperty
172 {
174
175 explicit PairProperty( AxPairData& rPairData ) :
176 mrPairData( rPairData ) {}
177 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
178 };
179
181 struct StringProperty final : public ComplexProperty
182 {
183 OUString& mrValue;
184 sal_uInt32 mnSize;
185
186 explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
187 mrValue( rValue ), mnSize( nSize ) {}
188 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
189 };
190
193 {
195 sal_uInt32 mnSize;
196 explicit ArrayStringProperty( AxArrayString& rArray, sal_uInt32 nSize ) :
197 mrArray( rArray ), mnSize( nSize ) {}
198 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
199 };
200
202 struct GuidProperty final : public ComplexProperty
203 {
204 OUString& mrGuid;
205
206 explicit GuidProperty( OUString& rGuid ) :
207 mrGuid( rGuid ) {}
208 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
209 };
210
212 struct FontProperty final : public ComplexProperty
213 {
215
216 explicit FontProperty( AxFontData& rFontData ) :
217 mrFontData( rFontData ) {}
218 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
219 };
220
222 struct PictureProperty final : public ComplexProperty
223 {
225
226 explicit PictureProperty( StreamDataSequence& rPicData ) :
227 mrPicData( rPicData ) {}
228 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
229 };
230
232
233private:
238 OUString maDummyString;
240 sal_Int64 mnPropFlags;
241 sal_Int64 mnNextProp;
242 sal_Int64 mnPropsEnd;
243 bool mbValid;
244};
245
246
247} // namespace oox::ole
248
249#endif
250
251/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface for binary input stream classes.
A wrapper for a binary input stream that supports aligned read operations.
virtual sal_Int32 readMemory(void *opMem, sal_Int32 nBytes, size_t nAtomSize=1) override
Reads nBytes bytes to the (existing) buffer opMem.
virtual sal_Int64 tell() const override
Return the current relative stream position (relative to position of the wrapped stream at constructi...
void align(size_t nSize)
Aligns the stream to a multiple of the passed size (relative to the position of the wrapped stream at...
Type readAligned()
Aligns the stream according to the passed type and reads a value.
sal_Int64 mnStrmSize
Size of the wrapped stream data.
sal_Int64 mnStrmPos
Tracks relative position in the stream.
virtual void skip(sal_Int32 nBytes, size_t nAtomSize=1) override
Seeks the stream forward by the passed number of bytes.
virtual void close() override
Closes the input stream but not the wrapped stream.
AxAlignedInputStream(BinaryInputStream &rInStrm)
virtual void seek(sal_Int64 nPos) override
Seeks the stream to the passed relative position, if it is behind the current position.
virtual sal_Int64 size() const override
Returns the size of the data this stream represents, if the wrapped stream supports the size() operat...
virtual sal_Int32 readData(StreamDataSequence &orData, sal_Int32 nBytes, size_t nAtomSize=1) override
Reads nBytes bytes to the passed sequence.
BinaryInputStream * mpInStrm
The wrapped input stream.
void skipAligned()
Aligns the stream according to the passed type and skips the size of the type.
Import helper to read simple and complex ActiveX form control properties from a binary input stream.
ComplexPropVector maLargeProps
Stores info for all used large properties.
void skipGuidProperty()
Skips the next GUID property in the stream, if the respective flag in the property mask is set.
void readIntProperty(DataType &ornValue)
Reads the next integer property value from the stream, if the respective flag in the property mask is...
bool finalizeImport()
Final processing, reads contents of all complex properties.
void skipIntProperty()
Skips the next integer property value in the stream, if the respective flag in the property mask is s...
OUString maDummyString
Dummy string for unsupported properties.
AxBinaryPropertyReader(BinaryInputStream &rInStrm, bool b64BitPropFlags=false)
bool ensureValid(bool bCondition=true)
void skipArrayStringProperty()
Skips the next ArrayString property in the stream, if the respective flag in the property mask is set...
void readGuidProperty(OUString &orGuid)
Reads the next GUID property from the stream, if the respective flag in the property mask is set.
void readFontProperty(AxFontData &orFontData)
Reads the next font property from the stream, if the respective flag in the property mask is set.
void readStringProperty(OUString &orValue)
Reads the next string property from the stream, if the respective flag in the property mask is set.
void skipBoolProperty()
Skips the next boolean property value in the stream, if the respective flag in the property mask is s...
void readPairProperty(AxPairData &orPairData)
Reads the next pair property from the stream, if the respective flag in the property mask is set.
void skipPictureProperty()
Skips the next picture property in the stream, if the respective flag in the property mask is set.
void skipUndefinedProperty()
Has to be called for undefined properties.
RefVector< ComplexProperty > ComplexPropVector
StreamDataSequence maDummyPicData
Dummy picture for unsupported properties.
AxArrayString maDummyArrayString
Dummy strings for unsupported ArrayString properties.
sal_Int64 mnPropsEnd
End position of simple/large properties.
sal_Int64 mnPropFlags
Flags specifying existing properties.
void skipStringProperty()
Skips the next string property in the stream, if the respective flag in the property mask is set.
bool mbValid
True = stream still valid.
void readArrayStringProperty(std::vector< OUString > &rStrings)
Reads ArrayString, an array of fmString ( compressed or uncompressed ) is read from the stream and in...
ComplexPropVector maStreamProps
Stores info for all used stream data properties.
void readBoolProperty(bool &orbValue, bool bReverse=false)
Reads the next boolean property value from the stream, if the respective flag in the property mask is...
AxAlignedInputStream maInStrm
The input stream to read from.
void readPictureProperty(StreamDataSequence &orPicData)
Reads the next picture property from the stream, if the respective flag in the property mask is set.
sal_Int64 mnNextProp
Next property to read.
sal_uInt16 nPos
Type
DataType
Specifiers for atomic data types.
Definition: dumperbase.hxx:155
::std::pair< sal_Int32, sal_Int32 > AxPairData
A pair of integer values as a property.
::std::vector< OUString > AxArrayString
An array of string values as a property.
css::uno::Sequence< sal_Int8 > StreamDataSequence
Complex property for an array of strings.
ArrayStringProperty(AxArrayString &rArray, sal_uInt32 nSize)
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
Base class for complex properties such as string, point, size, GUID, picture.
virtual bool readProperty(AxAlignedInputStream &rInStrm)=0
Stream property for a font structure.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
Complex property for a GUID value.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
Complex property for a 32-bit value pair, e.g.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
Stream property for a picture or mouse icon.
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
Complex property for a string value.
StringProperty(OUString &rValue, sal_uInt32 nSize)
virtual bool readProperty(AxAlignedInputStream &rInStrm) override
All entries of a font property.
Definition: axfontdata.hxx:54