aboutsummaryrefslogtreecommitdiff
path: root/src/support/error_handler.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-29 13:26:37 +0200
committerAdrian Kummerländer2014-05-29 13:26:37 +0200
commit3bc793d95293d40dbab62c593ce4ceaa86fae25b (patch)
tree07a0f99d72a074a75955a593318cc8bcd394f4c2 /src/support/error_handler.cc
parent52b60c1a8c23f11ab18fad06e0957490c7436e0a (diff)
downloadInputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.tar
InputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.tar.gz
InputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.tar.bz2
InputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.tar.lz
InputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.tar.xz
InputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.tar.zst
InputXSLT-3bc793d95293d40dbab62c593ce4ceaa86fae25b.zip
Improved TransformationFacade error handling
* ErrorHandler class created in 5859cb6 now caches all errors instead of pushing them to std::cerr ** cached errors are retrieved by TransformationFacade's "generate" member method * test frontend pushes all errors to std::cerr * FunctionTransform returns errors to the calling template as XML ** FunctionTransform test case demonstrates how one may test for successful transformation * "generate" member method returns std::string vector wrapped in a std::unique_ptr ** this is used as a kind of optional pointer, as the std::unique_ptr instance only wraps a vector if errors where actually generated
Diffstat (limited to 'src/support/error_handler.cc')
-rw-r--r--src/support/error_handler.cc63
1 files changed, 40 insertions, 23 deletions
diff --git a/src/support/error_handler.cc b/src/support/error_handler.cc
index 9a898a6..db54225 100644
--- a/src/support/error_handler.cc
+++ b/src/support/error_handler.cc
@@ -6,38 +6,55 @@
#include "support/xerces_string_guard.h"
+namespace {
+
+inline std::string getMessage(const xercesc::SAXParseException& exception) {
+ return std::string(
+ *InputXSLT::XercesStringGuard<char>(exception.getMessage())
+ );
+}
+
+}
+
namespace InputXSLT {
-ErrorHandler::ErrorHandler(const std::string& transformation):
- transformation_path_(transformation) { }
+ErrorHandler::ErrorHandler():
+ error_cache_{} { }
+
+void ErrorHandler::warning(const xercesc::SAXParseException& exception) {
+ this->constructErrorCache();
-void ErrorHandler::warning(const xercesc::SAXParseException& e) {
- std::cerr << "Warning in "
- << "'"
- << this->transformation_path_
- << "': "
- << *XercesStringGuard<char>(e.getMessage())
- << std::endl;
+ this->error_cache_->emplace_back(
+ "Warning: " + getMessage(exception)
+ );
}
-void ErrorHandler::error(const xercesc::SAXParseException& e) {
- std::cerr << "Error in "
- << "'"
- << this->transformation_path_
- << "': "
- << *XercesStringGuard<char>(e.getMessage())
- << std::endl;
+void ErrorHandler::error(const xercesc::SAXParseException& exception) {
+ this->constructErrorCache();
+
+ this->error_cache_->emplace_back(
+ "Error: " + getMessage(exception)
+ );
}
-void ErrorHandler::fatalError(const xercesc::SAXParseException& e) {
- std::cerr << "Fatal error in "
- << "'"
- << this->transformation_path_
- << "': "
- << *XercesStringGuard<char>(e.getMessage())
- << std::endl;
+void ErrorHandler::fatalError(const xercesc::SAXParseException& exception) {
+ this->constructErrorCache();
+
+ this->error_cache_->emplace_back(
+ "Fatal error: " + getMessage(exception)
+ );
}
void ErrorHandler::resetErrors() { }
+auto ErrorHandler::getCachedErrors() -> error_cache_ptr {
+ return error_cache_ptr(this->error_cache_.release());
+}
+
+void ErrorHandler::constructErrorCache() {
+ if ( !this->error_cache_ ) {
+ this->error_cache_.reset(new error_cache());
+ }
+}
+
}