diff options
Diffstat (limited to 'oox/inc/oox/helper/binarystreambase.hxx')
-rw-r--r-- | oox/inc/oox/helper/binarystreambase.hxx | 130 |
1 files changed, 88 insertions, 42 deletions
diff --git a/oox/inc/oox/helper/binarystreambase.hxx b/oox/inc/oox/helper/binarystreambase.hxx index ba0f34b21f40..0088b29208b0 100644 --- a/oox/inc/oox/helper/binarystreambase.hxx +++ b/oox/inc/oox/helper/binarystreambase.hxx @@ -29,75 +29,123 @@ #define OOX_HELPER_BINARYSTREAMBASE_HXX #include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/io/XSeekable.hpp> +#include <boost/shared_ptr.hpp> #include "oox/helper/helper.hxx" +namespace com { namespace sun { namespace star { + namespace io { class XSeekable; } +} } } + namespace oox { typedef ::com::sun::star::uno::Sequence< sal_Int8 > StreamDataSequence; // ============================================================================ -/** Base interface for binary stream classes. Implemenetations may or may not - support seeking the stream. */ +/** Base class for binary stream classes. + */ class BinaryStreamBase { public: virtual ~BinaryStreamBase(); - /** Derived classes return whether the stream is seekable. Default: false. */ - virtual bool isSeekable() const; - /** Derived classes return the size of the stream, if possible, - otherwise/default: -1. May return something for unseekable streams. */ - virtual sal_Int64 getLength() const; - /** Derived classes return the current stream position, if possible, - otherwise/default: -1. May return something for unseekable streams. */ - virtual sal_Int64 tell() const; - /** Derived classes implement seeking the stream to the passed position, if - the stream is seekable. */ - virtual void seek( sal_Int64 nPos ); + /** Implementations return the size of the stream, if possible. + + This function may be implemented for some types of unseekable streams, + and MUST be implemented for all seekable streams. + + @return + The size of the stream in bytes, or -1, if not implemented. + */ + virtual sal_Int64 size() const = 0; + + /** Implementations return the current stream position, if possible. + + This function may be implemented for some types of unseekable streams, + and MUST be implemented for all seekable streams. + + @return + The current position in the stream, or -1, if not implemented. + */ + virtual sal_Int64 tell() const = 0; + + /** Implementations seek the stream to the passed position, if + the stream is seekable. + */ + virtual void seek( sal_Int64 nPos ) = 0; + + /** Implementations close the stream. + */ + virtual void close() = 0; + + /** Returns true, if the implementation supports the seek() operation. + + Implementations may still implement size() and tell() even if the + stream is not seekable. + */ + inline bool isSeekable() const { return mbSeekable; } /** Returns true, if the stream position is invalid (EOF). This flag turns - true *after* the first attempt to seek/read beyond the stream end. */ + true *after* the first attempt to seek/read beyond the stream end. + */ inline bool isEof() const { return mbEof; } - /** Returns the size of the remaining data, if stream is seekable, otherwise -1. */ + /** Returns the size of the remaining data available in the stream, if + stream supports size() and tell(), otherwise -1. + */ sal_Int64 getRemaining() const; - /** Seeks the stream to the beginning, if stream is seekable. */ + + /** Seeks the stream to the beginning, if stream is seekable. + */ inline void seekToStart() { seek( 0 ); } - /** Seeks the stream to the end, if stream is seekable. */ - inline void seekToEnd() { seek( getLength() ); } + + /** Seeks the stream to the end, if stream is seekable. + */ + inline void seekToEnd() { seek( size() ); } + /** Seeks the stream forward to a position that is a multiple of the passed - block size, relative to the passed stream position, if stream is seekable. */ + block size, if stream is seekable. + + @param nBlockSize + The size of the data blocks the streams needs to be aligned to. + + @param nAnchorPos + Position in the stream the data blocks are aligned to. + */ void alignToBlock( sal_Int32 nBlockSize, sal_Int64 nAnchorPos = 0 ); protected: - inline explicit BinaryStreamBase() : mbEof( false ) {} + inline explicit BinaryStreamBase( bool bSeekable ) : mbEof( false ), mbSeekable( bSeekable ) {} private: BinaryStreamBase( const BinaryStreamBase& ); BinaryStreamBase& operator=( const BinaryStreamBase& ); protected: - bool mbEof; + bool mbEof; /// End of stream flag. + +private: + const bool mbSeekable; /// True = implementation supports seeking. }; // ============================================================================ -/** Base class for binary input and output streams wrapping an API stream, +/** Base class for binary input and output streams wrapping a UNO stream, seekable via the com.sun.star.io.XSeekable interface. */ class BinaryXSeekableStream : public virtual BinaryStreamBase { public: - /** Returns true, if the wrapped stream is seekable. */ - virtual bool isSeekable() const; - /** Returns the size of the stream, if stream is seekable, otherwise -1. */ - virtual sal_Int64 getLength() const; - /** Returns the current stream position, if stream is seekable, otherwise -1. */ + virtual ~BinaryXSeekableStream(); + + /** Returns the size of the stream, if wrapped stream is seekable, otherwise -1. */ + virtual sal_Int64 size() const; + /** Returns the current stream position, if wrapped stream is seekable, otherwise -1. */ virtual sal_Int64 tell() const; - /** Seeks the stream to the passed position, if stream is seekable. */ + /** Seeks the stream to the passed position, if wrapped stream is seekable. */ virtual void seek( sal_Int64 nPos ); + /** Releases the reference to the UNO XSeekable interface. */ + virtual void close(); protected: explicit BinaryXSeekableStream( @@ -111,31 +159,29 @@ private: // ============================================================================ /** Base class for binary input and output streams wrapping a - StreamDataSequence, which is always seekable. */ + StreamDataSequence, which is always seekable. + + The wrapped data sequence MUST live at least as long as this stream + wrapper. The data sequence MUST NOT be changed from outside as long as this + stream wrapper is used to modify it. + */ class SequenceSeekableStream : public virtual BinaryStreamBase { public: - /** Returns true (data sequence streams are always seekable). */ - virtual bool isSeekable() const; /** Returns the size of the wrapped data sequence. */ - virtual sal_Int64 getLength() const; + virtual sal_Int64 size() const; /** Returns the current stream position. */ virtual sal_Int64 tell() const; /** Seeks the stream to the passed position. */ virtual void seek( sal_Int64 nPos ); + /** Releases the reference to the data sequence. */ + virtual void close(); protected: - /** Constructs the wrapper object for the passed data sequence. - - @attention - The passed data sequence MUST live at least as long as this stream - wrapper. The data sequence MUST NOT be changed from outside as long - as this stream wrapper is used to modify it. - */ - inline explicit SequenceSeekableStream( const StreamDataSequence& rData ) : mrData( rData ), mnPos( 0 ) {} + explicit SequenceSeekableStream( const StreamDataSequence& rData ); protected: - const StreamDataSequence& mrData; /// Wrapped data sequence. + const StreamDataSequence* mpData; /// Wrapped data sequence. sal_Int32 mnPos; /// Current position in the sequence. }; |