LCOV - code coverage report
Current view: top level - include/oox/ole - axbinarywriter.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 13 100.0 %
Date: 2015-06-13 12:38:46 Functions: 18 23 78.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <utility>
      14             : #include <oox/helper/binaryoutputstream.hxx>
      15             : #include <oox/helper/refvector.hxx>
      16             : 
      17             : namespace oox {
      18             : namespace ole {
      19             : 
      20             : 
      21             : /** A wrapper for a binary output stream that supports aligned write operations.
      22             : 
      23             :     The implementation does support seeking back the wrapped stream. All
      24             :     seeking operations (tell, seekTo, align) are performed relative to the
      25             :     position of the wrapped stream at construction time of this wrapper.
      26             :     Unlike it's reader class counterpart it is NOT possible to construct this
      27             :     wrapper with an unseekable output stream.
      28             :  */
      29           2 : class AxAlignedOutputStream : public BinaryOutputStream
      30             : {
      31             : public:
      32             :     explicit            AxAlignedOutputStream( BinaryOutputStream& rOutStrm );
      33             : 
      34             :     /** Returns the size of the data this stream represents, if the wrapped
      35             :         stream supports the size() operation. */
      36             :     virtual sal_Int64   size() const SAL_OVERRIDE;
      37             :     /** Return the current relative stream position (relative to position of
      38             :         the wrapped stream at construction time). */
      39             :     virtual sal_Int64   tell() const SAL_OVERRIDE;
      40             :     /** Seeks the stream to the passed relative position, if it is behind the
      41             :         current position. */
      42             :     virtual void        seek( sal_Int64 nPos ) SAL_OVERRIDE;
      43             :     /** Closes the input stream but not the wrapped stream. */
      44             :     virtual void        close() SAL_OVERRIDE;
      45             : 
      46             :     /** Reads nBytes bytes to the passed sequence.
      47             :         @return  Number of bytes really read. */
      48             :     virtual void writeData( const StreamDataSequence& orData, size_t nAtomSize = 1 ) SAL_OVERRIDE;
      49             :     /** Reads nBytes bytes to the (existing) buffer opMem.
      50             :         @return  Number of bytes really read. */
      51             :     virtual void   writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) SAL_OVERRIDE;
      52             : 
      53             :     /** Aligns the stream to a multiple of the passed size (relative to the
      54             :         position of the wrapped stream at construction time). */
      55             :     void                align( size_t nSize );
      56             : 
      57             :     void         pad( sal_Int32 nBytes, size_t nAtomSize = 1);
      58             : 
      59             :     /** Aligns the stream according to the passed type and reads a value. */
      60             :     template< typename Type >
      61          12 :     void         writeAligned( Type nVal ) { align( sizeof( Type ) ); writeValue( nVal ); }
      62             :     /** Aligns the stream according to the passed type and skips the size of the type. */
      63             :     template< typename Type >
      64             :     void         padAligned() { align( sizeof( Type ) ); pad( sizeof( Type ) ); }
      65             : 
      66             : private:
      67             :     BinaryOutputStream*  mpOutStrm;           ///< The wrapped input stream.
      68             :     sal_Int64           mnStrmPos;          ///< Tracks relative position in the stream.
      69             :     sal_Int64           mnStrmSize;         ///< Size of the wrapped stream data.
      70             :     sal_Int64           mnWrappedBeginPos;     ///< starting pos or wrapped stream
      71             : };
      72             : 
      73             : /** A pair of integer values as a property. */
      74             : typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
      75             : 
      76             : /** An array of string values as a property. */
      77             : typedef ::std::vector< OUString > AxStringArray;
      78             : 
      79             : 
      80             : 
      81             : /** Export helper to write simple and complex ActiveX form control properties
      82             :     to a binary input stream. */
      83           2 : class AxBinaryPropertyWriter
      84             : {
      85             : public:
      86             :     explicit            AxBinaryPropertyWriter( BinaryOutputStream& rOutStrm, bool b64BitPropFlags = false );
      87             : 
      88             :     /** Write an integer property value to the stream, the
      89             :         respective flag in the property mask is set. */
      90             :     template< typename StreamType, typename DataType >
      91          10 :     void                writeIntProperty( DataType& ornValue )
      92          10 :                             { if( startNextProperty() ) maOutStrm.writeAligned< StreamType >( ornValue ); }
      93             :     /** Write a boolean property value to the stream, the
      94             :         respective flag in the property mask is set. */
      95             :     void                writeBoolProperty( bool orbValue, bool bReverse = false );
      96             :     /** Write a pair property the stream, the respective flag in
      97             :         the property mask is set. */
      98             :     void                writePairProperty( AxPairData& orPairData );
      99             :     /** Write a string property to the stream, the respective flag
     100             :         in the property mask is set. */
     101             :     void                writeStringProperty( OUString& orValue, bool bCompressed = true );
     102             : 
     103             :     /** Skips the next property clears the respective
     104             :         flag in the property mask. */
     105          27 :     void                skipProperty() { startNextProperty( true ); }
     106             : 
     107             :     /** Final processing, write contents of all complex properties, writes record size */
     108             :     bool                finalizeExport();
     109             : 
     110             : private:
     111             :     bool                ensureValid( bool bCondition = true );
     112             :     bool                startNextProperty( bool bSkip = false );
     113             : 
     114             : private:
     115             :     /** Base class for complex properties such as string, point, size, GUID, picture. */
     116           3 :     struct ComplexProperty
     117             :     {
     118             :         virtual             ~ComplexProperty();
     119             :         virtual bool        writeProperty( AxAlignedOutputStream& rOutStrm ) = 0;
     120             :     };
     121             : 
     122             :     /** Complex property for a 32-bit value pair, e.g. point or size. */
     123           2 :     struct PairProperty : public ComplexProperty
     124             :     {
     125             :         AxPairData&         mrPairData;
     126             : 
     127           1 :         explicit            PairProperty( AxPairData& rPairData ) :
     128           1 :                                 mrPairData( rPairData ) {}
     129             :         virtual bool        writeProperty( AxAlignedOutputStream& rOutStrm ) SAL_OVERRIDE;
     130             :     };
     131             : 
     132             :     /** Complex property for a string value. */
     133           4 :     struct StringProperty : public ComplexProperty
     134             :     {
     135             :         OUString&    mrValue;
     136             :         sal_uInt32          mnSize;
     137             : 
     138           2 :         explicit            StringProperty( OUString& rValue, sal_uInt32 nSize ) :
     139           2 :                                 mrValue( rValue ), mnSize( nSize ) {}
     140             :         virtual bool        writeProperty( AxAlignedOutputStream& rOutStrm ) SAL_OVERRIDE;
     141             :     };
     142             : 
     143             :     /** Stream property for a picture or mouse icon. */
     144             :     struct PictureProperty : public ComplexProperty
     145             :     {
     146             :         StreamDataSequence& mrPicData;
     147             : 
     148             :         explicit            PictureProperty( StreamDataSequence& rPicData ) :
     149             :                                 mrPicData( rPicData ) {}
     150             :         virtual bool        writeProperty( AxAlignedOutputStream& rOutStrm ) SAL_OVERRIDE;
     151             :     };
     152             : 
     153             :     typedef RefVector< ComplexProperty > ComplexPropVector;
     154             : 
     155             : private:
     156             :     AxAlignedOutputStream maOutStrm;        ///< The input stream to read from.
     157             :     ComplexPropVector   maLargeProps;       ///< Stores info for all used large properties.
     158             :     ComplexPropVector   maStreamProps;      ///< Stores info for all used stream data properties.
     159             :     AxPairData          maDummyPairData;    ///< Dummy pair for unsupported properties.
     160             :     StreamDataSequence  maDummyPicData;     ///< Dummy picture for unsupported properties.
     161             :     OUString     maDummyString;      ///< Dummy string for unsupported properties.
     162             :     AxStringArray       maDummyStringArray; ///< Dummy string array for unsupported properties.
     163             :     sal_Int16           mnBlockSize;
     164             :     sal_Int64           mnPropFlagsStart;     ///< pos of Prop flags
     165             :     sal_Int64           mnPropFlags;        ///< Flags specifying existing properties.
     166             :     sal_Int64           mnNextProp;         ///< Next property to read.
     167             :     bool                mbValid;            ///< True = stream still valid.
     168             :     bool                mb64BitPropFlags;
     169             : };
     170             : 
     171             : 
     172             : } // namespace ole
     173             : } // namespace oox
     174             : 
     175             : #endif
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11