summaryrefslogtreecommitdiff
path: root/sax/source/tools/fastserializer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sax/source/tools/fastserializer.cxx')
-rw-r--r--sax/source/tools/fastserializer.cxx98
1 files changed, 86 insertions, 12 deletions
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index b475f6d2342c..7e8394039831 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -135,6 +135,9 @@ namespace sax_fastparser {
if (!mxOutputStream.is())
return;
+ if ( !maMarkStack.empty() )
+ maMarkStack.top()->setCurrentElement( Element );
+
writeBytes(toUnoSequence(aOpeningBracket));
writeId(Element);
@@ -202,6 +205,9 @@ namespace sax_fastparser {
if (!mxOutputStream.is())
return;
+ if ( !maMarkStack.empty() )
+ maMarkStack.top()->setCurrentElement( Element );
+
writeBytes(toUnoSequence(aOpeningBracket));
writeId(Element);
@@ -323,24 +329,31 @@ namespace sax_fastparser {
return aRet;
}
- void FastSaxSerializer::mark()
+ void FastSaxSerializer::mark( Int32Sequence aOrder )
{
- maMarkStack.push( ForMerge() );
+ if ( aOrder.hasElements() )
+ {
+ boost::shared_ptr< ForMerge > pSort( new ForSort( aOrder ) );
+ maMarkStack.push( pSort );
+ }
+ else
+ {
+ boost::shared_ptr< ForMerge > pMerge( new ForMerge( ) );
+ maMarkStack.push( pMerge );
+ }
}
#if DEBUG
void FastSaxSerializer::printMarkStack( )
{
- ::std::stack< ForMerge > aCopy( maMarkStack );
+ ::std::stack< boost::shared_ptr< ForMerge > > aCopy( maMarkStack );
int nSize = aCopy.size();
int i = 0;
while ( !aCopy.empty() )
{
fprintf( stderr, "%d\n", nSize - i );
- ForMerge aMarks = aCopy.top( );
- aMarks.print();
-
+ aCopy.top( )->print( );
fprintf( stderr, "\n" );
@@ -357,19 +370,19 @@ namespace sax_fastparser {
if ( maMarkStack.size() == 1 )
{
- mxOutputStream->writeBytes( maMarkStack.top().getData() );
+ mxOutputStream->writeBytes( maMarkStack.top()->getData() );
maMarkStack.pop();
return;
}
- const Int8Sequence aMerge( maMarkStack.top().getData() );
+ const Int8Sequence aMerge( maMarkStack.top()->getData() );
maMarkStack.pop();
switch ( eMergeType )
{
- case MERGE_MARKS_APPEND: maMarkStack.top().append( aMerge ); break;
- case MERGE_MARKS_PREPEND: maMarkStack.top().prepend( aMerge ); break;
- case MERGE_MARKS_POSTPONE: maMarkStack.top().postpone( aMerge ); break;
+ case MERGE_MARKS_APPEND: maMarkStack.top()->append( aMerge ); break;
+ case MERGE_MARKS_PREPEND: maMarkStack.top()->prepend( aMerge ); break;
+ case MERGE_MARKS_POSTPONE: maMarkStack.top()->postpone( aMerge ); break;
}
}
@@ -378,7 +391,7 @@ namespace sax_fastparser {
if ( maMarkStack.empty() )
mxOutputStream->writeBytes( aData );
else
- maMarkStack.top().append( aData );
+ maMarkStack.top()->append( aData );
}
FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData()
@@ -445,6 +458,67 @@ namespace sax_fastparser {
}
}
+ void FastSaxSerializer::ForMerge::resetData( )
+ {
+ maData = Int8Sequence();
+ }
+
+ void FastSaxSerializer::ForSort::setCurrentElement( sal_Int32 nElement )
+ {
+ mnCurrentElement = nElement;
+ if ( maData.find( nElement ) == maData.end() )
+ maData[ nElement ] = Int8Sequence();
+ }
+
+ void FastSaxSerializer::ForSort::prepend( const Int8Sequence &rWhat )
+ {
+ append( rWhat );
+ }
+
+ void FastSaxSerializer::ForSort::append( const Int8Sequence &rWhat )
+ {
+ merge( maData[mnCurrentElement], rWhat, true );
+ }
+
+ void FastSaxSerializer::ForSort::sort()
+ {
+ // Clear the ForMerge data to avoid duplicate items
+ resetData();
+
+ // Sort it all
+ std::map< sal_Int32, Int8Sequence >::iterator iter;
+ for ( sal_Int32 i=0, len=maOrder.getLength(); i < len; i++ )
+ {
+ iter = maData.find( maOrder[i] );
+ if ( iter != maData.end() )
+ ForMerge::append( iter->second );
+ }
+ }
+
+ FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForSort::getData()
+ {
+ sort( );
+ return ForMerge::getData();
+ }
+
+#if DEBUG
+ void FastSaxSerializer::ForSort::print( )
+ {
+ std::map< sal_Int32, Int8Sequence >::iterator iter = maData.begin();
+ while ( iter != maData.end( ) )
+ {
+ fprintf( stderr, "pair: %d, ", iter->first );
+ for ( sal_Int32 i=0, len=iter->second.getLength(); i < len; i++ )
+ fprintf( stderr, "%c", iter->second[i] );
+ fprintf( stderr, "\n" );
+ iter++;
+ }
+
+ sort( );
+ ForMerge::print();
+ }
+#endif
+
} // namespace sax_fastparser
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */