/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ #pragma once
inline SvStream& operator<<( SvStream& rStr, SvStrPtr f );
// SvLockBytes
struct SvLockBytesStat
{
std::size_t nSize;
SvLockBytesStat() : nSize(0) {}
};
/** This is only extended by UcbLockBytes in ucb/ and appears to exist to allow UCB to do delayed feeding of data into a SvStream i.e. a kind of a pipe mechanism to allow asynchronous fetching of data.
*/ class UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) SvLockBytes: public SvRefBase
{ bool m_bSync;
// buffer management
std::unique_ptr<sal_uInt8[]>
m_pRWBuf; ///< Points to read/write buffer
sal_uInt8* m_pBufPos; ///< m_pRWBuf + m_nBufActualPos
sal_uInt16 m_nBufSize; ///< Allocated size of buffer
sal_uInt16 m_nBufActualLen; ///< Length of used segment of buffer ///< = m_nBufSize, if EOF did not occur
sal_uInt16 m_nBufActualPos; ///< current position in buffer (0..m_nBufSize-1)
sal_uInt16 m_nBufFree; ///< number of free slots in buffer to IO of type eIOMode bool m_isIoRead; bool m_isIoWrite;
template <typename N>
SvStream& WriteNumberAsString( N n ) { return WriteOString(OString::number(n)); }
std::size_t ReadBytes( void* pData, std::size_t nSize );
std::size_t WriteBytes( constvoid* pData, std::size_t nSize );
sal_uInt64 Seek( sal_uInt64 nPos );
sal_uInt64 SeekRel( sal_Int64 nPos );
sal_uInt64 Tell() const { return m_nBufFilePos + m_nBufActualPos; } virtual sal_uInt64 TellEnd(); // length between current (Tell()) pos and end of stream
sal_uInt64 remainingSize(); /// If we have data in our internal buffers, write them out void FlushBuffer(); /// Call FlushBuffer() and then call flush on the underlying OS stream void Flush(); // next Tell() <= nSize bool SetStreamSize( sal_uInt64 nSize );
/** Read a line of bytes.
@param nMaxBytesToRead Maximum of bytes to read, if line is longer it will be truncated.
@note NOTE that the default is one character less than STRING_MAXLEN to prevent problems after conversion to String that may be lurking in various places doing something like @code for (sal_uInt16 i=0; i < aString.Len(); ++i) @endcode causing endless loops ...
*/ bool ReadLine( OStringBuffer& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE ); bool ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE ); bool WriteLine( std::string_view rStr );
/** Read a line of bytes.
@param nMaxBytesToRead Maximum of bytes to read, if line is longer it will be truncated.
@note NOTE that the default is one character less than STRING_MAXLEN to prevent problems after conversion to String that may be lurking in various places doing something like @code for (sal_uInt16 i=0; i < aString.Len(); ++i) @endcode causing endless loops ...
*/ bool ReadByteStringLine( OUString& rStr, rtl_TextEncoding eSrcCharSet,
sal_Int32 nMaxBytesToRead = 0xFFFE ); bool WriteByteStringLine( std::u16string_view rStr, rtl_TextEncoding eDestCharSet );
/// Switch to no endian swapping and write 0xfeff void StartWritingUnicodeText();
/** If eReadBomCharSet==RTL_TEXTENCODING_DONTKNOW: read 16bit, if 0xfeff do nothing (UTF-16), if 0xfffe switch endian swapping (UTF-16), if 0xefbb or 0xbbef read another byte and check for UTF-8. If no UTF-* BOM was detected put all read bytes back. This means that if 2 bytes were read it was an UTF-16 BOM, if 3 bytes were read it was an UTF-8 BOM. There is no UTF-7, UTF-32 or UTF-EBCDIC BOM detection!
If eReadBomCharSet!=RTL_TEXTENCODING_DONTKNOW: only read a BOM of that
encoding and switch endian swapping if UTF-16 and 0xfffe. */ void StartReadingUnicodeText( rtl_TextEncoding eReadBomCharSet );
/** Read a line of Unicode.
@param nMaxCodepointsToRead Maximum of codepoints (UCS-2 or UTF-16 pairs, not bytes) to read, if line is longer it will be truncated.
*/
SAL_DLLPRIVATE bool ReadUniStringLine(OUString& rStr, sal_Int32 nMaxCodepointsToRead); /** Read a 32bit length prefixed sequence of utf-16 if eSrcCharSet==RTL_TEXTENCODING_UNICODE, otherwise read a 16bit length
prefixed sequence of bytes and convert from eSrcCharSet */
OUString ReadUniOrByteString(rtl_TextEncoding eSrcCharSet); /** Write a 32bit length prefixed sequence of utf-16 if eSrcCharSet==RTL_TEXTENCODING_UNICODE, otherwise convert to eSrcCharSet
and write a 16bit length prefixed sequence of bytes */
SvStream& WriteUniOrByteString( std::u16string_view rStr, rtl_TextEncoding eDestCharSet );
/** Read a line of Unicode if eSrcCharSet==RTL_TEXTENCODING_UNICODE, otherwise read a line of Bytecode and convert from eSrcCharSet
@param nMaxCodepointsToRead Maximum of codepoints (2 bytes if Unicode, bytes if not Unicode) to read, if line is longer it will be truncated.
@note NOTE that the default is one character less than STRING_MAXLEN to prevent problems after conversion to String that may be lurking in various places doing something like @code for (sal_uInt16 i=0; i < aString.Len(); ++i) @endcode causing endless loops ...
*/ bool ReadUniOrByteStringLine( OUString& rStr, rtl_TextEncoding eSrcCharSet,
sal_Int32 nMaxCodepointsToRead = 0xFFFE ); /** Write a sequence of Unicode characters if eDestCharSet==RTL_TEXTENCODING_UNICODE, otherwise write a sequence of
Bytecodes converted to eDestCharSet. Write trailing zero, if bZero is true. */ bool WriteUnicodeOrByteText(std::u16string_view rStr, rtl_TextEncoding eDestCharSet, bool bZero = false); bool WriteUnicodeOrByteText(std::u16string_view rStr)
{ return WriteUnicodeOrByteText(rStr, GetStreamCharSet(), /*bZero*/false); }
/** Write a Unicode character if eDestCharSet==RTL_TEXTENCODING_UNICODE, otherwise write as Bytecode converted to eDestCharSet.
This may result in more than one byte being written if a multi byte
encoding (e.g. UTF7, UTF8) is chosen. */ bool WriteUniOrByteChar( sal_Unicode ch, rtl_TextEncoding eDestCharSet ); bool WriteUniOrByteChar( sal_Unicode ch )
{ return WriteUniOrByteChar( ch, GetStreamCharSet() ); }
TOOLS_DLLPUBLIC SvStream& endl( SvStream& rStr ); /// same as endl() but Unicode
TOOLS_DLLPUBLIC SvStream& endlu( SvStream& rStr ); /// call endlu() if m_eStreamCharSet==RTL_TEXTECODING_UNICODE otherwise endl()
TOOLS_DLLPUBLIC SvStream& endlub( SvStream& rStr );
/// Attempt to read nUnits 8bit units to an OString, returned OString's /// length is number of units successfully read
TOOLS_DLLPUBLIC OString read_uInt8s_ToOString(SvStream& rStrm,
std::size_t nUnits);
/// Attempt to read nUnits 8bit units to an OUString inline OUString read_uInt8s_ToOUString(SvStream& rStrm,
std::size_t nUnits, rtl_TextEncoding eEnc)
{ return OStringToOUString(read_uInt8s_ToOString(rStrm, nUnits), eEnc);
}
/// Attempt to read nUnits 16bit units to an OUString, returned /// OUString's length is number of units successfully read
TOOLS_DLLPUBLIC OUString read_uInt16s_ToOUString(SvStream& rStrm,
std::size_t nUnits);
/// Attempt to read a pascal-style length (of type prefix) prefixed sequence of /// 16bit units to an OUString, returned OString's length is number of /// units successfully read. inline OUString read_uInt16_lenPrefixed_uInt16s_ToOUString(SvStream& rStrm)
{
sal_uInt16 nUnits = 0;
rStrm.ReadUInt16( nUnits ); return read_uInt16s_ToOUString(rStrm, nUnits);
}
/// Attempt to write a pascal-style length (of type prefix) prefixed sequence /// of 16bit units from an OUString, returned value is number of bytes written /// (including byte-count of prefix)
std::size_t write_uInt32_lenPrefixed_uInt16s_FromOUString(SvStream& rStrm,
std::u16string_view rStr);
/// Attempt to write a pascal-style length (of type prefix) prefixed sequence /// of 16bit units from an OUString, returned value is number of bytes written /// (including byte-count of prefix)
UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) std::size_t write_uInt16_lenPrefixed_uInt16s_FromOUString(SvStream& rStrm,
std::u16string_view rStr);
/// Attempt to read 8bit units to an OString until a zero terminator is /// encountered, returned OString's length is number of units *definitely* /// successfully read, check SvStream::good() to see if null terminator was /// successfully read
TOOLS_DLLPUBLIC OString read_zeroTerminated_uInt8s_ToOString(SvStream& rStrm);
/// Attempt to read 8bit units assuming source encoding eEnc to an OUString /// until a zero terminator is encountered. Check SvStream::good() to see if /// null terminator was successfully read
TOOLS_DLLPUBLIC OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rStrm, rtl_TextEncoding eEnc);
/// Attempt to read a pascal-style length (of type prefix) prefixed sequence of /// 8bit units to an OString, returned OString's length is number of units /// successfully read. inline OString read_uInt32_lenPrefixed_uInt8s_ToOString(SvStream& rStrm)
{
sal_uInt32 nUnits = 0;
rStrm.ReadUInt32(nUnits); return read_uInt8s_ToOString(rStrm, nUnits);
} inline OString read_uInt16_lenPrefixed_uInt8s_ToOString(SvStream& rStrm)
{
sal_uInt16 nUnits = 0;
rStrm.ReadUInt16(nUnits); return read_uInt8s_ToOString(rStrm, nUnits);
}
/// Attempt to write a pascal-style length (of type prefix) prefixed /// sequence of units from a string-type, returned value is number of bytes /// written (including byte-count of prefix)
TOOLS_DLLPUBLIC std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString(SvStream& rStrm,
std::string_view rStr);
/// Attempt to write a pascal-style length (of type prefix) prefixed sequence /// of 8bit units from an OUString, returned value is number of bytes written /// (including byte-count of prefix) inline std::size_t write_uInt16_lenPrefixed_uInt8s_FromOUString(SvStream& rStrm,
std::u16string_view rStr,
rtl_TextEncoding eEnc)
{ return write_uInt16_lenPrefixed_uInt8s_FromOString(rStrm, OUStringToOString(rStr, eEnc));
}
namespace tools
{ /// Is rUrl a file:// URL with no contents?
TOOLS_DLLPUBLIC bool isEmptyFileUrl(const OUString& rUrl);
}
// FileStream
class TOOLS_DLLPUBLIC SvFileStream final : public SvStream
{ private: void* mxFileHandle = nullptr; // on windows, it is a HANDLE, otherwise, it is a oslFileHandle #ifdefined(_WIN32)
sal_uInt16 nLockCounter; #endif
OUString aFilename; bool bIsOpen;
/// AllocateMemory must update pBuf accordingly /// - pBuf: Address of new block void AllocateMemory( std::size_t nSize );
/// ReAllocateMemory must update the following variables: /// - pBuf: Address of new block /// - nEndOfData: Set to nNewSize-1 , if outside of block /// Set to 0 , if new block size is 0 bytes /// - nSize: New block size /// - nPos: Set to 0 if position outside of block bool ReAllocateMemory( tools::Long nDiff );
/// Is called when this stream allocated the buffer or the buffer is /// resized. FreeMemory may need to NULLify handles in derived classes. void FreeMemory();
// return the buffer currently in use, and allocate a new buffer internally void* SwitchBuffer(); // the buffer is not owned by this class void SetBuffer( void* pBuf, std::size_t nSize, std::size_t nEOF );
void ObjectOwnsMemory( bool bOwn ) { bOwnsData = bOwn; } /// Makes the stream read-only after it was (possibly) initially writable, /// without having to copy the data or change buffers. /// @since LibreOffice 7.5 void MakeReadOnly(); void SetResizeOffset( std::size_t nNewResize ) { nResize = nNewResize; } virtual sal_uInt64 TellEnd() override final { FlushBuffer(); return nEndOfData; }
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.