diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-18 15:50:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-19 09:31:43 +0200 |
commit | ba91bc19023f3d7158ef9e394665eb5eb89c4037 (patch) | |
tree | 4fdacef635894c2fe0c5a3e16b04b07353654770 | |
parent | f320d1edeb2c95a21479baaf6ef77344f8df62e4 (diff) |
fix SequenceOutputStream constness
Change-Id: I6e1039c077602b2cb42702cb4131f9503ef533c2
-rw-r--r-- | include/oox/core/filterbase.hxx | 2 | ||||
-rw-r--r-- | include/oox/helper/binaryoutputstream.hxx | 17 | ||||
-rw-r--r-- | oox/source/core/filterbase.cxx | 2 | ||||
-rw-r--r-- | oox/source/helper/binaryoutputstream.cxx | 35 | ||||
-rw-r--r-- | sc/source/filter/inc/worksheetfragment.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/oox/worksheetfragment.cxx | 2 |
6 files changed, 50 insertions, 10 deletions
diff --git a/include/oox/core/filterbase.hxx b/include/oox/core/filterbase.hxx index dcbebc122309..3accd63f2872 100644 --- a/include/oox/core/filterbase.hxx +++ b/include/oox/core/filterbase.hxx @@ -196,7 +196,7 @@ public: /** Imports the raw binary data from the specified stream. @return True, if the data could be imported from the stream. */ - bool importBinaryData( StreamDataSequence const & orDataSeq, const OUString& rStreamName ); + bool importBinaryData( StreamDataSequence & orDataSeq, const OUString& rStreamName ); // com.sun.star.lang.XServiceInfo interface ------------------------------- diff --git a/include/oox/helper/binaryoutputstream.hxx b/include/oox/helper/binaryoutputstream.hxx index 2b954a66f49a..21f563227fd8 100644 --- a/include/oox/helper/binaryoutputstream.hxx +++ b/include/oox/helper/binaryoutputstream.hxx @@ -175,7 +175,7 @@ private: construction, the stream points to the beginning of the passed data sequence. The data sequence is expanded automatically while writing to it. */ -class OOX_DLLPUBLIC SequenceOutputStream : public SequenceSeekableStream, public BinaryOutputStream +class OOX_DLLPUBLIC SequenceOutputStream : public BinaryOutputStream { public: /** Constructs the wrapper object for the passed data sequence. @@ -185,13 +185,26 @@ public: wrapper. The data sequence MUST NOT be changed from outside as long as this stream wrapper is used to write to it. */ - explicit SequenceOutputStream( StreamDataSequence const & rData ); + explicit SequenceOutputStream( StreamDataSequence & rData ); /** Writes the passed data sequence. */ virtual void writeData( const StreamDataSequence& rData, size_t nAtomSize = 1 ) override; /** Write nBytes bytes from the (preallocated!) buffer pMem. */ virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override; + + /** Returns the size of the wrapped data sequence. */ + virtual sal_Int64 size() const override; + /** Returns the current stream position. */ + virtual sal_Int64 tell() const override; + /** Seeks the stream to the passed position. */ + virtual void seek( sal_Int64 nPos ) override; + /** Releases the reference to the data sequence. */ + virtual void close() override; + +private: + StreamDataSequence* mpData; ///< Wrapped data sequence. + sal_Int32 mnPos; ///< Current position in the sequence. }; diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx index 4945039c901b..6ac5048072bf 100644 --- a/oox/source/core/filterbase.cxx +++ b/oox/source/core/filterbase.cxx @@ -379,7 +379,7 @@ VbaProject& FilterBase::getVbaProject() const return *mxImpl->mxVbaProject; } -bool FilterBase::importBinaryData( StreamDataSequence const & orDataSeq, const OUString& rStreamName ) +bool FilterBase::importBinaryData( StreamDataSequence & orDataSeq, const OUString& rStreamName ) { OSL_ENSURE( !rStreamName.isEmpty(), "FilterBase::importBinaryData - empty stream name" ); if( rStreamName.isEmpty() ) diff --git a/oox/source/helper/binaryoutputstream.cxx b/oox/source/helper/binaryoutputstream.cxx index f75e2f5bc024..652b768f81b9 100644 --- a/oox/source/helper/binaryoutputstream.cxx +++ b/oox/source/helper/binaryoutputstream.cxx @@ -130,9 +130,10 @@ void BinaryOutputStream::writeCompressedUnicodeArray( const OUString& rString, b writeUnicodeArray( rString ); } -SequenceOutputStream::SequenceOutputStream( StreamDataSequence const & rData ) : +SequenceOutputStream::SequenceOutputStream( StreamDataSequence & rData ) : BinaryStreamBase( true ), - SequenceSeekableStream( rData ) + mpData( &rData ), + mnPos( 0 ) { } @@ -147,12 +148,38 @@ void SequenceOutputStream::writeMemory( const void* pMem, sal_Int32 nBytes, size if( mpData && (nBytes > 0) ) { if( mpData->getLength() - mnPos < nBytes ) - const_cast< StreamDataSequence* >( mpData )->realloc( mnPos + nBytes ); - memcpy( const_cast< StreamDataSequence* >( mpData )->getArray() + mnPos, pMem, static_cast< size_t >( nBytes ) ); + mpData->realloc( mnPos + nBytes ); + memcpy( mpData->getArray() + mnPos, pMem, static_cast< size_t >( nBytes ) ); mnPos += nBytes; } } +sal_Int64 SequenceOutputStream::size() const +{ + return mpData ? mpData->getLength() : -1; +} + +sal_Int64 SequenceOutputStream::tell() const +{ + return mpData ? mnPos : -1; +} + +void SequenceOutputStream::seek( sal_Int64 nPos ) +{ + if( mpData ) + { + mnPos = getLimitedValue< sal_Int32, sal_Int64 >( nPos, 0, mpData->getLength() ); + mbEof = mnPos != nPos; + } +} + +void SequenceOutputStream::close() +{ + mpData = nullptr; + mbEof = true; +} + + } // namespace oox /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/inc/worksheetfragment.hxx b/sc/source/filter/inc/worksheetfragment.hxx index 512412d24ea2..4993bc67f198 100644 --- a/sc/source/filter/inc/worksheetfragment.hxx +++ b/sc/source/filter/inc/worksheetfragment.hxx @@ -176,7 +176,7 @@ private: void importControl( SequenceInputStream& rStrm ); /** Imports the binary data of an embedded OLE object from the fragment with the passed ID. */ - void importEmbeddedOleData( const StreamDataSequence& orEmbeddedData, const OUString& rRelId ); + void importEmbeddedOleData( StreamDataSequence& orEmbeddedData, const OUString& rRelId ); }; } // namespace xls diff --git a/sc/source/filter/oox/worksheetfragment.cxx b/sc/source/filter/oox/worksheetfragment.cxx index 57a8d0051f44..703593747c22 100644 --- a/sc/source/filter/oox/worksheetfragment.cxx +++ b/sc/source/filter/oox/worksheetfragment.cxx @@ -895,7 +895,7 @@ void WorksheetFragment::importControl( SequenceInputStream& rStrm ) getVmlDrawing().registerControl( aInfo ); } -void WorksheetFragment::importEmbeddedOleData( const StreamDataSequence& orEmbeddedData, const OUString& rRelId ) +void WorksheetFragment::importEmbeddedOleData( StreamDataSequence& orEmbeddedData, const OUString& rRelId ) { OUString aFragmentPath = getFragmentPathFromRelId( rRelId ); if( !aFragmentPath.isEmpty() ) |