From eb854e72efa780fd6ceb6e7457b6ac6429a54dad Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 10 May 2014 15:51:34 +0200 Subject: Implemented StylesheetParameterGuard class * removes responsibility for clearing parameters from the generate member methods * abstracts parameter escaping and setting and handles map conversion * marked actual generate member method as private and added StylesheetParameterGuard reference argument ** "frontend" generate member methods instantiate a StylesheetParameterGuard instance and pass it to the actual generate method ** this enables central default parameter definition while offering the possibility for custom parameters --- src/support/stylesheet_parameter_guard.cc | 36 +++++++++++++++++++++++++++++++ src/support/stylesheet_parameter_guard.h | 35 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/support/stylesheet_parameter_guard.cc create mode 100644 src/support/stylesheet_parameter_guard.h (limited to 'src/support') diff --git a/src/support/stylesheet_parameter_guard.cc b/src/support/stylesheet_parameter_guard.cc new file mode 100644 index 0000000..f82c2d5 --- /dev/null +++ b/src/support/stylesheet_parameter_guard.cc @@ -0,0 +1,36 @@ +#include "stylesheet_parameter_guard.h" + +namespace InputXSLT { + +StylesheetParameterGuard::StylesheetParameterGuard( + xalan::XalanTransformer& transformer +): transformer_(transformer) { } + +StylesheetParameterGuard::StylesheetParameterGuard( + xalan::XalanTransformer& transformer, + const map& parameters +): transformer_(transformer) { + this->set(parameters); +} + +StylesheetParameterGuard::~StylesheetParameterGuard() { + this->transformer_.clearStylesheetParams(); +} + +void StylesheetParameterGuard::set(const map& parameters) { + for ( auto&& parameter : parameters ) { + this->set(parameter.first, parameter.second); + } +} + +void StylesheetParameterGuard::set( + const std::string& key, + const std::string& value +) { + this->transformer_.setStylesheetParam( + key.data(), + std::string("'" + value + "'").data() + ); +} + +} diff --git a/src/support/stylesheet_parameter_guard.h b/src/support/stylesheet_parameter_guard.h new file mode 100644 index 0000000..f0622ad --- /dev/null +++ b/src/support/stylesheet_parameter_guard.h @@ -0,0 +1,35 @@ +#ifndef INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_ +#define INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_ + +#include + +#include +#include + +#include "common.h" + +namespace InputXSLT { + +class StylesheetParameterGuard { + public: + typedef std::unordered_map map; + + explicit StylesheetParameterGuard(xalan::XalanTransformer&); + StylesheetParameterGuard( + xalan::XalanTransformer&, + const map& + ); + + ~StylesheetParameterGuard(); + + void set(const map&); + void set(const std::string&, const std::string&); + + private: + xalan::XalanTransformer& transformer_; + +}; + +} + +#endif // INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_ -- cgit v1.2.3