From 272b34c1a4639cd0f909bfb52d30339c93b0c42b Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Fri, 6 Jun 2014 22:00:39 +0200 Subject: Implemented WarningCapacitor as a counterpart to ErrorCapacitor * in difference to ErrorCapacitor this class doesn't throw an exception on "discharge" but returns the gathered warnings * adapted FunctionTransform and frontend error handling to include warnings * added static "try_create" method to TransformationFacade ** wraps construction error handling ** custom logic may be embedded using the std::function argument *** this was implemented to prevent unneccessary code duplication for handling both construction and generation errors * adapted FunctionTransform to return warning as "warning" nodes in the result tree ** added functional lambda expression factory method "handleErrors" *** returns a error handling lambda expression for a given ResultNodeFacade * implemented WarningGuard class in frontend executable ** guarantees warnings to be printed to std::cerr independent of any exceptions --- ixslt.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 20 deletions(-) (limited to 'ixslt.cc') diff --git a/ixslt.cc b/ixslt.cc index d65e5aa..86b883e 100644 --- a/ixslt.cc +++ b/ixslt.cc @@ -7,7 +7,26 @@ #include "plattform_guard.h" #include "transformation_facade.h" -#include "support/error/error_capacitor.h" + +class WarningGuard { + public: + WarningGuard(InputXSLT::TransformationFacade* transformation): + transformation_(transformation) { }; + + ~WarningGuard() { + InputXSLT::WarningCapacitor::warning_cache_ptr warnings( + this->transformation_->getCachedWarnings() + ); + + for ( auto&& warning : *warnings ) { + std::cerr << warning << std::endl; + } + }; + + private: + InputXSLT::TransformationFacade* const transformation_; + +}; boost::optional input( int argc, @@ -57,6 +76,12 @@ boost::optional input( return boost::make_optional(variables); } +void handleErrors(const InputXSLT::ErrorCapacitor::error_cache& errors) { + for ( auto&& error : errors ) { + std::cerr << error << std::endl; + } +} + bool process(const boost::program_options::variables_map& variables) { std::vector includePath; @@ -66,29 +91,32 @@ bool process(const boost::program_options::variables_map& variables) { InputXSLT::PlattformGuard plattform(includePath); - try { - InputXSLT::TransformationFacade transformation( - variables["transformation"].as(), - plattform.getEntityResolver() - ); - - if ( variables.count("target") ) { - transformation.generate( - variables["target"].as() - ); - } else { - transformation.generate(std::cout); + if ( auto transformation = InputXSLT::TransformationFacade::try_create( + variables["transformation"].as(), + plattform.getEntityResolver(), + handleErrors + ) ) { + WarningGuard guard(transformation.get()); + + try { + if ( variables.count("target") ) { + transformation->generate( + variables["target"].as() + ); + } else { + transformation->generate(std::cout); + } + + return true; } + catch (const InputXSLT::ErrorCapacitor::exception& exception) { + handleErrors(*exception); - return true; - } - catch (const InputXSLT::ErrorCapacitor::exception& exception) { - for ( auto&& error : *(exception.getCachedErrors()) ) { - std::cerr << error << std::endl; + return false; } - - return false; } + + return false; } int main(int argc, char** argv) { -- cgit v1.2.3