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 --- src/transformation_facade.cc | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/transformation_facade.cc') diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 6d7b7a3..3c94bdd 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -7,17 +7,33 @@ #include -#include "support/error/error_capacitor.h" - namespace InputXSLT { +auto TransformationFacade::try_create( + const std::string& transformation, + IncludeEntityResolver* resolver, + const std::function& handleErrors +) -> ptr{ + try { + return ptr( + new InputXSLT::TransformationFacade(transformation, resolver) + ); + } + catch (const ErrorCapacitor::exception& exception) { + handleErrors(*exception); + + return ptr(); + } +} + TransformationFacade::TransformationFacade( const std::string& transformation, IncludeEntityResolver* resolver ): transformation_{}, transformer_(), - error_multiplexer_(&transformer_) { + error_multiplexer_(&transformer_), + warning_capacitor_(&error_multiplexer_) { this->transformer_.setEntityResolver(resolver); ErrorCapacitor errorCapacitor(&this->error_multiplexer_); @@ -36,6 +52,10 @@ TransformationFacade::~TransformationFacade() { ); } +WarningCapacitor::warning_cache_ptr TransformationFacade::getCachedWarnings() { + return this->warning_capacitor_.discharge(); +} + void TransformationFacade::generate( const std::string& targetPath, StylesheetParameterGuard& parameters -- cgit v1.2.3