diff options
author | Adrian Kummerlaender | 2014-07-13 21:46:39 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-07-13 21:46:39 +0200 |
commit | a3fe119214fa61b571326348f3ed23ec7ffd77e6 (patch) | |
tree | 5bf8a6091261cefec755d24c31095928139ef0b3 | |
parent | 086779c6d3d40f244b6aafd6d402fd29b921a735 (diff) | |
download | InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.tar InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.tar.gz InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.tar.bz2 InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.tar.lz InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.tar.xz InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.tar.zst InputXSLT-a3fe119214fa61b571326348f3ed23ec7ffd77e6.zip |
Improved xalan::XalanCompiledStylesheet lifetime management
* added custom deleter for xalan::XalanCompiledStylesheet specific std::unique_ptr specialization
* added previously missing check for successful stylesheet compilation
-rw-r--r-- | src/transformer_facade.cc | 100 |
1 files changed, 66 insertions, 34 deletions
diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc index 5910bc7..431b9f8 100644 --- a/src/transformer_facade.cc +++ b/src/transformer_facade.cc @@ -49,6 +49,44 @@ std::unique_ptr<xalan::FormatterToXML> augmentFormatterToXML( ); } +class compiled_stylesheet_deleter { + public: + compiled_stylesheet_deleter(xalan::XalanTransformer* transformer): + transformer_(transformer) { } + + void operator()(const xalan::XalanCompiledStylesheet* transformation) { + this->transformer_->destroyStylesheet(transformation); + } + + private: + xalan::XalanTransformer* const transformer_; + +}; + +typedef std::unique_ptr< + const xalan::XalanCompiledStylesheet, + compiled_stylesheet_deleter +> CompiledStylesheetPtr; + +CompiledStylesheetPtr compileStylesheet( + xalan::XalanTransformer* const transformer, + const xalan::XSLTInputSource& transformation +) { + const xalan::XalanCompiledStylesheet* compiled{}; + + if ( transformer->compileStylesheet(transformation, compiled) == 0 ) { + return CompiledStylesheetPtr( + compiled, + compiled_stylesheet_deleter(transformer) + ); + } else { + return CompiledStylesheetPtr( + nullptr, + compiled_stylesheet_deleter(transformer) + ); + } +} + } namespace InputXSLT { @@ -159,42 +197,36 @@ void TransformerFacade::dispatchTransformer( const xalan::XSLTInputSource& transformation, xalan::FormatterListener& target ) { - const xalan::XalanCompiledStylesheet* compiledTransformation{}; - - this->transformer_.compileStylesheet( - transformation, - compiledTransformation - ); - - switch ( target.getOutputFormat() ) { - case xalan::FormatterListener::eFormat::OUTPUT_METHOD_XML: { - auto formatter = augmentFormatterToXML( - compiledTransformation, - target - ); - - this->transformer_.transform( - source, - compiledTransformation, - *formatter - ); - - break; - } - default: { - this->transformer_.transform( - source, - compiledTransformation, - target - ); - - break; + if ( auto compiledTransformation = compileStylesheet( + &(this->transformer_), + transformation + ) ) { + switch ( target.getOutputFormat() ) { + case xalan::FormatterListener::eFormat::OUTPUT_METHOD_XML: { + auto formatter = augmentFormatterToXML( + compiledTransformation.get(), + target + ); + + this->transformer_.transform( + source, + compiledTransformation.get(), + *formatter + ); + + break; + } + default: { + this->transformer_.transform( + source, + compiledTransformation.get(), + target + ); + + break; + } } } - - this->transformer_.destroyStylesheet( - compiledTransformation - ); } } |