diff options
author | Adrian Kummerländer | 2014-05-18 20:07:45 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-05-18 20:07:45 +0200 |
commit | d19a195985b96701b2ab302538fe24e87e76decf (patch) | |
tree | c6cd7fe10322c62463e93f82de2c9894b05add0b /src | |
parent | 246a8e020d97cfc3b4409996f99450fa95b730b1 (diff) | |
download | InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.tar InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.tar.gz InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.tar.bz2 InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.tar.lz InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.tar.xz InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.tar.zst InputXSLT-d19a195985b96701b2ab302538fe24e87e76decf.zip |
Added possibility for streaming TransformationFacade output
* added "std::basic_ostream<char>" taking "generate" member method overloads
* marked cli parameter "target" as optional
** output is streamed to std::cout if target file is not provided
Diffstat (limited to 'src')
-rw-r--r-- | src/transformation_facade.cc | 54 | ||||
-rw-r--r-- | src/transformation_facade.h | 41 |
2 files changed, 62 insertions, 33 deletions
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 41ee458..07483c1 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -25,49 +25,43 @@ TransformationFacade::~TransformationFacade() { ); } -int TransformationFacade::generate(const std::string& target) { - StylesheetParameterGuard guard(this->transformer_); - - return this->generate(target, guard); -} - int TransformationFacade::generate( - const std::string& target, - const StylesheetParameterGuard::map& parameters + const std::string& targetPath, + StylesheetParameterGuard& parameters ) { - StylesheetParameterGuard guard(this->transformer_, parameters); - - return this->generate(target, guard); -} + const boost::filesystem::path targetPathHelper( + boost::filesystem::absolute(targetPath) + ); -int TransformationFacade::generate( - const std::string& target, - const xalan::XObjectPtr& parameter -) { - StylesheetParameterGuard guard(this->transformer_); - guard.set("parameters", parameter); + parameters.set( + "target-file", targetPathHelper.filename().string() + ); + parameters.set( + "parent-directory", targetPathHelper.parent_path().filename().string() + ); - return this->generate(target, guard); + return this->generate( + xalan::XSLTResultTarget(targetPath.data()), + parameters + ); } int TransformationFacade::generate( - const std::string& target, + std::basic_ostream<char>& targetStream, StylesheetParameterGuard& parameters ) { - const boost::filesystem::path targetFilePath( - boost::filesystem::absolute(target) - ); - - parameters.set( - "target-file", targetFilePath.filename().string() - ); - parameters.set( - "parent-directory", targetFilePath.parent_path().filename().string() + return this->generate( + xalan::XSLTResultTarget(targetStream), + parameters ); +} +int TransformationFacade::generate( + xalan::XSLTResultTarget&& outputTarget, + StylesheetParameterGuard& +) { std::stringstream emptyStream("<dummy/>"); xalan::XSLTInputSource inputSource(emptyStream); - xalan::XSLTResultTarget outputTarget(target.data()); const int resultCode = this->transformer_.transform( inputSource, diff --git a/src/transformation_facade.h b/src/transformation_facade.h index be06d07..7fb0926 100644 --- a/src/transformation_facade.h +++ b/src/transformation_facade.h @@ -15,9 +15,14 @@ class TransformationFacade { explicit TransformationFacade(const std::string&); ~TransformationFacade(); - int generate(const std::string&); - int generate(const std::string&, const StylesheetParameterGuard::map&); - int generate(const std::string&, const xalan::XObjectPtr&); + template <typename Target> + int generate(Target&); + + template <typename Target> + int generate(Target&, const StylesheetParameterGuard::map&); + + template <typename Target> + int generate(Target&, const xalan::XObjectPtr&); private: const xalan::XalanCompiledStylesheet* transformation_; @@ -25,9 +30,39 @@ class TransformationFacade { xalan::XalanTransformer transformer_; int generate(const std::string&, StylesheetParameterGuard&); + int generate(std::basic_ostream<char>&, StylesheetParameterGuard&); + int generate(xalan::XSLTResultTarget&&, StylesheetParameterGuard&); }; +template <typename Target> +int TransformationFacade::generate(Target& target) { + StylesheetParameterGuard guard(this->transformer_); + + return this->generate(target, guard); +} + +template <typename Target> +int TransformationFacade::generate( + Target& target, + const StylesheetParameterGuard::map& parameters +) { + StylesheetParameterGuard guard(this->transformer_, parameters); + + return this->generate(target, guard); +} + +template <typename Target> +int TransformationFacade::generate( + Target& target, + const xalan::XObjectPtr& parameter +) { + StylesheetParameterGuard guard(this->transformer_); + guard.set("parameters", parameter); + + return this->generate(target, guard); +} + } #endif // INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_ |