Parameterised ExecutionContext

as a result had to add string_adaptor parameter to XPathExpression,
XPathVariable, UnionExpresion and various other classes
This commit is contained in:
jez_higgins 2005-08-17 10:13:05 +00:00
parent ff2b3f6551
commit 9ae5ba9c6f
13 changed files with 265 additions and 233 deletions

View file

@ -9,90 +9,96 @@ namespace XPath
{
template<class string_type, class string_adaptor>
class PlusOperator : private BinaryExpression<string_type>, public XPathExpression<string_type>
class PlusOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type> baseT;
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
PlusOperator(XPathExpression<string_type>* lhs, XPathExpression<string_type>* rhs) :
BinaryExpression<string_type>(lhs, rhs) { }
PlusOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) + baseT::rhs()->evaluateAsNumber(context));
} // evaluate
}; // class PlusOperator
template<class string_type, class string_adaptor>
class MinusOperator : private BinaryExpression<string_type>, public XPathExpression<string_type>
class MinusOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type> baseT;
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
MinusOperator(XPathExpression<string_type>* lhs, XPathExpression<string_type>* rhs) :
BinaryExpression<string_type>(lhs, rhs) { }
MinusOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) - baseT::rhs()->evaluateAsNumber(context));
} // evaluate
}; // class MinusOperator
template<class string_type, class string_adaptor>
class MultiplyOperator : private BinaryExpression<string_type>, public XPathExpression<string_type>
class MultiplyOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type> baseT;
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
MultiplyOperator(XPathExpression<string_type>* lhs, XPathExpression<string_type>* rhs) :
BinaryExpression<string_type>(lhs, rhs) { }
MultiplyOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) * baseT::rhs()->evaluateAsNumber(context));
} // evaluate
}; // class MultiplyOperator
template<class string_type, class string_adaptor>
class DivideOperator : private BinaryExpression<string_type>, public XPathExpression<string_type>
class DivideOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type> baseT;
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
DivideOperator(XPathExpression<string_type>* lhs, XPathExpression<string_type>* rhs) :
BinaryExpression<string_type>(lhs, rhs) { }
DivideOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) / baseT::rhs()->evaluateAsNumber(context));
} // evaluate
}; // class DivideOperator
template<class string_type, class string_adaptor>
class ModOperator : private BinaryExpression<string_type>, public XPathExpression<string_type>
class ModOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type> baseT;
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
ModOperator(XPathExpression<string_type>* lhs, XPathExpression<string_type>* rhs) :
BinaryExpression<string_type>(lhs, rhs) { }
ModOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(static_cast<long>(baseT::lhs()->evaluateAsNumber(context)) % static_cast<long>(baseT::rhs()->evaluateAsNumber(context)));
} // evaluate
}; // class ModOperator
template<class string_type, class string_adaptor>
class UnaryNegative : private UnaryExpression<string_type>, public XPathExpression<string_type>
class UnaryNegative : private UnaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef UnaryExpression<string_type> baseT;
typedef UnaryExpression<string_type, string_adaptor> baseT;
public:
UnaryNegative(XPathExpression<string_type>* expr) :
UnaryExpression<string_type>(expr) { }
UnaryNegative(XPathExpression<string_type, string_adaptor>* expr) :
UnaryExpression<string_type, string_adaptor>(expr) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(-baseT::expr()->evaluate(context, executionContext)->asNumber());
} // evaluate

View file

@ -9,7 +9,8 @@ namespace Arabica
{
namespace XPath
{
template<class string_type, class string_adaptor>
class ExecutionContext
{
public:
@ -31,14 +32,14 @@ public:
void setPosition(unsigned int pos) { position_ = pos; }
const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >& variableResolver() const { return variableResolver_.get(); }
void setVariableResolver(const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >& resolver) { variableResolver_.set(resolver); }
void setVariableResolver(VariableResolverPtr<std::string, Arabica::default_string_adaptor<std::string> >& resolver) { variableResolver_.set(resolver); }
const VariableResolver<string_type, string_adaptor>& variableResolver() const { return variableResolver_.get(); }
void setVariableResolver(const VariableResolver<string_type, string_adaptor>& resolver) { variableResolver_.set(resolver); }
void setVariableResolver(VariableResolverPtr<string_type,string_adaptor>& resolver) { variableResolver_.set(resolver); }
private:
size_t position_;
size_t last_;
ResolverHolder<const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> > > variableResolver_;
ResolverHolder<const VariableResolver<string_type, string_adaptor> > variableResolver_;
ExecutionContext(const ExecutionContext&);
ExecutionContext& operator=(const ExecutionContext&);

View file

@ -11,7 +11,7 @@ namespace Arabica
namespace XPath
{
template<class string_type>
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class XPathExpression
{
protected:
@ -22,7 +22,7 @@ public:
XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context) const
{
ExecutionContext executionContext;
ExecutionContext<string_type, string_adaptor> executionContext;
return evaluate(context, executionContext);
} // evaluate
@ -32,7 +32,7 @@ public:
virtual NodeSet<string_type> evaluateAsNodeSet(const DOM::Node<string_type>& context) const { return evaluate(context)->asNodeSet(); }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const = 0;
const ExecutionContext<string_type, string_adaptor>& executionContext) const = 0;
private:
XPathExpression(const XPathExpression&);
@ -40,18 +40,21 @@ private:
XPathExpression& operator=(const XPathExpression&);
}; // class XPathExpression
template<class string_type>
class XPathExpressionPtr : public boost::shared_ptr<XPathExpression<string_type> >
template<class string_type, class string_adaptor>
class XPathExpressionPtr : public boost::shared_ptr<XPathExpression<string_type, string_adaptor> >
{
public:
explicit XPathExpressionPtr(XPathExpression<string_type>* xp) : boost::shared_ptr<XPathExpression<string_type> >(xp) { }
};
explicit XPathExpressionPtr(XPathExpression<string_type, string_adaptor>* xp) :
boost::shared_ptr<XPathExpression<string_type,string_adaptor> >(xp)
{
} // XPathExpressionPtr
}; // class XPathExpressionPtr
template<class string_type>
template<class string_type, class string_adaptor>
class UnaryExpression
{
public:
UnaryExpression(XPathExpression<string_type>* expr) :
UnaryExpression(XPathExpression<string_type, string_adaptor>* expr) :
expr_(expr) { }
protected:
@ -60,20 +63,20 @@ protected:
delete expr_;
} // ~UnaryExpression
XPathExpression<string_type>* expr() const { return expr_; }
XPathExpression<string_type, string_adaptor>* expr() const { return expr_; }
private:
XPathExpression<string_type>* expr_;
XPathExpression<string_type, string_adaptor>* expr_;
}; // class UnaryExpression
template<class string_type>
template<class string_type, class string_adaptor>
class BinaryExpression
{
public:
BinaryExpression(XPathExpression<string_type>* lhs,
XPathExpression<string_type>* rhs) :
BinaryExpression(XPathExpression<string_type, string_adaptor>* lhs,
XPathExpression<string_type, string_adaptor>* rhs) :
lhs_(lhs),
rhs_(rhs)
rhs_(rhs)
{
} // BinaryExpression
@ -84,12 +87,12 @@ protected:
delete rhs_;
} // ~BinaryExpression
XPathExpression<string_type>* lhs() const { return lhs_; }
XPathExpression<string_type>* rhs() const { return rhs_; }
XPathExpression<string_type, string_adaptor>* lhs() const { return lhs_; }
XPathExpression<string_type, string_adaptor>* rhs() const { return rhs_; }
private:
XPathExpression<string_type>* lhs_;
XPathExpression<string_type>* rhs_;
XPathExpression<string_type, string_adaptor>* lhs_;
XPathExpression<string_type, string_adaptor>* rhs_;
}; // class BinaryExpression
} // namespace XPath

View file

@ -16,7 +16,7 @@ namespace XPath
class XPathFunction
{
protected:
XPathFunction(int minArgs, int maxArgs, const std::vector<XPathExpressionPtr<std::string> >& args) :
XPathFunction(int minArgs, int maxArgs, const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) :
args_(args)
{
if(((minArgs != -1) && (static_cast<int>(args.size()) < minArgs)) ||
@ -28,41 +28,41 @@ public:
virtual ~XPathFunction() { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const = 0;
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const = 0;
protected:
size_t argCount() const { return args_.size(); }
bool argAsBool(size_t index,
const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return args_[index]->evaluate(context, executionContext)->asBool();
} // argAsBool
double argAsNumber(size_t index,
const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return args_[index]->evaluate(context, executionContext)->asNumber();
} // argAsNumber
std::string argAsString(size_t index,
const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return args_[index]->evaluate(context, executionContext)->asString();
} // argAsString
NodeSet<std::string> argAsNodeSet(size_t index,
const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return args_[index]->evaluate(context, executionContext)->asNodeSet();
} // argAsNodeSet
private:
const std::vector<XPathExpressionPtr<std::string> > args_;
const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > > args_;
}; // class XPathFunction
////////////////////////////////
@ -71,10 +71,10 @@ private:
class LastFn : public XPathFunction
{
public:
LastFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 0, args) { }
LastFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 0, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(executionContext.last());
} // evaluate
@ -84,10 +84,10 @@ public:
class PositionFn : public XPathFunction
{
public:
PositionFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 0, args) { }
PositionFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 0, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(executionContext.position());
} // evaluate
@ -97,10 +97,10 @@ public:
class CountFn : public XPathFunction
{
public:
CountFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
CountFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(argAsNodeSet(0, context, executionContext).size());
} // evaluate
@ -111,10 +111,10 @@ public:
class LocalNameFn : public XPathFunction
{
public:
LocalNameFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
LocalNameFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
DOM::Node<std::string> node;
if(argCount() == 0)
@ -144,10 +144,10 @@ public:
class NamespaceURIFn : public XPathFunction
{
public:
NamespaceURIFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
NamespaceURIFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
DOM::Node<std::string> node;
if(argCount() == 0)
@ -176,10 +176,10 @@ public:
class NameFn : public XPathFunction
{
public:
NameFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
NameFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
DOM::Node<std::string> node;
if(argCount() == 0)
@ -212,10 +212,10 @@ public:
class StringFn : public XPathFunction
{
public:
StringFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
StringFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new StringValue<std::string, Arabica::default_string_adaptor<std::string> >((argCount() > 0) ? argAsString(0, context, executionContext) : nodeStringValue(context));
} // evaluate
@ -225,10 +225,10 @@ public:
class ConcatFn : public XPathFunction
{
public:
ConcatFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(2, -1, args) { }
ConcatFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(2, -1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string s;
for(size_t a = 0, ae = argCount(); a < ae; ++a)
@ -241,10 +241,10 @@ public:
class StartsWithFn : public XPathFunction
{
public:
StartsWithFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(2, 2, args) { }
StartsWithFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(2, 2, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string value = argAsString(0, context, executionContext);
std::string start = argAsString(1, context, executionContext);
@ -264,10 +264,10 @@ public:
class ContainsFn : public XPathFunction
{
public:
ContainsFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(2, 2, args) { }
ContainsFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(2, 2, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new BoolValue<std::string, Arabica::default_string_adaptor<std::string> >(argAsString(0, context, executionContext).find(argAsString(1, context, executionContext)) != std::string::npos);
} // evaluate
@ -277,10 +277,10 @@ public:
class SubstringBeforeFn : public XPathFunction
{
public:
SubstringBeforeFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(2, 2, args) { }
SubstringBeforeFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(2, 2, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string value = argAsString(0, context, executionContext);
size_t splitAt = value.find(argAsString(1, context, executionContext));
@ -296,10 +296,10 @@ public:
class SubstringAfterFn : public XPathFunction
{
public:
SubstringAfterFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(2, 2, args) { }
SubstringAfterFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(2, 2, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string value = argAsString(0, context, executionContext);
std::string split = argAsString(1, context, executionContext);
@ -316,10 +316,10 @@ public:
class SubstringFn : public XPathFunction
{
public:
SubstringFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(2, 3, args) { }
SubstringFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(2, 3, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string value = argAsString(0, context, executionContext);
double startAt = roundNumber(argAsNumber(1, context, executionContext)) - 1;
@ -341,10 +341,10 @@ public:
class StringLengthFn : public XPathFunction
{
public:
StringLengthFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
StringLengthFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(((argCount() > 0) ? argAsString(0, context, executionContext) : nodeStringValue(context)).length());
} // evaluate
@ -354,10 +354,10 @@ public:
class NormalizeSpaceFn : public XPathFunction
{
public:
NormalizeSpaceFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
NormalizeSpaceFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string value = ((argCount() > 0) ? argAsString(0, context, executionContext) : nodeStringValue(context));
size_t i = 0, ie = value.length();
@ -387,10 +387,10 @@ public:
class TranslateFn : public XPathFunction
{
public:
TranslateFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(3, 3, args) { }
TranslateFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(3, 3, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
std::string str = argAsString(0, context, executionContext);
std::string from = argAsString(1, context, executionContext);
@ -419,10 +419,10 @@ public:
class BooleanFn : public XPathFunction
{
public:
BooleanFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
BooleanFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new BoolValue<std::string, Arabica::default_string_adaptor<std::string> >(argAsBool(0, context, executionContext));
} // evaluate
@ -432,10 +432,10 @@ public:
class NotFn : public XPathFunction
{
public:
NotFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
NotFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new BoolValue<std::string, Arabica::default_string_adaptor<std::string> >(!argAsBool(0, context, executionContext));
}
@ -445,10 +445,10 @@ public:
class TrueFn : public XPathFunction
{
public:
TrueFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 0, args) { }
TrueFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 0, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new BoolValue<std::string, Arabica::default_string_adaptor<std::string> >(true);
} // evaluate
@ -458,10 +458,10 @@ public:
class FalseFn : public XPathFunction
{
public:
FalseFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 0, args) { }
FalseFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 0, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new BoolValue<std::string, Arabica::default_string_adaptor<std::string> >(false);
} // evaluate
@ -476,10 +476,10 @@ public:
class NumberFn : public XPathFunction
{
public:
NumberFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(0, 1, args) { }
NumberFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(0, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
double result = (argCount() > 0) ? argAsNumber(0, context, executionContext) :
StringValue<std::string, Arabica::default_string_adaptor<std::string> >(nodeStringValue(context)).asNumber();
@ -491,10 +491,10 @@ public:
class SumFn : public XPathFunction
{
public:
SumFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
SumFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
double sum = 0;
NodeSet<std::string> ns = argAsNodeSet(0, context, executionContext);
@ -508,10 +508,10 @@ public:
class FloorFn : public XPathFunction
{
public:
FloorFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
FloorFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(std::floor(argAsNumber(0, context, executionContext)));
} // evaluate
@ -521,10 +521,10 @@ public:
class CeilingFn : public XPathFunction
{
public:
CeilingFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
CeilingFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(std::ceil(argAsNumber(0, context, executionContext)));
} // evaluate
@ -534,10 +534,10 @@ public:
class RoundFn : public XPathFunction
{
public:
RoundFn(const std::vector<XPathExpressionPtr<std::string> >& args) : XPathFunction(1, 1, args) { }
RoundFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& args) : XPathFunction(1, 1, args) { }
virtual XPathValue<std::string>* evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return new NumericValue<std::string, Arabica::default_string_adaptor<std::string> >(roundNumber(argAsNumber(0, context, executionContext)));
} // evaluate

View file

@ -11,9 +11,9 @@ namespace XPath
{
template<class function_type>
XPathFunction* CreateFn(const std::vector<XPathExpressionPtr<std::string> >& argExprs) { return new function_type(argExprs); }
XPathFunction* CreateFn(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& argExprs) { return new function_type(argExprs); }
typedef XPathFunction* (*CreateFnPtr)(const std::vector<XPathExpressionPtr<std::string> >& argExprs);
typedef XPathFunction* (*CreateFnPtr)(const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& argExprs);
struct NamedFunction { const char* name; CreateFnPtr creator; };
@ -49,7 +49,7 @@ const NamedFunction FunctionLookupTable[] = { // node-set functions
{0, 0}
};
class FunctionHolder : public XPathExpression<std::string>
class FunctionHolder : public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
FunctionHolder(XPathFunction* func) :
@ -63,13 +63,13 @@ public:
} // ~FunctionHolder
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return XPathValuePtr<std::string>(func_->evaluate(context, executionContext));
} // evaluate
static FunctionHolder* createFunction(const std::string& name,
const std::vector<XPathExpressionPtr<std::string> >& argExprs,
const std::vector<XPathExpressionPtr<std::string, Arabica::default_string_adaptor<std::string> > >& argExprs,
const CompilationContext<std::string, Arabica::default_string_adaptor<std::string> >& context)
{
for(const NamedFunction* fn = FunctionLookupTable; fn->name != 0; ++fn)

View file

@ -7,7 +7,7 @@ namespace XPath
{
class XPathFunction;
template<class string_type> class XPathExpressionPtr;
template<class string_type, class string_adaptor> class XPathExpressionPtr;
class UndefinedFunctionException : public std::runtime_error
{
@ -23,7 +23,7 @@ public:
// TODO: should make this a QName
virtual XPathFunction* resolveFunction(const string_type& name,
const std::vector<XPathExpressionPtr<string_type> >& argExprs) const = 0;
const std::vector<XPathExpressionPtr<string_type, string_adaptor> >& argExprs) const = 0;
}; // class FunctionResolver
template<class string_type, class string_adaptor>
@ -41,7 +41,7 @@ class NullFunctionResolver : public FunctionResolver<string_type, string_adaptor
{
public:
virtual XPathFunction* resolveFunction(const string_type& name,
const std::vector<XPathExpressionPtr<string_type> >& argExprs) const
const std::vector<XPathExpressionPtr<string_type, string_adaptor> >& argExprs) const
{
throw UndefinedFunctionException(string_adaptor().asStdString(name));
} // resolveVariable

View file

@ -8,14 +8,16 @@ namespace Arabica
namespace XPath
{
class OrOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class OrOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
OrOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
OrOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
// From XPath 1.0 Rec, section 3.4
// An or expression is evaluated by evaluating each operand and converting its value
@ -28,14 +30,16 @@ public:
} // evaluate
}; // class OrOperator
class AndOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class AndOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
AndOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
AndOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
// From XPath 1.0 Rec, section 3.4
// An and expression is evaluated by evaluating each operand and converting its value

View file

@ -58,26 +58,26 @@ public:
{
} // ~XPath
XPathExpressionPtr<string_type> compile(const string_type& xpath) const
XPathExpressionPtr<string_type, string_adaptor> compile(const string_type& xpath) const
{
return do_compile(xpath, &XPath::parse_xpath);
} // compile
XPathExpressionPtr<string_type> compile_expr(const string_type& xpath) const
XPathExpressionPtr<string_type, string_adaptor> compile_expr(const string_type& xpath) const
{
return do_compile(xpath, &XPath::parse_xpath_expr);
} // compile
XPathValuePtr<string_type> evaluate(const string_type& xpath, const DOM::Node<string_type>& context) const
{
ExecutionContext executionContext;
ExecutionContext<string_type, string_adaptor> executionContext;
executionContext.setVariableResolver(getVariableResolver());
return compile(xpath)->evaluate(context, executionContext);
} // evaluate
XPathValuePtr<string_type> evaluate_expr(const string_type& xpath, const DOM::Node<string_type>& context) const
{
ExecutionContext executionContext;
ExecutionContext<string_type, string_adaptor> executionContext;
executionContext.setVariableResolver(getVariableResolver());
return compile_expr(xpath)->evaluate(context, executionContext);
} // evaluate_expr
@ -98,8 +98,8 @@ public:
void resetFunctionResolver() { functionResolver_.set(FunctionResolverPtr<string_type, string_adaptor>(new NullFunctionResolver<string_type, string_adaptor>())); }
private:
XPathExpressionPtr<string_type> do_compile(const string_type& xpath,
tree_info_t(XPath::*fn)(const string_type& str) const) const
XPathExpressionPtr<string_type, string_adaptor> do_compile(const string_type& xpath,
tree_info_t(XPath::*fn)(const string_type& str) const) const
{
tree_info_t ast;
try {
@ -108,7 +108,7 @@ private:
throw SyntaxException(xpath);
CompilationContext<string_type, string_adaptor> context(*this, getNamespaceContext(), getFunctionResolver());
return XPathExpressionPtr<std::string>(compile_expression(ast.trees.begin(), context));
return XPathExpressionPtr<string_type, string_adaptor>(compile_expression(ast.trees.begin(), context));
} // try
catch(std::exception& ex)
{
@ -141,7 +141,7 @@ private:
/////////////////////////////////////////////////////////////////////////////////
public:
static XPathExpression<string_type>* compile_expression(node_iter_t const& i,
static XPathExpression<string_type, string_adaptor>* compile_expression(node_iter_t const& i,
CompilationContext<string_type, string_adaptor>& context)
{
long id = getNodeId(i);
@ -156,22 +156,22 @@ public:
} // compile_expression
private:
static XPathExpression<string_type>* createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createFunction(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createBinaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createLiteral(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createNumber(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createVariable(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createUnaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type>* createUnaryNegativeExpr(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createFunction(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createBinaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createLiteral(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createNumber(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createVariable(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createUnaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static XPathExpression<string_type, string_adaptor>* createUnaryNegativeExpr(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static StepList createStepList(node_iter_t const& from, node_iter_t const& to, CompilationContext<string_type, string_adaptor>& context);
typedef XPathExpression<string_type>* (*compileFn)(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
typedef XPathExpression<string_type, string_adaptor>* (*compileFn)(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
static std::map<int, compileFn>& factory()
{
static std::map<int, compileFn> f = init_createFunctions();
@ -367,26 +367,26 @@ namespace XPath
{
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
return new AbsoluteLocationPath(createStepList(i->children.begin(), i->children.end(), context));
} // createAbsoluteLocationPath
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
return new RelativeLocationPath(createStepList(i->children.begin(), i->children.end(), context));
} // createRelativeLocationPath
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
node_iter_t n = i;
return new RelativeLocationPath(StepFactory::createStep(n, context));
} // createSingleStepRelativeLocationPath
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
node_iter_t c = i->children.begin();
skipWhitespace(c);
@ -394,7 +394,7 @@ XPathExpression<string_type>* XPath<string_type, string_adaptor>::createExpressi
} // createExpression
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createFunction(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createFunction(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
node_iter_t c = i->children.begin();
string_type name(c->value.begin(), c->value.end());
@ -404,10 +404,10 @@ XPathExpression<string_type>* XPath<string_type, string_adaptor>::createFunction
++c;
skipWhitespace(c);
std::vector<XPathExpressionPtr<string_type> > args;
std::vector<XPathExpressionPtr<string_type, string_adaptor> > args;
while(getNodeId(c) != impl::RightBracket_id)
{
XPathExpressionPtr<string_type> arg(XPath<string_type, string_adaptor>::compile_expression(c++, context));
XPathExpressionPtr<string_type, string_adaptor> arg(XPath<string_type, string_adaptor>::compile_expression(c++, context));
args.push_back(arg);
skipWhitespace(c);
@ -418,17 +418,17 @@ XPathExpression<string_type>* XPath<string_type, string_adaptor>::createFunction
} // createFunction
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createBinaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createBinaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
node_iter_t c = i->children.begin();
XPathExpression<string_type>* p1 = XPath<string_type, string_adaptor>::compile_expression(c, context);
XPathExpression<string_type, string_adaptor>* p1 = XPath<string_type, string_adaptor>::compile_expression(c, context);
++c;
do
{
long op = getNodeId(c);
++c;
XPathExpression<string_type>* p2 = XPath<string_type, string_adaptor>::compile_expression(c, context);
XPathExpression<string_type, string_adaptor>* p2 = XPath<string_type, string_adaptor>::compile_expression(c, context);
switch(op)
{
@ -472,7 +472,7 @@ XPathExpression<string_type>* XPath<string_type, string_adaptor>::createBinaryEx
p1 = new AndOperator(p1, p2);
break;
case impl::UnionOperator_id:
p1 = new UnionExpression<string_type>(p1, p2);
p1 = new UnionExpression<string_type, string_adaptor>(p1, p2);
break;
default:
throw UnsupportedException(boost::lexical_cast<string_type>(op));
@ -484,39 +484,39 @@ XPathExpression<string_type>* XPath<string_type, string_adaptor>::createBinaryEx
} // createBinaryExpression
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createLiteral(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createLiteral(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
string_type str(i->value.begin(), i->value.end());
return new StringValue<string_type, string_adaptor>(str);
} // createLiteral
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createNumber(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createNumber(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
return new NumericValue<string_type, string_adaptor>(boost::lexical_cast<double>(string_type(i->value.begin(), i->value.end())));
} // createNumber
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createVariable(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createVariable(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
return new Variable<string_type>(string_type(i->value.begin()+1, i->value.end())); // skip $
return new Variable<string_type, string_adaptor>(string_type(i->value.begin()+1, i->value.end())); // skip $
} // createVariable
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
node_iter_t n = i;
return new AbsoluteLocationPath(StepFactory::createStep(n, context));
} // createSingleStepAbsoluteLocationPath
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createUnaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createUnaryExpression(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
return XPath<string_type, string_adaptor>::compile_expression(i->children.begin(), context);
} // createUnaryExpression
template<class string_type, class string_adaptor>
XPathExpression<string_type>* XPath<string_type, string_adaptor>::createUnaryNegativeExpr(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createUnaryNegativeExpr(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{
return new UnaryNegative<string_type, string_adaptor>(XPath<string_type, string_adaptor>::compile_expression(i+1, context));
} // createUnaryNegativeExpr

View file

@ -8,84 +8,96 @@ namespace Arabica
namespace XPath
{
class EqualsOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class EqualsOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
EqualsOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
EqualsOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return BoolValue<std::string, Arabica::default_string_adaptor<std::string> >::createValue(areEqual(lhs()->evaluate(context, executionContext),
rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class EqualsOperator
class NotEqualsOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class NotEqualsOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
NotEqualsOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
NotEqualsOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return BoolValue<std::string, Arabica::default_string_adaptor<std::string> >::createValue(!areEqual(lhs()->evaluate(context, executionContext),
rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class NotEqualsOperator
class LessThanOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class LessThanOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
LessThanOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
LessThanOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return BoolValue<std::string, Arabica::default_string_adaptor<std::string> >::createValue(isLessThan(lhs()->evaluate(context, executionContext),
rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class LessThanOperator
class LessThanEqualsOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class LessThanEqualsOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
LessThanEqualsOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
LessThanEqualsOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return BoolValue<std::string, Arabica::default_string_adaptor<std::string> >::createValue(isLessThanEquals(lhs()->evaluate(context, executionContext),
rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class LessThanEqualsOperator
class GreaterThanOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class GreaterThanOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
GreaterThanOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
GreaterThanOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return BoolValue<std::string, Arabica::default_string_adaptor<std::string> >::createValue(isGreaterThan(lhs()->evaluate(context, executionContext),
rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class GreaterThanOperator
class GreaterThanEqualsOperator : private BinaryExpression<std::string>, public XPathExpression<std::string>
class GreaterThanEqualsOperator : private BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >,
public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
GreaterThanEqualsOperator(XPathExpression<std::string>* lhs, XPathExpression<std::string>* rhs) :
BinaryExpression<std::string>(lhs, rhs) { }
GreaterThanEqualsOperator(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* lhs,
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* rhs) :
BinaryExpression<std::string, Arabica::default_string_adaptor<std::string> >(lhs, rhs) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
return BoolValue<std::string, Arabica::default_string_adaptor<std::string> >::createValue(isGreaterThanEquals(lhs()->evaluate(context, executionContext),
rhs()->evaluate(context, executionContext)));

View file

@ -17,27 +17,27 @@ namespace Arabica
namespace XPath
{
class StepExpression : public XPathExpression<std::string>
class StepExpression : public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
StepExpression() { }
StepExpression(const std::vector<XPathExpression<std::string> *>& predicates) : predicates_(predicates) { }
StepExpression(const std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> > *>& predicates) : predicates_(predicates) { }
virtual ~StepExpression()
{
for(std::vector<XPathExpression<std::string>*>::iterator p = predicates_.begin(), e = predicates_.end(); p != e; ++p)
for(std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >*>::iterator p = predicates_.begin(), e = predicates_.end(); p != e; ++p)
delete *p;
} // ~StepExpression
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext& executionContext) const = 0;
virtual XPathValuePtr<std::string> evaluate(NodeSet<std::string>& context, const ExecutionContext& executionContext) const = 0;
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const = 0;
virtual XPathValuePtr<std::string> evaluate(NodeSet<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const = 0;
bool has_predicates() const { return !predicates_.empty(); }
protected:
NodeSet<std::string> applyPredicates(NodeSet<std::string>& nodes, const ExecutionContext& parentContext) const
NodeSet<std::string> applyPredicates(NodeSet<std::string>& nodes, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& parentContext) const
{
for(std::vector<XPathExpression<std::string>*>::const_iterator p = predicates_.begin(), e = predicates_.end();
for(std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >*>::const_iterator p = predicates_.begin(), e = predicates_.end();
(p != e) && (!nodes.empty()); ++p)
nodes = applyPredicate(nodes, *p, parentContext);
return nodes;
@ -45,10 +45,10 @@ protected:
private:
NodeSet<std::string> applyPredicate(NodeSet<std::string>& nodes,
XPathExpression<std::string>* predicate,
const ExecutionContext& parentContext) const
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* predicate,
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& parentContext) const
{
ExecutionContext executionContext(nodes.size(), parentContext);
ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> > executionContext(nodes.size(), parentContext);
NodeSet<std::string> results(nodes.forward());
unsigned int position = 1;
for(NodeSet<std::string>::iterator i = nodes.begin(); i != nodes.end(); ++i, ++position)
@ -66,7 +66,7 @@ private:
return results;
} // applyPredicate
std::vector<XPathExpression<std::string>*> predicates_;
std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >*> predicates_;
}; // StepExpression
class TestStepExpression : public StepExpression
@ -80,7 +80,7 @@ public:
} // TestStepExpression
TestStepExpression(Axis axis, NodeTest* test,
const std::vector<XPathExpression<std::string>*>& predicates) :
const std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >*>& predicates) :
StepExpression(predicates),
axis_(axis),
test_(test)
@ -92,14 +92,14 @@ public:
delete test_;
} // StepExpression
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
NodeSet<std::string> nodes;
enumerateOver(context, nodes, executionContext);
return XPathValuePtr<std::string>(new NodeSetValue<std::string, Arabica::default_string_adaptor<std::string> >(nodes));
} // evaluate
virtual XPathValuePtr<std::string> evaluate(NodeSet<std::string>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<std::string> evaluate(NodeSet<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
NodeSet<std::string> nodes;
for(NodeSet<std::string>::iterator n = context.begin(); n != context.end(); ++n)
@ -110,7 +110,7 @@ public:
private:
void enumerateOver(const DOM::Node<std::string>& context,
NodeSet<std::string>& results,
const ExecutionContext& parentContext) const
const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& parentContext) const
{
AxisEnumerator enumerator(context, axis_);
NodeSet<std::string> intermediate(enumerator.forward());
@ -142,8 +142,8 @@ private:
class ExprStepExpression : public StepExpression
{
public:
ExprStepExpression(XPathExpression<std::string>* expr,
const std::vector<XPathExpression<std::string>*>& predicates) :
ExprStepExpression(XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* expr,
const std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >*>& predicates) :
StepExpression(predicates),
expr_(expr)
{
@ -154,7 +154,7 @@ public:
delete expr_;
} // ExprStepExpression
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
if(!has_predicates())
return expr_->evaluate(context, executionContext);
@ -163,14 +163,14 @@ public:
return XPathValuePtr<std::string>(new NodeSetValue<std::string, Arabica::default_string_adaptor<std::string> >(applyPredicates(ns, executionContext)));
} // evaluate
virtual XPathValuePtr<std::string> evaluate(NodeSet<std::string>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<std::string> evaluate(NodeSet<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
DOM::Node<std::string> c = context.top();
return evaluate(c, executionContext);
} // evaluate
private:
XPathExpression<std::string>* expr_;
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* expr_;
std::vector<XPathExpression*> predicates_;
}; // class ExprStepExpression
@ -183,11 +183,11 @@ public:
{
Axis axis = getAxis(node);
NodeTest* test = getTest(node, context.namespaceContext());
XPathExpression<std::string>* thing = 0;
XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >* thing = 0;
if(!test)
thing = XPath<std::string>::compile_expression(node++, context);
std::vector<XPathExpression<std::string>*> preds;
std::vector<XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >*> preds;
while((node != end) && (getNodeId(node) == impl::Predicate_id))
{
@ -366,7 +366,7 @@ private:
StepFactory();
}; // class StepFactory
class RelativeLocationPath : public XPathExpression<std::string>
class RelativeLocationPath : public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> >
{
public:
RelativeLocationPath(StepExpression* step) : steps_() { steps_.push_back(step); }
@ -378,7 +378,7 @@ public:
delete *i;
} // ~LocationPath
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
NodeSet<std::string> nodes;
nodes.push_back(context);
@ -402,7 +402,7 @@ public:
AbsoluteLocationPath(StepExpression* step) : RelativeLocationPath(step) { }
AbsoluteLocationPath(const StepList& steps) : RelativeLocationPath(steps) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const
{
int type = context.getNodeType();
if((type == DOM::Node<std::string>::DOCUMENT_NODE) ||

View file

@ -9,16 +9,18 @@ namespace Arabica
namespace XPath
{
template<class string_type>
class UnionExpression : private BinaryExpression<string_type>, public XPathExpression<string_type>
template<class string_type, class string_adaptor>
class UnionExpression : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type> baseT;
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
UnionExpression(XPathExpression<string_type>* lhs, XPathExpression<string_type>* rhs) :
BinaryExpression<string_type>(lhs, rhs) { }
UnionExpression(XPathExpression<string_type, string_adaptor>* lhs,
XPathExpression<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
XPathValuePtr<string_type> p1 = baseT::lhs()->evaluate(context, executionContext);
if(p1->type() != NODE_SET)
@ -67,7 +69,7 @@ public:
private:
XPathValuePtr<string_type> wrap(const NodeSet<string_type>& ns) const
{
return XPathValuePtr<string_type>(new NodeSetValue<std::string, Arabica::default_string_adaptor<std::string> >(ns));
return XPathValuePtr<string_type>(new NodeSetValue<string_type, string_adaptor>(ns));
} // wrap
}; // UnionExpression

View file

@ -15,7 +15,7 @@ namespace XPath
{
template<class string_type, class string_adaptor>
class BoolValue : public XPathValue<string_type>, public XPathExpression<string_type>
class BoolValue : public XPathValue<string_type>, public XPathExpression<string_type, string_adaptor>
{
public:
BoolValue(bool value) :
@ -23,7 +23,8 @@ public:
static XPathValuePtr<string_type> createValue(bool value) { return XPathValuePtr<string_type>(new BoolValue(value)); }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return XPathValuePtr<string_type>(new BoolValue(value_));
} // evaluate
@ -44,7 +45,7 @@ private:
}; // class BoolValue
template<class string_type, class string_adaptor>
class NumericValue : public XPathValue<string_type>, public XPathExpression<string_type>
class NumericValue : public XPathValue<string_type>, public XPathExpression<string_type, string_adaptor>
{
public:
NumericValue(double value) :
@ -52,7 +53,8 @@ public:
static XPathValuePtr<string_type> createValue(double value) { return XPathValuePtr<string_type>(new NumericValue(value)); }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return createValue(value_);
} // evaluate
@ -82,7 +84,7 @@ private:
}; // class NumberValue
template<class string_type, class string_adaptor>
class StringValue : public XPathValue<string_type>, public XPathExpression<string_type>
class StringValue : public XPathValue<string_type>, public XPathExpression<string_type, string_adaptor>
{
public:
StringValue(const char* value) :
@ -90,7 +92,8 @@ public:
StringValue(const string_type& value) :
value_(value) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return XPathValuePtr<string_type>(new StringValue(value_));
} // evaluate
@ -114,12 +117,13 @@ private:
}; // class StringValue
template<class string_type, class string_adaptor>
class NodeSetValue : public XPathValue<string_type>, public XPathExpression<string_type>
class NodeSetValue : public XPathValue<string_type>, public XPathExpression<string_type, string_adaptor>
{
public:
NodeSetValue(const NodeSet<string_type>& set) : set_(set) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context, const ExecutionContext& executionContext) const
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return XPathValuePtr<string_type>(this);
} // evaluate

View file

@ -10,14 +10,14 @@ namespace Arabica
namespace XPath
{
template<class string_type>
class Variable : public XPathExpression<string_type>
template<class string_type, class string_adaptor>
class Variable : public XPathExpression<string_type, string_adaptor>
{
public:
Variable(const string_type& name) : name_(name) { }
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
const ExecutionContext& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return executionContext.variableResolver().resolveVariable(name_);
} // evaluate