fix SequenceOutputStream constness

Change-Id: I6e1039c077602b2cb42702cb4131f9503ef533c2
This commit is contained in:
Noel Grandin
2017-09-18 15:50:25 +02:00
parent f320d1edeb
commit ba91bc1902
6 changed files with 50 additions and 10 deletions

View File

@@ -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 -------------------------------

View File

@@ -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.
};

View File

@@ -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() )

View File

@@ -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: */

View File

@@ -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

View File

@@ -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() )