LibreOffice Module oox (master)  1
axbinarywriter.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 
10 #ifndef INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
11 #define INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
12 
13 #include <cstddef>
14 #include <utility>
15 
18 #include <oox/helper/refvector.hxx>
19 #include <rtl/ustring.hxx>
20 #include <sal/types.h>
21 
22 namespace oox::ole {
23 
24 
34 {
35 public:
36  explicit AxAlignedOutputStream( BinaryOutputStream& rOutStrm );
37 
40  virtual sal_Int64 size() const override;
43  virtual sal_Int64 tell() const override;
46  virtual void seek( sal_Int64 nPos ) override;
48  virtual void close() override;
49 
52  virtual void writeData( const StreamDataSequence& orData, size_t nAtomSize = 1 ) override;
55  virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
56 
59  void align( size_t nSize );
60 
61  void pad( sal_Int32 nBytes );
62 
64  template< typename Type >
65  void writeAligned( Type nVal ) { align( sizeof( Type ) ); writeValue( nVal ); }
66 
67 private:
69  sal_Int64 mnStrmPos;
70  sal_Int64 mnStrmSize;
71  sal_Int64 mnWrappedBeginPos;
72 };
73 
75 typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
76 
80 {
81 public:
82  explicit AxBinaryPropertyWriter( BinaryOutputStream& rOutStrm, bool b64BitPropFlags = false );
83 
86  template< typename StreamType, typename DataType >
87  void writeIntProperty( DataType ornValue )
88  { startNextProperty(); maOutStrm.writeAligned< StreamType >( ornValue ); }
91  void writeBoolProperty( bool orbValue );
94  void writePairProperty( AxPairData& orPairData );
97  void writeStringProperty( OUString& orValue );
98 
101  void skipProperty() { startNextProperty( true ); }
102 
104  void finalizeExport();
105 
106 private:
107  bool ensureValid();
108  void startNextProperty( bool bSkip = false );
109 
110 private:
113  {
114  virtual ~ComplexProperty();
115  virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) = 0;
116  };
117 
119  struct PairProperty final : public ComplexProperty
120  {
121  AxPairData& mrPairData;
122 
123  explicit PairProperty( AxPairData& rPairData ) :
124  mrPairData( rPairData ) {}
125  virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
126  };
127 
129  struct StringProperty final : public ComplexProperty
130  {
131  OUString& mrValue;
132  sal_uInt32 mnSize;
133 
134  explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
135  mrValue( rValue ), mnSize( nSize ) {}
136  virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
137  };
138 
140  struct PictureProperty final : public ComplexProperty
141  {
142  virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
143  };
144 
146 
147 private:
149  ComplexPropVector maLargeProps;
150  ComplexPropVector maStreamProps;
151  sal_Int16 mnBlockSize;
152  sal_Int64 mnPropFlagsStart;
153  sal_Int64 mnPropFlags;
154  sal_Int64 mnNextProp;
155  bool mbValid;
157 };
158 
159 
160 } // namespace oox::ole
161 
162 #endif
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Export helper to write simple and complex ActiveX form control properties to a binary input stream...
sal_Int64 mnNextProp
Next property to read.
Type
void writeIntProperty(DataType ornValue)
Write an integer property value to the stream, the respective flag in the property mask is set...
bool mbValid
True = stream still valid.
AxAlignedOutputStream maOutStrm
The input stream to read from.
virtual bool writeProperty(AxAlignedOutputStream &rOutStrm)=0
Stream property for a picture or mouse icon.
void writeValue(Type nValue)
Writes a value to the stream and converts it to platform byte order.
virtual void writeData(const StreamDataSequence &orData, size_t nAtomSize=1) override
Reads nBytes bytes to the passed sequence.
virtual bool writeProperty(AxAlignedOutputStream &rOutStrm) override
::std::pair< sal_Int32, sal_Int32 > AxPairData
A pair of integer values as a property.
sal_Int64 mnPropFlags
Flags specifying existing properties.
virtual void writeMemory(const void *pMem, sal_Int32 nBytes, size_t nAtomSize=1) override
Reads nBytes bytes to the (existing) buffer opMem.
Interface for binary output stream classes.
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
void finalizeExport()
Final processing, write contents of all complex properties, writes record size.
void writeAligned(Type nVal)
Aligns the stream according to the passed type and reads a value.
void pad(sal_Int32 nBytes)
Base class for complex properties such as string, point, size, GUID, picture.
Complex property for a string value.
virtual sal_Int64 tell() const override
Return the current relative stream position (relative to position of the wrapped stream at constructi...
A wrapper for a binary output stream that supports aligned write operations.
void writePairProperty(AxPairData &orPairData)
Write a pair property the stream, the respective flag in the property mask is set.
virtual sal_Int64 size() const override
Returns the size of the data this stream represents, if the wrapped stream supports the size() operat...
css::uno::Sequence< sal_Int8 > StreamDataSequence
AxAlignedOutputStream(BinaryOutputStream &rOutStrm)
void skipProperty()
Skips the next property clears the respective flag in the property mask.
sal_Int64 mnStrmSize
Size of the wrapped stream data.
virtual bool writeProperty(AxAlignedOutputStream &rOutStrm) override
sal_Int64 mnWrappedBeginPos
starting pos or wrapped stream
void startNextProperty(bool bSkip=false)
virtual void close() override
Closes the input stream but not the wrapped stream.
void align(size_t nSize)
Aligns the stream to a multiple of the passed size (relative to the position of the wrapped stream at...
RefVector< ComplexProperty > ComplexPropVector
virtual bool writeProperty(AxAlignedOutputStream &rOutStrm) override
void writeStringProperty(OUString &orValue)
Write a string property to the stream, the respective flag in the property mask is set...
SQLSMALLINT DataType
virtual void seek(sal_Int64 nPos) override
Seeks the stream to the passed relative position, if it is behind the current position.
Complex property for a 32-bit value pair, e.g.
ComplexPropVector maLargeProps
Stores info for all used large properties.
BinaryOutputStream * mpOutStrm
The wrapped input stream.
sal_Int64 mnStrmPos
Tracks relative position in the stream.
ComplexPropVector maStreamProps
Stores info for all used stream data properties.
AxBinaryPropertyWriter(BinaryOutputStream &rOutStrm, bool b64BitPropFlags=false)
StringProperty(OUString &rValue, sal_uInt32 nSize)
sal_uInt16 nPos