LibreOffice Module sax (master) 1
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
sax_fastparser::FastSaxSerializer Class Reference

Receives notification of sax document events to write into an XOutputStream. More...

#include <fastserializer.hxx>

Collaboration diagram for sax_fastparser::FastSaxSerializer:
[legend]

Classes

class  ForMerge
 
class  ForSort
 

Public Member Functions

 FastSaxSerializer (const css::uno::Reference< css::io::XOutputStream > &xOutputStream)
 
 ~FastSaxSerializer ()
 
css::uno::Reference< css::io::XOutputStream > const & getOutputStream () const
 
TokenValueListgetTokenValueList ()
 called by FSHelper to put data in for writeTokenValueList More...
 
void startDocument ()
 called by the parser when parsing of an XML stream is started. More...
 
void endDocument ()
 called by the parser after the last XML element of a stream is processed. More...
 
void startFastElement (::sal_Int32 Element, FastAttributeList const *pAttrList=nullptr)
 receives notification of the beginning of an element. More...
 
void endFastElement (::sal_Int32 Element)
 receives notification of the end of a known element. More...
 
void singleFastElement (::sal_Int32 Element, FastAttributeList const *pAttrList=nullptr)
 receives notification of the beginning of a single element. More...
 
void writeId (::sal_Int32 Element)
 
OString getId (::sal_Int32 Element)
 
void write (double value)
 
void write (std::u16string_view s, bool bEscape=false)
 
void write (std::string_view s, bool bEscape=false)
 
void write (const char *pStr, sal_Int32 nLen, bool bEscape=false)
 
void setAllowXEscape (bool bSet)
 
void mark (sal_Int32 nTag, const Int32Sequence &rOrder)
 From now on, don't write directly to the stream, but to top of a stack. More...
 
void mergeTopMarks (sal_Int32 nTag, sax_fastparser::MergeMarks eMergeType)
 Merge 2 topmost marks. More...
 

Private Types

typedef css::uno::Sequence< ::sal_Int8Int8Sequence
 
typedef css::uno::Sequence< ::sal_Int32 > Int32Sequence
 

Private Member Functions

void writeTokenValueList ()
 
void writeFastAttributeList (FastAttributeList const &rAttrList)
 
void writeBytes (const css::uno::Sequence< ::sal_Int8 > &aData)
 Forward the call to the output stream, or write to the stack. More...
 
void writeBytes (const char *pStr, size_t nLen)
 

Private Attributes

CachedOutputStream maCachedOutputStream
 Helper class to cache data and write in chunks to XOutputStream or ForMerge::append. More...
 
css::uno::Reference< css::xml::sax::XFastTokenHandler > mxFastTokenHandler
 
std::stack< std::shared_ptr< ForMerge > > maMarkStack
 
bool mbMarkStackEmpty
 
rtl_String * mpDoubleStr
 
sal_Int32 mnDoubleStrCapacity
 
TokenValueList maTokenValues
 
bool mbXescape
 whether to escape invalid XML characters as xHHHH in write(const char*,sal_Int32,true) More...
 
std::stack< sal_Int32 > m_DebugStartedElements
 

Detailed Description

Receives notification of sax document events to write into an XOutputStream.

Definition at line 46 of file fastserializer.hxx.

Member Typedef Documentation

◆ Int32Sequence

typedef css::uno::Sequence< ::sal_Int32 > sax_fastparser::FastSaxSerializer::Int32Sequence
private

Definition at line 49 of file fastserializer.hxx.

◆ Int8Sequence

typedef css::uno::Sequence< ::sal_Int8 > sax_fastparser::FastSaxSerializer::Int8Sequence
private

Definition at line 48 of file fastserializer.hxx.

Constructor & Destructor Documentation

◆ FastSaxSerializer()

sax_fastparser::FastSaxSerializer::FastSaxSerializer ( const css::uno::Reference< css::io::XOutputStream > &  xOutputStream)
explicit

◆ ~FastSaxSerializer()

sax_fastparser::FastSaxSerializer::~FastSaxSerializer ( )

Definition at line 73 of file fastserializer.cxx.

References mpDoubleStr.

Member Function Documentation

◆ endDocument()

void sax_fastparser::FastSaxSerializer::endDocument ( )

called by the parser after the last XML element of a stream is processed.

Definition at line 310 of file fastserializer.cxx.

References sax_fastparser::CachedOutputStream::flush(), maCachedOutputStream, maMarkStack, and mbMarkStackEmpty.

◆ endFastElement()

void sax_fastparser::FastSaxSerializer::endFastElement ( ::sal_Int32  Element)

receives notification of the end of a known element.

See also
startFastElement

Definition at line 380 of file fastserializer.cxx.

References m_DebugStartedElements, maMarkStack, mbMarkStackEmpty, N_CHARS, sClosingBracket, sOpeningBracketAndSlash, writeBytes(), and writeId().

◆ getId()

OString sax_fastparser::FastSaxSerializer::getId ( ::sal_Int32  Element)

Definition at line 334 of file fastserializer.cxx.

References HAS_NAMESPACE, mxFastTokenHandler, name, NAMESPACE, ns, sColon, and TOKEN.

Referenced by writeFastAttributeList(), and writeTokenValueList().

◆ getOutputStream()

css::uno::Reference< css::io::XOutputStream > const & sax_fastparser::FastSaxSerializer::getOutputStream ( ) const

◆ getTokenValueList()

TokenValueList & sax_fastparser::FastSaxSerializer::getTokenValueList ( )
inline

called by FSHelper to put data in for writeTokenValueList

Definition at line 57 of file fastserializer.hxx.

References maTokenValues.

◆ mark()

void sax_fastparser::FastSaxSerializer::mark ( sal_Int32  nTag,
const Int32Sequence rOrder 
)

From now on, don't write directly to the stream, but to top of a stack.

This is to be able to change the order of the data being written. If you need to write eg. p, r, rPr, [something], /rPr, t, [text], /t, /r, /p, but get it in order p, r, t, [text], /t, rPr, [something], /rPr, /r, /p, simply do p, r, mark(), t, [text], /t, mark(), rPr, [something], /rPr, mergeTopMarks( MergeMarks::PREPEND ), mergeTopMarks( MergeMarks::APPEND ), /r, /p and you are done.

Parameters
nTagdebugging aid to ensure mark and merge match in LIFO order

Definition at line 506 of file fastserializer.cxx.

References maCachedOutputStream, maMarkStack, mbMarkStackEmpty, and sax_fastparser::CachedOutputStream::setOutput().

◆ mergeTopMarks()

void sax_fastparser::FastSaxSerializer::mergeTopMarks ( sal_Int32  nTag,
sax_fastparser::MergeMarks  eMergeType 
)

Merge 2 topmost marks.

The possibilities: prepend the top before the second top-most mark, append it, append it later or ignore; prepending brings the possibility to switch parts of the output, appending later allows to write some output in advance.

Writes the result to the output stream if the mark stack becomes empty by the operation.

When the MergeMarks::POSTPONE is specified, the merge happens just before the next merge.

Parameters
nTagdebugging aid to ensure mark and merge match in LIFO order
See also
mark()

Definition at line 577 of file fastserializer.cxx.

References sax_fastparser::APPEND, aSeq, sax_fastparser::CachedOutputStream::flush(), sax_fastparser::lcl_DebugMergeAppend(), sax_fastparser::lcl_DebugMergePrepend(), m_DebugStartedElements, maCachedOutputStream, maMarkStack, mbMarkStackEmpty, sax_fastparser::POSTPONE, sax_fastparser::PREPEND, sax_fastparser::CachedOutputStream::resetOutputToStream(), SAL_WARN_IF, sax_fastparser::CachedOutputStream::setOutput(), and sax_fastparser::CachedOutputStream::writeBytes().

◆ setAllowXEscape()

void sax_fastparser::FastSaxSerializer::setAllowXEscape ( bool  bSet)
inline

Definition at line 120 of file fastserializer.hxx.

References mbXescape.

◆ singleFastElement()

void sax_fastparser::FastSaxSerializer::singleFastElement ( ::sal_Int32  Element,
FastAttributeList const *  pAttrList = nullptr 
)

receives notification of the beginning of a single element.

Parameters
Elementcontains the integer token from the <type>XFastTokenHandler</type> registered at the <type>XFastParser</type>.

If the element has a namespace that was registered with the <type>XFastParser</type>, Element

contains the integer token of the elements local name from the <type>XFastTokenHandler</type> and the integer token of the namespace combined with an arithmetic or operation.

Parameters
pAttrListContains a <type>FastAttributeList</type> to access the attributes from the element.

Definition at line 416 of file fastserializer.cxx.

References sax_fastparser::CachedOutputStream::flush(), maCachedOutputStream, maMarkStack, mbMarkStackEmpty, N_CHARS, sOpeningBracket, sSlashAndClosingBracket, writeBytes(), writeFastAttributeList(), writeId(), and writeTokenValueList().

◆ startDocument()

void sax_fastparser::FastSaxSerializer::startDocument ( )

called by the parser when parsing of an XML stream is started.

Definition at line 78 of file fastserializer.cxx.

References N_CHARS, sXmlHeader, and writeBytes().

◆ startFastElement()

void sax_fastparser::FastSaxSerializer::startFastElement ( ::sal_Int32  Element,
FastAttributeList const *  pAttrList = nullptr 
)

receives notification of the beginning of an element.

Parameters
Elementcontains the integer token from the <type>XFastTokenHandler</type> registered at the <type>XFastParser</type>.

If the element has a namespace that was registered with the <type>XFastParser</type>, Element

contains the integer token of the elements local name from the <type>XFastTokenHandler</type> and the integer token of the namespace combined with an arithmetic or operation.

Parameters
pAttrListContains a <type>FastAttributeList</type> to access the attributes from the element.

Definition at line 354 of file fastserializer.cxx.

References sax_fastparser::CachedOutputStream::flush(), m_DebugStartedElements, maCachedOutputStream, maMarkStack, mbMarkStackEmpty, N_CHARS, sClosingBracket, sOpeningBracket, writeBytes(), writeFastAttributeList(), writeId(), and writeTokenValueList().

◆ write() [1/4]

void sax_fastparser::FastSaxSerializer::write ( const char *  pStr,
sal_Int32  nLen,
bool  bEscape = false 
)

◆ write() [2/4]

void sax_fastparser::FastSaxSerializer::write ( double  value)

Definition at line 83 of file fastserializer.cxx.

References mnDoubleStrCapacity, mpDoubleStr, value, and write().

Referenced by write(), writeFastAttributeList(), and writeTokenValueList().

◆ write() [3/4]

void sax_fastparser::FastSaxSerializer::write ( std::string_view  s,
bool  bEscape = false 
)

Definition at line 102 of file fastserializer.cxx.

References write().

◆ write() [4/4]

void sax_fastparser::FastSaxSerializer::write ( std::u16string_view  s,
bool  bEscape = false 
)

Definition at line 96 of file fastserializer.cxx.

References OUStringToOString(), and write().

◆ writeBytes() [1/2]

void sax_fastparser::FastSaxSerializer::writeBytes ( const char *  pStr,
size_t  nLen 
)
private

◆ writeBytes() [2/2]

void sax_fastparser::FastSaxSerializer::writeBytes ( const css::uno::Sequence< ::sal_Int8 > &  aData)
private

Forward the call to the output stream, or write to the stack.

The latter in the case that we are inside a mark().

Referenced by endFastElement(), singleFastElement(), startDocument(), startFastElement(), write(), writeFastAttributeList(), writeId(), and writeTokenValueList().

◆ writeFastAttributeList()

void sax_fastparser::FastSaxSerializer::writeFastAttributeList ( FastAttributeList const &  rAttrList)
private

◆ writeId()

void sax_fastparser::FastSaxSerializer::writeId ( ::sal_Int32  Element)

◆ writeTokenValueList()

void sax_fastparser::FastSaxSerializer::writeTokenValueList ( )
private

Member Data Documentation

◆ m_DebugStartedElements

std::stack<sal_Int32> sax_fastparser::FastSaxSerializer::m_DebugStartedElements
private

Definition at line 239 of file fastserializer.hxx.

Referenced by endFastElement(), mergeTopMarks(), and startFastElement().

◆ maCachedOutputStream

CachedOutputStream sax_fastparser::FastSaxSerializer::maCachedOutputStream
private

Helper class to cache data and write in chunks to XOutputStream or ForMerge::append.

Its flush method needs to be called before touching maMarkStack to ensure correct order of ForSort methods.

Definition at line 164 of file fastserializer.hxx.

Referenced by endDocument(), FastSaxSerializer(), getOutputStream(), mark(), mergeTopMarks(), singleFastElement(), startFastElement(), and writeBytes().

◆ maMarkStack

std::stack< std::shared_ptr< ForMerge > > sax_fastparser::FastSaxSerializer::maMarkStack
private

◆ maTokenValues

TokenValueList sax_fastparser::FastSaxSerializer::maTokenValues
private

Definition at line 234 of file fastserializer.hxx.

Referenced by getTokenValueList(), and writeTokenValueList().

◆ mbMarkStackEmpty

bool sax_fastparser::FastSaxSerializer::mbMarkStackEmpty
private

◆ mbXescape

bool sax_fastparser::FastSaxSerializer::mbXescape
private

whether to escape invalid XML characters as xHHHH in write(const char*,sal_Int32,true)

Definition at line 235 of file fastserializer.hxx.

Referenced by setAllowXEscape(), and write().

◆ mnDoubleStrCapacity

sal_Int32 sax_fastparser::FastSaxSerializer::mnDoubleStrCapacity
private

Definition at line 233 of file fastserializer.hxx.

Referenced by FastSaxSerializer(), and write().

◆ mpDoubleStr

rtl_String* sax_fastparser::FastSaxSerializer::mpDoubleStr
private

Definition at line 232 of file fastserializer.hxx.

Referenced by FastSaxSerializer(), write(), and ~FastSaxSerializer().

◆ mxFastTokenHandler

css::uno::Reference< css::xml::sax::XFastTokenHandler > sax_fastparser::FastSaxSerializer::mxFastTokenHandler
private

Definition at line 165 of file fastserializer.hxx.

Referenced by FastSaxSerializer(), getId(), and writeId().


The documentation for this class was generated from the following files: