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 {
173 private:
175 public:
176 explicit PairProperty( AxPairData& rPairData ) :
177 mrPairData( rPairData ) {}
178 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
179 };
180
182 struct StringProperty final : public ComplexProperty
183 {
184 private:
185 OUString& mrValue;
186 sal_uInt32 mnSize;
187 public:
188 explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
189 mrValue( rValue ), mnSize( nSize ) {}
190 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
191 };
192
195 {
196 private:
198 sal_uInt32 mnSize;
199 public:
200 explicit ArrayStringProperty( AxArrayString& rArray, sal_uInt32 nSize ) :
201 mrArray( rArray ), mnSize( nSize ) {}
202 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
203 };
204
206 struct GuidProperty final : public ComplexProperty
207 {
208 private:
209 OUString& mrGuid;
210
211 public:
212 explicit GuidProperty( OUString& rGuid ) :
213 mrGuid( rGuid ) {}
214 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
215 };
216
218 struct FontProperty final : public ComplexProperty
219 {
220 private:
222
223 public:
224 explicit FontProperty( AxFontData& rFontData ) :
225 mrFontData( rFontData ) {}
226 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
227 };
228
230 struct PictureProperty final : public ComplexProperty
231 {
232 private:
234
235 public:
236 explicit PictureProperty( StreamDataSequence& rPicData ) :
237 mrPicData( rPicData ) {}
238 virtual bool readProperty( AxAlignedInputStream& rInStrm ) override;
239 };
240
242
243private:
248 OUString maDummyString;
250 sal_Int64 mnPropFlags;
251 sal_Int64 mnNextProp;
252 sal_Int64 mnPropsEnd;
253 bool mbValid;
254};
255
256
257} // namespace oox::ole
258
259#endif
260
261/* 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