aboutsummaryrefslogtreecommitdiff
path: root/ixslt.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-06-06 22:00:39 +0200
committerAdrian Kummerländer2014-06-06 22:00:39 +0200
commit272b34c1a4639cd0f909bfb52d30339c93b0c42b (patch)
treed3bed13ddf28e86f8de319222daf535305082431 /ixslt.cc
parent78bb3387b15d15d766fb5d17a99612f0480f2bee (diff)
downloadInputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.gz
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.bz2
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.lz
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.xz
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.zst
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.zip
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
Diffstat (limited to 'ixslt.cc')
-rw-r--r--ixslt.cc68
1 files changed, 48 insertions, 20 deletions
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<boost::program_options::variables_map> input(
int argc,
@@ -57,6 +76,12 @@ boost::optional<boost::program_options::variables_map> 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<std::string> 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<std::string>(),
- plattform.getEntityResolver()
- );
-
- if ( variables.count("target") ) {
- transformation.generate(
- variables["target"].as<std::string>()
- );
- } else {
- transformation.generate(std::cout);
+ if ( auto transformation = InputXSLT::TransformationFacade::try_create(
+ variables["transformation"].as<std::string>(),
+ plattform.getEntityResolver(),
+ handleErrors
+ ) ) {
+ WarningGuard guard(transformation.get());
+
+ try {
+ if ( variables.count("target") ) {
+ transformation->generate(
+ variables["target"].as<std::string>()
+ );
+ } 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) {