arabica/include/XSLT/impl/xslt_with_param.hpp

116 lines
3.2 KiB
C++
Raw Normal View History

2007-07-19 19:01:42 +02:00
#ifndef ARABICA_XSLT_WITH_PARAM_HPP
#define ARABICA_XSLT_WITH_PARAM_HPP
#include "xslt_variable_impl.hpp"
namespace Arabica
{
namespace XSLT
{
2012-11-06 09:11:27 +01:00
template<class stringT, class adaptorT>
2012-11-06 21:21:39 +01:00
class WithParam : public Variable_impl<stringT, adaptorT>
2007-07-19 19:01:42 +02:00
{
public:
2012-11-06 09:11:27 +01:00
typedef stringT string_type;
typedef adaptorT string_adaptor;
2012-11-04 23:34:40 +01:00
2012-11-06 09:11:27 +01:00
WithParam(const string_type& name,
const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& select,
const Precedence& precedence) :
2012-11-06 21:27:20 +01:00
Variable_impl<string_type, string_adaptor>(name, select, precedence)
2007-07-19 19:01:42 +02:00
{
} // WithParam
virtual ~WithParam() { }
2012-11-06 09:11:27 +01:00
virtual void execute(const DOM::Node<string_type, string_adaptor>& node,
2012-11-08 18:13:33 +01:00
ExecutionContext<string_type, string_adaptor>& context) const
2007-07-19 19:01:42 +02:00
{
name_ = context.passParam(node, *this);
2007-07-19 19:01:42 +02:00
} // declare
2012-11-08 18:13:33 +01:00
void unpass(ExecutionContext<string_type, string_adaptor>& context) const
{
context.unpassParam(name_);
} // unpass
private:
2012-11-06 09:11:27 +01:00
mutable string_type name_;
2007-07-19 19:01:42 +02:00
}; // WithParam
2012-11-06 09:14:07 +01:00
template<class string_type, class string_adaptor> class ParamPasser;
2012-11-06 09:11:27 +01:00
template<class string_type, class string_adaptor>
2007-07-19 19:01:42 +02:00
class WithParamable
{
protected:
WithParamable()
{
} // WithParamable
~WithParamable()
{
2012-11-06 09:11:27 +01:00
for(WithParamListIterator s = withparams_.begin(), e = withparams_.end(); s != e; ++s)
delete (*s);
2007-07-19 19:01:42 +02:00
} // ~WithParamable
public:
2012-11-06 09:11:27 +01:00
void add_with_param(WithParam<string_type, string_adaptor>* withparam)
{
withparams_.push_back(withparam);
} // add_WithParam
private:
2012-11-06 09:11:27 +01:00
void passParams(const DOM::Node<string_type, string_adaptor>& node,
2012-11-08 18:13:33 +01:00
ExecutionContext<string_type, string_adaptor>& context) const
2007-07-19 19:01:42 +02:00
{
2012-11-06 09:11:27 +01:00
for(WithParamListIterator s = withparams_.begin(), e = withparams_.end(); s != e; ++s)
(*s)->execute(node, context);
2007-07-19 19:01:42 +02:00
} // execute
2012-11-08 18:13:33 +01:00
void unpassParams(ExecutionContext<string_type, string_adaptor>& context) const
2007-07-19 19:01:42 +02:00
{
2012-11-06 09:11:27 +01:00
for(WithParamListIterator s = withparams_.begin(), e = withparams_.end(); s != e; ++s)
(*s)->unpass(context);
} // unpassParams
2007-07-19 19:01:42 +02:00
2012-11-06 09:11:27 +01:00
typedef std::vector<WithParam<string_type, string_adaptor>*> WithParamList;
typedef typename WithParamList::const_iterator WithParamListIterator;
WithParamList withparams_;
2007-07-19 19:01:42 +02:00
2012-11-06 09:14:07 +01:00
friend class ParamPasser<string_type, string_adaptor>;
2007-07-19 19:01:42 +02:00
}; // class WithParamable
2012-11-06 09:11:27 +01:00
template<class string_type, class string_adaptor>
class ParamPasser
{
public:
2012-11-06 09:11:27 +01:00
ParamPasser(const WithParamable<string_type, string_adaptor>& paramable,
const DOM::Node<string_type, string_adaptor>& node,
2012-11-08 18:13:33 +01:00
ExecutionContext<string_type, string_adaptor>& context) :
paramable_(paramable),
context_(context)
{
paramable_.passParams(node, context_);
} // ParamPasser
~ParamPasser()
{
paramable_.unpassParams(context_);
} // ~ParamPasser
private:
2012-11-06 09:11:27 +01:00
const WithParamable<string_type, string_adaptor>& paramable_;
2012-11-08 18:13:33 +01:00
ExecutionContext<string_type, string_adaptor>& context_;
ParamPasser(const ParamPasser&);
ParamPasser& operator=(const ParamPasser&);
bool operator==(const ParamPasser&) const;
}; // class ParamPasser
2007-07-19 19:01:42 +02:00
} // namespace XSLT
} // namespace Arabica
#endif