tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / include / oox / ole / axbinarywriter.hxx
blobd19e2ae3b3c3515aa99ee04bd8eca4fb28a38453
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 #ifndef INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
11 #define INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
13 #include <cstddef>
14 #include <utility>
16 #include <oox/helper/binaryoutputstream.hxx>
17 #include <oox/helper/binarystreambase.hxx>
18 #include <oox/helper/refvector.hxx>
19 #include <rtl/ustring.hxx>
20 #include <sal/types.h>
22 namespace oox::ole {
25 /** A wrapper for a binary output stream that supports aligned write operations.
27 The implementation does support seeking back the wrapped stream. All
28 seeking operations (tell, seekTo, align) are performed relative to the
29 position of the wrapped stream at construction time of this wrapper.
30 Unlike it's reader class counterpart it is NOT possible to construct this
31 wrapper with an unseekable output stream.
33 class AxAlignedOutputStream final : public BinaryOutputStream
35 public:
36 explicit AxAlignedOutputStream( BinaryOutputStream& rOutStrm );
38 /** Returns the size of the data this stream represents, if the wrapped
39 stream supports the size() operation. */
40 virtual sal_Int64 size() const override;
41 /** Return the current relative stream position (relative to position of
42 the wrapped stream at construction time). */
43 virtual sal_Int64 tell() const override;
44 /** Seeks the stream to the passed relative position, if it is behind the
45 current position. */
46 virtual void seek( sal_Int64 nPos ) override;
47 /** Closes the input stream but not the wrapped stream. */
48 virtual void close() override;
50 /** Reads nBytes bytes to the passed sequence.
51 @return Number of bytes really read. */
52 virtual void writeData( const StreamDataSequence& orData, size_t nAtomSize = 1 ) override;
53 /** Reads nBytes bytes to the (existing) buffer opMem.
54 @return Number of bytes really read. */
55 virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
57 /** Aligns the stream to a multiple of the passed size (relative to the
58 position of the wrapped stream at construction time). */
59 void align( size_t nSize );
61 void pad( sal_Int32 nBytes );
63 /** Aligns the stream according to the passed type and reads a value. */
64 template< typename Type >
65 void writeAligned( Type nVal ) { align( sizeof( Type ) ); writeValue( nVal ); }
67 private:
68 BinaryOutputStream* mpOutStrm; ///< The wrapped input stream.
69 sal_Int64 mnStrmPos; ///< Tracks relative position in the stream.
70 sal_Int64 mnStrmSize; ///< Size of the wrapped stream data.
71 sal_Int64 mnWrappedBeginPos; ///< starting pos or wrapped stream
74 /** A pair of integer values as a property. */
75 typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
77 /** Export helper to write simple and complex ActiveX form control properties
78 to a binary input stream. */
79 class AxBinaryPropertyWriter
81 public:
82 explicit AxBinaryPropertyWriter( BinaryOutputStream& rOutStrm, bool b64BitPropFlags = false );
84 /** Write an integer property value to the stream, the
85 respective flag in the property mask is set. */
86 template< typename StreamType, typename DataType >
87 void writeIntProperty( DataType ornValue )
88 { startNextProperty(); maOutStrm.writeAligned< StreamType >( ornValue ); }
89 /** Write a boolean property value to the stream, the
90 respective flag in the property mask is set. */
91 void writeBoolProperty( bool orbValue );
92 /** Write a pair property the stream, the respective flag in
93 the property mask is set. */
94 void writePairProperty( AxPairData& orPairData );
95 /** Write a string property to the stream, the respective flag
96 in the property mask is set. */
97 void writeStringProperty( OUString& orValue );
99 /** Skips the next property clears the respective
100 flag in the property mask. */
101 void skipProperty() { startNextProperty( true ); }
103 /** Final processing, write contents of all complex properties, writes record size */
104 void finalizeExport();
106 private:
107 bool ensureValid();
108 void startNextProperty( bool bSkip = false );
110 private:
111 /** Base class for complex properties such as string, point, size, GUID, picture. */
112 struct ComplexProperty
114 virtual ~ComplexProperty();
115 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) = 0;
118 /** Complex property for a 32-bit value pair, e.g. point or size. */
119 struct PairProperty final : public ComplexProperty
121 private:
122 AxPairData& mrPairData;
124 public:
125 explicit PairProperty( AxPairData& rPairData ) :
126 mrPairData( rPairData ) {}
127 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
130 /** Complex property for a string value. */
131 struct StringProperty final : public ComplexProperty
133 private:
134 OUString& mrValue;
135 sal_uInt32 mnSize;
136 public:
137 explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
138 mrValue( rValue ), mnSize( nSize ) {}
139 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
142 /** Stream property for a picture or mouse icon. */
143 struct PictureProperty final : public ComplexProperty
145 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
148 typedef RefVector< ComplexProperty > ComplexPropVector;
150 private:
151 AxAlignedOutputStream maOutStrm; ///< The input stream to read from.
152 ComplexPropVector maLargeProps; ///< Stores info for all used large properties.
153 ComplexPropVector maStreamProps; ///< Stores info for all used stream data properties.
154 sal_Int16 mnBlockSize;
155 sal_Int64 mnPropFlagsStart; ///< pos of Prop flags
156 sal_Int64 mnPropFlags; ///< Flags specifying existing properties.
157 sal_Int64 mnNextProp; ///< Next property to read.
158 bool mbValid; ///< True = stream still valid.
159 bool mb64BitPropFlags;
163 } // namespace oox::ole
165 #endif
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */