Kaydet (Commit) 2842c5cf authored tarafından Michael Stahl's avatar Michael Stahl

sax, sw: try to make that maMarkStack easier to understand

In DocxAttributeOutput it's not at all obvious which mark() is supposed
to be ended by which mergeTopMarks(), so add an extra parameter to the
FastSaxSerializer functions and verify with an assertion that a LIFO
order is maintained.

Change-Id: I5a421e2fb11f15343147417fe0b9b23642c70721
üst 7352a7c1
...@@ -137,9 +137,11 @@ public: ...@@ -137,9 +137,11 @@ public:
static FastAttributeList *createAttrList(); static FastAttributeList *createAttrList();
void mark( const ::com::sun::star::uno::Sequence< sal_Int32 >& aOrder = void mark(sal_Int32 nTag,
const ::com::sun::star::uno::Sequence< sal_Int32 >& rOrder =
::com::sun::star::uno::Sequence< sal_Int32 >() ); ::com::sun::star::uno::Sequence< sal_Int32 >() );
void mergeTopMarks( MergeMarksEnum eMergeType = MERGE_MARKS_APPEND ); void mergeTopMarks(sal_Int32 nTag,
MergeMarksEnum eMergeType = MERGE_MARKS_APPEND );
/* /*
Now create all the overloads in a typesafe way (i.e. without varargs) by creating a number of overloads Now create all the overloads in a typesafe way (i.e. without varargs) by creating a number of overloads
......
...@@ -45,6 +45,9 @@ using namespace sax_fastparser; ...@@ -45,6 +45,9 @@ using namespace sax_fastparser;
using namespace oox::vml; using namespace oox::vml;
using namespace com::sun::star; using namespace com::sun::star;
static const sal_Int32 Tag_Container = 44444;
static const sal_Int32 Tag_Commit = 44445;
VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr pSerializer, VMLTextExport* pTextExport ) VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr pSerializer, VMLTextExport* pTextExport )
: EscherEx( EscherExGlobalRef(new EscherExGlobal(0)), 0, /*bOOXML=*/true ) : EscherEx( EscherExGlobalRef(new EscherExGlobal(0)), 0, /*bOOXML=*/true )
, m_pSerializer( pSerializer ) , m_pSerializer( pSerializer )
...@@ -98,7 +101,7 @@ void VMLExport::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance ) ...@@ -98,7 +101,7 @@ void VMLExport::OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance )
// postpone the output so that we are able to write even the elements // postpone the output so that we are able to write even the elements
// that we learn inside Commit() // that we learn inside Commit()
m_pSerializer->mark(); m_pSerializer->mark(Tag_Container);
} }
} }
...@@ -109,7 +112,7 @@ void VMLExport::CloseContainer() ...@@ -109,7 +112,7 @@ void VMLExport::CloseContainer()
// write the shape now when we have all the info // write the shape now when we have all the info
sal_Int32 nShapeElement = StartShape(); sal_Int32 nShapeElement = StartShape();
m_pSerializer->mergeTopMarks(); m_pSerializer->mergeTopMarks(Tag_Container);
EndShape( nShapeElement ); EndShape( nShapeElement );
...@@ -357,7 +360,7 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect ...@@ -357,7 +360,7 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect
// postpone the output of the embedded elements so that they are written // postpone the output of the embedded elements so that they are written
// inside the shapes // inside the shapes
m_pSerializer->mark(); m_pSerializer->mark(Tag_Commit);
// dimensions // dimensions
if ( m_nShapeType == ESCHER_ShpInst_Line ) if ( m_nShapeType == ESCHER_ShpInst_Line )
...@@ -860,7 +863,7 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect ...@@ -860,7 +863,7 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect
} }
} }
m_pSerializer->mergeTopMarks( sax_fastparser::MERGE_MARKS_POSTPONE ); m_pSerializer->mergeTopMarks(Tag_Commit, sax_fastparser::MERGE_MARKS_POSTPONE );
} }
OString VMLExport::ShapeIdString( sal_uInt32 nId ) OString VMLExport::ShapeIdString( sal_uInt32 nId )
......
...@@ -330,17 +330,17 @@ namespace sax_fastparser { ...@@ -330,17 +330,17 @@ namespace sax_fastparser {
} }
} }
void FastSaxSerializer::mark( const Int32Sequence& aOrder ) void FastSaxSerializer::mark(sal_Int32 const nTag, const Int32Sequence& rOrder)
{ {
if ( aOrder.hasElements() ) if (rOrder.hasElements())
{ {
boost::shared_ptr< ForMerge > pSort( new ForSort( aOrder ) ); boost::shared_ptr< ForMerge > pSort( new ForSort(nTag, rOrder) );
maMarkStack.push( pSort ); maMarkStack.push( pSort );
maCachedOutputStream.setOutput( pSort ); maCachedOutputStream.setOutput( pSort );
} }
else else
{ {
boost::shared_ptr< ForMerge > pMerge( new ForMerge( ) ); boost::shared_ptr< ForMerge > pMerge( new ForMerge(nTag) );
maMarkStack.push( pMerge ); maMarkStack.push( pMerge );
maCachedOutputStream.setOutput( pMerge ); maCachedOutputStream.setOutput( pMerge );
} }
...@@ -401,12 +401,16 @@ namespace sax_fastparser { ...@@ -401,12 +401,16 @@ namespace sax_fastparser {
} }
#endif #endif
void FastSaxSerializer::mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType ) void FastSaxSerializer::mergeTopMarks(
sal_Int32 const nTag, sax_fastparser::MergeMarksEnum const eMergeType)
{ {
SAL_WARN_IF(mbMarkStackEmpty, "sax", "Empty mark stack - nothing to merge"); SAL_WARN_IF(mbMarkStackEmpty, "sax", "Empty mark stack - nothing to merge");
assert(!mbMarkStackEmpty); // should never happen
if ( mbMarkStackEmpty ) if ( mbMarkStackEmpty )
return; return;
assert(maMarkStack.top()->m_Tag == nTag && "mark/merge tag mismatch!");
(void) nTag;
#ifdef DBG_UTIL #ifdef DBG_UTIL
if (dynamic_cast<ForSort*>(maMarkStack.top().get())) if (dynamic_cast<ForSort*>(maMarkStack.top().get()))
{ {
......
...@@ -127,8 +127,10 @@ public: ...@@ -127,8 +127,10 @@ public:
p, r, mark(), t, [text], /t, mark(), rPr, [something], /rPr, p, r, mark(), t, [text], /t, mark(), rPr, [something], /rPr,
mergeTopMarks( MERGE_MARKS_PREPEND ), mergeTopMarks( MERGE_MARKS_APPEND ), /r, /p mergeTopMarks( MERGE_MARKS_PREPEND ), mergeTopMarks( MERGE_MARKS_APPEND ), /r, /p
and you are done. and you are done.
@param nTag debugging aid to ensure mark and merge match in LIFO order
*/ */
void mark( const Int32Sequence& aOrder = Int32Sequence() ); void mark(sal_Int32 nTag, const Int32Sequence& rOrder = Int32Sequence());
/** Merge 2 topmost marks. /** Merge 2 topmost marks.
...@@ -143,9 +145,12 @@ public: ...@@ -143,9 +145,12 @@ public:
When the MERGE_MARKS_POSTPONE is specified, the merge happens just When the MERGE_MARKS_POSTPONE is specified, the merge happens just
before the next merge. before the next merge.
@param nTag debugging aid to ensure mark and merge match in LIFO order
@see mark() @see mark()
*/ */
void mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType = sax_fastparser::MERGE_MARKS_APPEND ); void mergeTopMarks(sal_Int32 nTag,
sax_fastparser::MergeMarksEnum eMergeType = sax_fastparser::MERGE_MARKS_APPEND);
private: private:
/** Helper class to cache data and write in chunks to XOutputStream or ForMerge::append. /** Helper class to cache data and write in chunks to XOutputStream or ForMerge::append.
...@@ -161,6 +166,7 @@ private: ...@@ -161,6 +166,7 @@ private:
Int8Sequence maPostponed; Int8Sequence maPostponed;
public: public:
sal_Int32 const m_Tag;
#ifdef DBG_UTIL #ifdef DBG_UTIL
// pending close tags, followed by pending open tags // pending close tags, followed by pending open tags
::std::deque<sal_Int32> m_DebugEndedElements; ::std::deque<sal_Int32> m_DebugEndedElements;
...@@ -170,7 +176,7 @@ private: ...@@ -170,7 +176,7 @@ private:
::std::deque<sal_Int32> m_DebugPostponedStartedElements; ::std::deque<sal_Int32> m_DebugPostponedStartedElements;
#endif #endif
ForMerge() : maData(), maPostponed() {} ForMerge(sal_Int32 const nTag) : m_Tag(nTag) {}
virtual ~ForMerge() {} virtual ~ForMerge() {}
virtual void setCurrentElement( ::sal_Int32 /*nToken*/ ) {} virtual void setCurrentElement( ::sal_Int32 /*nToken*/ ) {}
...@@ -196,11 +202,11 @@ private: ...@@ -196,11 +202,11 @@ private:
Int32Sequence maOrder; Int32Sequence maOrder;
public: public:
ForSort( const Int32Sequence& aOrder ) : ForSort(sal_Int32 const nTag, const Int32Sequence& rOrder)
ForMerge(), : ForMerge(nTag)
maData(), , mnCurrentElement( 0 )
mnCurrentElement( 0 ), , maOrder( rOrder )
maOrder( aOrder ) {} {}
void setCurrentElement( ::sal_Int32 nToken ) SAL_OVERRIDE; void setCurrentElement( ::sal_Int32 nToken ) SAL_OVERRIDE;
......
...@@ -153,14 +153,16 @@ FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId) ...@@ -153,14 +153,16 @@ FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
return mpSerializer->getOutputStream(); return mpSerializer->getOutputStream();
} }
void FastSerializerHelper::mark( const Sequence< sal_Int32 >& aOrder ) void FastSerializerHelper::mark(
sal_Int32 const nTag, const Sequence<sal_Int32>& rOrder)
{ {
mpSerializer->mark( aOrder ); mpSerializer->mark(nTag, rOrder);
} }
void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType ) void FastSerializerHelper::mergeTopMarks(
sal_Int32 const nTag, MergeMarksEnum const eMergeType)
{ {
mpSerializer->mergeTopMarks( eMergeType ); mpSerializer->mergeTopMarks(nTag, eMergeType);
} }
FastAttributeList * FastSerializerHelper::createAttrList() FastAttributeList * FastSerializerHelper::createAttrList()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment