diff options
Diffstat (limited to 'oox/inc/oox/helper/binaryoutputstream.hxx')
-rw-r--r-- | oox/inc/oox/helper/binaryoutputstream.hxx | 86 |
1 files changed, 52 insertions, 34 deletions
diff --git a/oox/inc/oox/helper/binaryoutputstream.hxx b/oox/inc/oox/helper/binaryoutputstream.hxx index e24777c4f296..362c7fbdea87 100644 --- a/oox/inc/oox/helper/binaryoutputstream.hxx +++ b/oox/inc/oox/helper/binaryoutputstream.hxx @@ -28,10 +28,12 @@ #ifndef OOX_HELPER_BINARYOUTPUTSTREAM_HXX #define OOX_HELPER_BINARYOUTPUTSTREAM_HXX -#include <boost/shared_ptr.hpp> -#include <com/sun/star/io/XOutputStream.hpp> #include "oox/helper/binarystreambase.hxx" +namespace com { namespace sun { namespace star { + namespace io { class XOutputStream; } +} } } + namespace oox { // ============================================================================ @@ -43,24 +45,38 @@ namespace oox { class BinaryOutputStream : public virtual BinaryStreamBase { public: - /** Derived classes implement writing the passed data sequence. */ - virtual void writeData( const StreamDataSequence& rData ) = 0; - /** Derived classes implement writing from the (existing) buffer pMem. */ - virtual void writeMemory( const void* pMem, sal_Int32 nBytes ) = 0; + /** Derived classes implement writing the contents of the passed data + sequence. + + @param nAtomSize + The size of the elements in the memory block, if available. Derived + classes may be interested in this information. + */ + virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ) = 0; + + /** Derived classes implement writing the contents of the (preallocated!) + memory buffer pMem. + + @param nAtomSize + The size of the elements in the memory block, if available. Derived + classes may be interested in this information. + */ + virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) = 0; /** Writes a value to the stream and converts it to platform byte order. - Supported types: SAL integers (8 to 64 bit), float, double. */ + All data types supported by the ByteOrderConverter class can be used. + */ template< typename Type > void writeValue( Type nValue ); - /** Stream operator for integral and floating-point types. */ + + /** Stream operator for all data types supported by the writeValue() function. */ template< typename Type > inline BinaryOutputStream& operator<<( Type nValue ) { writeValue( nValue ); return *this; } -private: - /** Used by the writeValue() template function to write built-in types. - @descr Derived classes may overwrite this default implementation which - simply calls writeMemory() with something own. */ - virtual void writeAtom( const void* pMem, sal_uInt8 nSize ); +protected: + /** This dummy default c'tor will never call the c'tor of the virtual base + class BinaryStreamBase as this class cannot be instanciated directly. */ + inline explicit BinaryOutputStream() : BinaryStreamBase( false ) {} }; typedef ::boost::shared_ptr< BinaryOutputStream > BinaryOutputStreamRef; @@ -70,14 +86,13 @@ typedef ::boost::shared_ptr< BinaryOutputStream > BinaryOutputStreamRef; template< typename Type > void BinaryOutputStream::writeValue( Type nValue ) { - // can be instanciated for all types supported in class ByteOrderConverter ByteOrderConverter::convertLittleEndian( nValue ); - writeMemory( &nValue, static_cast< sal_Int32 >( sizeof( Type ) ) ); + writeMemory( &nValue, static_cast< sal_Int32 >( sizeof( Type ) ), sizeof( Type ) ); } // ============================================================================ -/** Wraps a com.sun.star.io.XOutputStream and provides convenient access functions. +/** Wraps a UNO output stream and provides convenient access functions. The binary data in the stream is written in little-endian format. */ @@ -86,10 +101,13 @@ class BinaryXOutputStream : public BinaryXSeekableStream, public BinaryOutputStr public: /** Constructs the wrapper object for the passed output stream. - @param rxOutStream The com.sun.star.io.XOutputStream interface of the - output stream to be wrapped. - @param bAutoClose True = automatically close the wrapped output stream - on destruction of this wrapper. + @param rxOutStream + The com.sun.star.io.XOutputStream interface of the output stream to + be wrapped. + + @param bAutoClose + True = automatically close the wrapped output stream on destruction + of this wrapper or when close() is called. */ explicit BinaryXOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxOutStrm, @@ -97,20 +115,23 @@ public: virtual ~BinaryXOutputStream(); + /** Flushes and closes the output stream. Does also close the wrapped UNO + output stream if bAutoClose has been set to true in the constructor. */ + void close(); + /** Writes the passed data sequence. */ - virtual void writeData( const StreamDataSequence& rData ); - /** Write nBytes bytes from the (existing) buffer pMem. */ - virtual void writeMemory( const void* pMem, sal_Int32 nBytes ); + virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ); + + /** Write nBytes bytes from the (preallocated!) buffer pMem. */ + virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ); - /** Stream operator for integral and floating-point types. */ + /** Stream operator for all data types supported by the writeValue() function. */ template< typename Type > inline BinaryXOutputStream& operator<<( Type nValue ) { writeValue( nValue ); return *this; } /** Returns the XOutputStream interface of the wrapped output stream. */ inline ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getXOutputStream() const { return mxOutStrm; } - /** Flushes and closes the wrapped XOutputStream. */ - void close(); private: StreamDataSequence maBuffer; /// Data buffer used in writeMemory() function. @@ -119,8 +140,6 @@ private: bool mbAutoClose; /// True = automatically close stream on destruction. }; -typedef ::boost::shared_ptr< BinaryXOutputStream > BinaryXOutputStreamRef; - // ============================================================================ /** Wraps a StreamDataSequence and provides convenient access functions. @@ -142,17 +161,16 @@ public: explicit SequenceOutputStream( StreamDataSequence& rData ); /** Writes the passed data sequence. */ - virtual void writeData( const StreamDataSequence& rData ); - /** Write nBytes bytes from the (existing) buffer pMem. */ - virtual void writeMemory( const void* pMem, sal_Int32 nBytes ); + virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ); - /** Stream operator for integral and floating-point types. */ + /** Write nBytes bytes from the (preallocated!) buffer pMem. */ + virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ); + + /** Stream operator for all data types supported by the writeValue() function. */ template< typename Type > inline SequenceOutputStream& operator<<( Type nValue ) { writeValue( nValue ); return *this; } }; -typedef ::boost::shared_ptr< SequenceOutputStream > SequenceOutputStreamRef; - // ============================================================================ } // namespace oox |