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/support/error/error_multiplexer.cc | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/support/error/error_multiplexer.cc') diff --git a/src/support/error/error_multiplexer.cc b/src/support/error/error_multiplexer.cc index f5d4e0f..bbf0e71 100644 --- a/src/support/error/error_multiplexer.cc +++ b/src/support/error/error_multiplexer.cc @@ -27,15 +27,15 @@ inline std::string getMessage(const xercesc::SAXParseException& exception) { ); } -inline ErrorMultiplexer::ErrorType toErrorType( +inline ErrorMultiplexer::error_type toErrorType( const xalan::ProblemListenerBase::eClassification classification) { switch ( classification ) { case xalan::ProblemListenerBase::eClassification::eMessage || xalan::ProblemListenerBase::eClassification::eWarning: { - return ErrorMultiplexer::ErrorType::Warning; + return ErrorMultiplexer::error_type::warning; } default: { - return ErrorMultiplexer::ErrorType::Error; + return ErrorMultiplexer::error_type::error; } } } @@ -56,11 +56,11 @@ ErrorMultiplexer::~ErrorMultiplexer() { this->transformer_->setProblemListener(nullptr); } -void ErrorMultiplexer::connectReceiver(Receiver* receiver) { +void ErrorMultiplexer::connectReceiver(receiver* receiver) { this->receivers_.push_back(receiver); } -void ErrorMultiplexer::disconnectReceiver(Receiver* receiver) { +void ErrorMultiplexer::disconnectReceiver(receiver* receiver) { this->receivers_.erase( std::remove( this->receivers_.begin(), @@ -72,21 +72,21 @@ void ErrorMultiplexer::disconnectReceiver(Receiver* receiver) { void ErrorMultiplexer::warning(const xercesc::SAXParseException& exception) { this->multiplex( - ErrorType::Warning, + error_type::warning, "Warning: " + getMessage(exception) ); } void ErrorMultiplexer::error(const xercesc::SAXParseException& exception) { this->multiplex( - ErrorType::Error, + error_type::error, "Error: " + getMessage(exception) ); } void ErrorMultiplexer::fatalError(const xercesc::SAXParseException& exception) { this->multiplex( - ErrorType::Error, + error_type::error, "Fatal error: " + getMessage(exception) ); } @@ -155,16 +155,25 @@ void ErrorMultiplexer::problem( void ErrorMultiplexer::setPrintWriter(xalan::PrintWriter*) { } void ErrorMultiplexer::multiplex( - const ErrorType type, + const error_type type, const std::string& message ) { std::for_each( this->receivers_.begin(), this->receivers_.end(), - [&type, &message](Receiver* const receiver) -> void { + [&type, &message](receiver* const receiver) -> void { receiver->receive(type, message); } ); } +ErrorMultiplexer::receiver::receiver(ErrorMultiplexer* multiplexer): + multiplexer_(multiplexer) { + this->multiplexer_->connectReceiver(this); +} + +ErrorMultiplexer::receiver::~receiver() { + this->multiplexer_->disconnectReceiver(this); +} + } -- cgit v1.2.3