From d19a195985b96701b2ab302538fe24e87e76decf Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sun, 18 May 2014 20:07:45 +0200 Subject: Added possibility for streaming TransformationFacade output * added "std::basic_ostream" taking "generate" member method overloads * marked cli parameter "target" as optional ** output is streamed to std::cout if target file is not provided --- src/transformation_facade.cc | 54 ++++++++++++++++++++------------------------ src/transformation_facade.h | 41 ++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 33 deletions(-) (limited to 'src') 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& 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(""); 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 + int generate(Target&); + + template + int generate(Target&, const StylesheetParameterGuard::map&); + + template + 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&, StylesheetParameterGuard&); + int generate(xalan::XSLTResultTarget&&, StylesheetParameterGuard&); }; +template +int TransformationFacade::generate(Target& target) { + StylesheetParameterGuard guard(this->transformer_); + + return this->generate(target, guard); +} + +template +int TransformationFacade::generate( + Target& target, + const StylesheetParameterGuard::map& parameters +) { + StylesheetParameterGuard guard(this->transformer_, parameters); + + return this->generate(target, guard); +} + +template +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_ -- cgit v1.2.3