mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
parameterised node_iter_t and chums
This commit is contained in:
parent
97e9414b73
commit
7c9492a63d
3 changed files with 88 additions and 79 deletions
|
@ -11,20 +11,29 @@ namespace Arabica
|
||||||
namespace XPath
|
namespace XPath
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef std::string::const_iterator str_iter_t;
|
template<class string_type>
|
||||||
|
class types
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename string_type::const_iterator str_iter_t;
|
||||||
|
typedef boost::spirit::tree_match<str_iter_t> tree_match_t;
|
||||||
|
typedef typename tree_match_t::tree_iterator node_iter_t;
|
||||||
|
typedef boost::spirit::tree_parse_info<str_iter_t> tree_info_t;
|
||||||
|
|
||||||
typedef boost::spirit::tree_match<str_iter_t> tree_match_t;
|
private:
|
||||||
typedef tree_match_t::tree_iterator node_iter_t;
|
~types();
|
||||||
typedef boost::spirit::tree_parse_info<str_iter_t> tree_info_t;
|
}; // types
|
||||||
|
|
||||||
inline long getNodeId(node_iter_t const& node)
|
template<class string_type>
|
||||||
|
long getNodeId(typename types<string_type>::node_iter_t const& node)
|
||||||
{
|
{
|
||||||
return static_cast<long>(node->value.id().to_long());
|
return static_cast<long>(node->value.id().to_long());
|
||||||
} // getNodeId
|
} // getNodeId
|
||||||
|
|
||||||
inline node_iter_t& skipWhitespace(node_iter_t& node)
|
template<class string_type>
|
||||||
|
typename types<string_type>::node_iter_t& skipWhitespace(typename types<string_type>::node_iter_t& node)
|
||||||
{
|
{
|
||||||
while(getNodeId(node) == impl::S_id)
|
while(getNodeId<string_type>(node) == impl::S_id)
|
||||||
++node;
|
++node;
|
||||||
return node;
|
return node;
|
||||||
} // skipWhitespace
|
} // skipWhitespace
|
||||||
|
|
|
@ -101,9 +101,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XPathExpressionPtr<string_type, string_adaptor> do_compile(const string_type& xpath,
|
XPathExpressionPtr<string_type, string_adaptor> do_compile(const string_type& xpath,
|
||||||
tree_info_t(XPath::*fn)(const string_type& str) const) const
|
typename types<string_type>::tree_info_t(XPath::*fn)(const string_type& str) const) const
|
||||||
{
|
{
|
||||||
tree_info_t ast;
|
types<string_type>::tree_info_t ast;
|
||||||
try {
|
try {
|
||||||
ast = (this->*fn)(xpath);
|
ast = (this->*fn)(xpath);
|
||||||
if(!ast.full)
|
if(!ast.full)
|
||||||
|
@ -122,15 +122,15 @@ private:
|
||||||
} // catch
|
} // catch
|
||||||
} // do_compile
|
} // do_compile
|
||||||
|
|
||||||
tree_info_t parse_xpath(const string_type& str) const
|
typename types<string_type>::tree_info_t parse_xpath(const string_type& str) const
|
||||||
{
|
{
|
||||||
str_iter_t first = str.begin(), last = str.end();
|
types<string_type>::str_iter_t first = str.begin(), last = str.end();
|
||||||
return ast_parse(first, last, xpathg_);
|
return ast_parse(first, last, xpathg_);
|
||||||
} // parse_xpath
|
} // parse_xpath
|
||||||
|
|
||||||
tree_info_t parse_xpath_expr(const string_type& str) const
|
typename types<string_type>::tree_info_t parse_xpath_expr(const string_type& str) const
|
||||||
{
|
{
|
||||||
str_iter_t first = str.begin(), last = str.end();
|
types<string_type>::str_iter_t first = str.begin(), last = str.end();
|
||||||
return ast_parse(first, last, xpathge_);
|
return ast_parse(first, last, xpathge_);
|
||||||
} // parse_xpath
|
} // parse_xpath
|
||||||
|
|
||||||
|
@ -143,10 +143,10 @@ private:
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
public:
|
public:
|
||||||
static XPathExpression<string_type, string_adaptor>* compile_expression(node_iter_t const& i,
|
static XPathExpression<string_type, string_adaptor>* compile_expression(typename types<string_type>::node_iter_t const& i,
|
||||||
CompilationContext<string_type, string_adaptor>& context)
|
CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
long id = getNodeId(i);
|
long id = getNodeId<string_type>(i);
|
||||||
|
|
||||||
if(XPath::factory().find(id) == XPath::factory().end())
|
if(XPath::factory().find(id) == XPath::factory().end())
|
||||||
{
|
{
|
||||||
|
@ -158,22 +158,22 @@ public:
|
||||||
} // compile_expression
|
} // compile_expression
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static XPathExpression<string_type, string_adaptor>* createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
|
static XPathExpression<string_type, string_adaptor>* createAbsoluteLocationPath(typename types<string_type>::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>* createRelativeLocationPath(typename types<string_type>::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>* createSingleStepRelativeLocationPath(typename types<string_type>::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>* createExpression(typename types<string_type>::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>* createFunction(typename types<string_type>::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>* createBinaryExpression(typename types<string_type>::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>* createLiteral(typename types<string_type>::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>* createNumber(typename types<string_type>::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>* createVariable(typename types<string_type>::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>* createSingleStepAbsoluteLocationPath(typename types<string_type>::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>* createUnaryExpression(typename types<string_type>::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 XPathExpression<string_type, string_adaptor>* createUnaryNegativeExpr(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
|
||||||
|
|
||||||
static StepList<string_type, string_adaptor> createStepList(node_iter_t const& from, node_iter_t const& to, CompilationContext<string_type, string_adaptor>& context);
|
static StepList<string_type, string_adaptor> createStepList(typename types<string_type>::node_iter_t const& from, typename types<string_type>::node_iter_t const& to, CompilationContext<string_type, string_adaptor>& context);
|
||||||
|
|
||||||
typedef XPathExpression<string_type, string_adaptor>* (*compileFn)(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
|
typedef XPathExpression<string_type, string_adaptor>* (*compileFn)(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context);
|
||||||
static std::map<int, compileFn>& factory()
|
static std::map<int, compileFn>& factory()
|
||||||
{
|
{
|
||||||
static std::map<int, compileFn> f = init_createFunctions();
|
static std::map<int, compileFn> f = init_createFunctions();
|
||||||
|
@ -235,7 +235,7 @@ private:
|
||||||
|
|
||||||
static const std::map<int, string_type> init_debugNames()
|
static const std::map<int, string_type> init_debugNames()
|
||||||
{
|
{
|
||||||
std::map<int, std::string> names;
|
std::map<int, string_type> names;
|
||||||
|
|
||||||
names[impl::LocationPath_id] = "LocationPath";
|
names[impl::LocationPath_id] = "LocationPath";
|
||||||
names[impl::AbsoluteLocationPath_id] = "AbsoluteLocationPath";
|
names[impl::AbsoluteLocationPath_id] = "AbsoluteLocationPath";
|
||||||
|
@ -331,7 +331,7 @@ private:
|
||||||
} // init_debugNames
|
} // init_debugNames
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static void dump(node_iter_t const& i, int depth)
|
static void dump(typename types<string_type>::node_iter_t const& i, int depth)
|
||||||
{
|
{
|
||||||
long id = static_cast<long>(i->value.id().to_long());
|
long id = static_cast<long>(i->value.id().to_long());
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ private:
|
||||||
std::cerr << ' ';
|
std::cerr << ' ';
|
||||||
std::cerr << names()[id] << " - " << std::string(i->value.begin(), i->value.end()) << std::endl;
|
std::cerr << names()[id] << " - " << std::string(i->value.begin(), i->value.end()) << std::endl;
|
||||||
|
|
||||||
for(node_iter_t c = i->children.begin(); c != i->children.end(); ++c)
|
for(typename types<string_type>::node_iter_t c = i->children.begin(); c != i->children.end(); ++c)
|
||||||
dump(c, depth+2);
|
dump(c, depth+2);
|
||||||
} // dump
|
} // dump
|
||||||
*/
|
*/
|
||||||
|
@ -371,50 +371,50 @@ namespace XPath
|
||||||
{
|
{
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
return new AbsoluteLocationPath<string_type, string_adaptor>(createStepList(i->children.begin(), i->children.end(), context));
|
return new AbsoluteLocationPath<string_type, string_adaptor>(createStepList(i->children.begin(), i->children.end(), context));
|
||||||
} // createAbsoluteLocationPath
|
} // createAbsoluteLocationPath
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
return new RelativeLocationPath<string_type, string_adaptor>(createStepList(i->children.begin(), i->children.end(), context));
|
return new RelativeLocationPath<string_type, string_adaptor>(createStepList(i->children.begin(), i->children.end(), context));
|
||||||
} // createRelativeLocationPath
|
} // createRelativeLocationPath
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
node_iter_t n = i;
|
typename types<string_type>::node_iter_t n = i;
|
||||||
return new RelativeLocationPath<string_type, string_adaptor>(StepFactory<string_type, string_adaptor>::createStep(n, context));
|
return new RelativeLocationPath<string_type, string_adaptor>(StepFactory<string_type, string_adaptor>::createStep(n, context));
|
||||||
} // createSingleStepRelativeLocationPath
|
} // createSingleStepRelativeLocationPath
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
node_iter_t c = i->children.begin();
|
typename types<string_type>::node_iter_t c = i->children.begin();
|
||||||
skipWhitespace(c);
|
skipWhitespace<string_type>(c);
|
||||||
return XPath<string_type, string_adaptor>::compile_expression(c, context);
|
return XPath<string_type, string_adaptor>::compile_expression(c, context);
|
||||||
} // createExpression
|
} // createExpression
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
node_iter_t c = i->children.begin();
|
typename types<string_type>::node_iter_t c = i->children.begin();
|
||||||
string_type name(c->value.begin(), c->value.end());
|
string_type name(c->value.begin(), c->value.end());
|
||||||
++c;
|
++c;
|
||||||
skipWhitespace(c);
|
skipWhitespace<string_type>(c);
|
||||||
assert(getNodeId(c) == impl::LeftBracket_id);
|
assert(getNodeId<string_type>(c) == impl::LeftBracket_id);
|
||||||
++c;
|
++c;
|
||||||
skipWhitespace(c);
|
skipWhitespace<string_type>(c);
|
||||||
|
|
||||||
std::vector<XPathExpressionPtr<string_type, string_adaptor> > args;
|
std::vector<XPathExpressionPtr<string_type, string_adaptor> > args;
|
||||||
while(getNodeId(c) != impl::RightBracket_id)
|
while(getNodeId<string_type>(c) != impl::RightBracket_id)
|
||||||
{
|
{
|
||||||
XPathExpressionPtr<string_type, string_adaptor> 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);
|
args.push_back(arg);
|
||||||
|
|
||||||
skipWhitespace(c);
|
skipWhitespace<string_type>(c);
|
||||||
} // while ...
|
} // while ...
|
||||||
// maybe trailing whitespace ...
|
// maybe trailing whitespace ...
|
||||||
|
|
||||||
|
@ -422,15 +422,15 @@ XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>
|
||||||
} // createFunction
|
} // createFunction
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
node_iter_t c = i->children.begin();
|
typename types<string_type>::node_iter_t c = i->children.begin();
|
||||||
XPathExpression<string_type, string_adaptor>* 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;
|
++c;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
long op = getNodeId(c);
|
long op = getNodeId<string_type>(c);
|
||||||
++c;
|
++c;
|
||||||
XPathExpression<string_type, string_adaptor>* 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);
|
||||||
|
|
||||||
|
@ -488,55 +488,55 @@ XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>
|
||||||
} // createBinaryExpression
|
} // createBinaryExpression
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
string_type str(i->value.begin(), i->value.end());
|
string_type str(i->value.begin(), i->value.end());
|
||||||
return new StringValue<string_type, string_adaptor>(str);
|
return new StringValue<string_type, string_adaptor>(str);
|
||||||
} // createLiteral
|
} // createLiteral
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::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())));
|
return new NumericValue<string_type, string_adaptor>(boost::lexical_cast<double>(string_type(i->value.begin(), i->value.end())));
|
||||||
} // createNumber
|
} // createNumber
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
return new Variable<string_type, string_adaptor>(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
|
} // createVariable
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
node_iter_t n = i;
|
typename types<string_type>::node_iter_t n = i;
|
||||||
return new AbsoluteLocationPath<string_type, string_adaptor>(StepFactory<string_type, string_adaptor>::createStep(n, context));
|
return new AbsoluteLocationPath<string_type, string_adaptor>(StepFactory<string_type, string_adaptor>::createStep(n, context));
|
||||||
} // createSingleStepAbsoluteLocationPath
|
} // createSingleStepAbsoluteLocationPath
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
return XPath<string_type, string_adaptor>::compile_expression(i->children.begin(), context);
|
return XPath<string_type, string_adaptor>::compile_expression(i->children.begin(), context);
|
||||||
} // createUnaryExpression
|
} // createUnaryExpression
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
XPathExpression<string_type, string_adaptor>* 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(typename types<string_type>::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));
|
return new UnaryNegative<string_type, string_adaptor>(XPath<string_type, string_adaptor>::compile_expression(i+1, context));
|
||||||
} // createUnaryNegativeExpr
|
} // createUnaryNegativeExpr
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
StepList<string_type, string_adaptor> XPath<string_type, string_adaptor>::createStepList(node_iter_t const& from,
|
StepList<string_type, string_adaptor> XPath<string_type, string_adaptor>::createStepList(typename types<string_type>::node_iter_t const& from,
|
||||||
node_iter_t const& to,
|
typename types<string_type>::node_iter_t const& to,
|
||||||
CompilationContext<string_type, string_adaptor>& context)
|
CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
StepList<string_type, string_adaptor> steps;
|
StepList<string_type, string_adaptor> steps;
|
||||||
|
|
||||||
node_iter_t c = from;
|
typename types<string_type>::node_iter_t c = from;
|
||||||
node_iter_t end = to;
|
typename types<string_type>::node_iter_t end = to;
|
||||||
|
|
||||||
while(c != end)
|
while(c != end)
|
||||||
switch(getNodeId(c))
|
switch(getNodeId<string_type>(c))
|
||||||
{
|
{
|
||||||
case impl::S_id:
|
case impl::S_id:
|
||||||
case impl::Slash_id:
|
case impl::Slash_id:
|
||||||
|
@ -549,7 +549,7 @@ StepList<string_type, string_adaptor> XPath<string_type, string_adaptor>::create
|
||||||
break;
|
break;
|
||||||
case impl::Step_id:
|
case impl::Step_id:
|
||||||
{
|
{
|
||||||
node_iter_t step = c->children.begin();
|
typename types<string_type>::node_iter_t step = c->children.begin();
|
||||||
steps.push_back(StepFactory<string_type, string_adaptor>::createStep(step, c->children.end(), context));
|
steps.push_back(StepFactory<string_type, string_adaptor>::createStep(step, c->children.end(), context));
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,8 +184,8 @@ class StepFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static StepExpression<string_type, string_adaptor>*
|
static StepExpression<string_type, string_adaptor>*
|
||||||
createStep(node_iter_t& node,
|
createStep(typename types<string_type>::node_iter_t& node,
|
||||||
node_iter_t const& end,
|
typename types<string_type>::node_iter_t const& end,
|
||||||
CompilationContext<string_type, string_adaptor>& context)
|
CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
Axis axis = getAxis(node);
|
Axis axis = getAxis(node);
|
||||||
|
@ -196,14 +196,14 @@ public:
|
||||||
|
|
||||||
std::vector<XPathExpression<string_type, string_adaptor>*> preds;
|
std::vector<XPathExpression<string_type, string_adaptor>*> preds;
|
||||||
|
|
||||||
while((node != end) && (getNodeId(node) == impl::Predicate_id))
|
while((node != end) && (getNodeId<string_type>(node) == impl::Predicate_id))
|
||||||
{
|
{
|
||||||
node_iter_t c = node->children.begin();
|
typename types<string_type>::node_iter_t c = node->children.begin();
|
||||||
assert(getNodeId(c) == impl::LeftSquare_id);
|
assert(getNodeId<string_type>(c) == impl::LeftSquare_id);
|
||||||
++c;
|
++c;
|
||||||
preds.push_back(XPath<string_type>::compile_expression(c, context));
|
preds.push_back(XPath<string_type>::compile_expression(c, context));
|
||||||
++c;
|
++c;
|
||||||
assert(getNodeId(c) == impl::RightSquare_id);
|
assert(getNodeId<string_type>(c) == impl::RightSquare_id);
|
||||||
|
|
||||||
++node;
|
++node;
|
||||||
} // if ...
|
} // if ...
|
||||||
|
@ -212,7 +212,7 @@ public:
|
||||||
return new TestStepExpression<string_type, string_adaptor>(axis, test, preds);
|
return new TestStepExpression<string_type, string_adaptor>(axis, test, preds);
|
||||||
} // createStep
|
} // createStep
|
||||||
|
|
||||||
static StepExpression<string_type, string_adaptor>* createStep(node_iter_t& node, CompilationContext<string_type, string_adaptor>& context)
|
static StepExpression<string_type, string_adaptor>* createStep(typename types<string_type>::node_iter_t& node, CompilationContext<string_type, string_adaptor>& context)
|
||||||
{
|
{
|
||||||
Axis axis = getAxis(node);
|
Axis axis = getAxis(node);
|
||||||
NodeTest<string_type>* test = getTest(node, context.namespaceContext());
|
NodeTest<string_type>* test = getTest(node, context.namespaceContext());
|
||||||
|
@ -220,9 +220,9 @@ public:
|
||||||
} // createStep
|
} // createStep
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Axis getAxis(node_iter_t& node)
|
static Axis getAxis(typename types<string_type>::node_iter_t& node)
|
||||||
{
|
{
|
||||||
long id = getNodeId(node);
|
long id = getNodeId<string_type>(node);
|
||||||
|
|
||||||
switch(id)
|
switch(id)
|
||||||
{
|
{
|
||||||
|
@ -246,8 +246,8 @@ private:
|
||||||
return CHILD;
|
return CHILD;
|
||||||
} // switch(id)
|
} // switch(id)
|
||||||
|
|
||||||
node_iter_t axis_node = node->children.begin();
|
typename types<string_type>::node_iter_t axis_node = node->children.begin();
|
||||||
long axis = getNodeId(skipWhitespace(axis_node));
|
long axis = getNodeId<string_type>(skipWhitespace<string_type>(axis_node));
|
||||||
++node;
|
++node;
|
||||||
switch(axis)
|
switch(axis)
|
||||||
{
|
{
|
||||||
|
@ -284,15 +284,15 @@ private:
|
||||||
return CHILD;
|
return CHILD;
|
||||||
} // getAxis
|
} // getAxis
|
||||||
|
|
||||||
static NodeTest<string_type>* getTest(node_iter_t& node, const NamespaceContext<string_type, string_adaptor>& namespaceContext)
|
static NodeTest<string_type>* getTest(typename types<string_type>::node_iter_t& node, const NamespaceContext<string_type, string_adaptor>& namespaceContext)
|
||||||
{
|
{
|
||||||
long id = getNodeId(skipWhitespace(node));
|
long id = getNodeId<string_type>(skipWhitespace<string_type>(node));
|
||||||
|
|
||||||
switch(id)
|
switch(id)
|
||||||
{
|
{
|
||||||
case impl::NodeTest_id:
|
case impl::NodeTest_id:
|
||||||
{
|
{
|
||||||
node_iter_t c = node->children.begin();
|
typename types<string_type>::node_iter_t c = node->children.begin();
|
||||||
NodeTest<string_type>* t = getTest(c, namespaceContext);
|
NodeTest<string_type>* t = getTest(c, namespaceContext);
|
||||||
++node;
|
++node;
|
||||||
return t;
|
return t;
|
||||||
|
@ -300,7 +300,7 @@ private:
|
||||||
|
|
||||||
case impl::QName_id:
|
case impl::QName_id:
|
||||||
{
|
{
|
||||||
node_iter_t c = node->children.begin();
|
typename types<string_type>::node_iter_t c = node->children.begin();
|
||||||
string_type prefix(c->value.begin(), c->value.end());
|
string_type prefix(c->value.begin(), c->value.end());
|
||||||
string_type uri = namespaceContext.namespaceURI(prefix);
|
string_type uri = namespaceContext.namespaceURI(prefix);
|
||||||
++c;
|
++c;
|
||||||
|
@ -331,7 +331,7 @@ private:
|
||||||
case impl::ProcessingInstruction_id:
|
case impl::ProcessingInstruction_id:
|
||||||
{
|
{
|
||||||
++node;
|
++node;
|
||||||
if(getNodeId(node) != impl::Literal_id) // not sure if this is always safe
|
if(getNodeId<string_type>(node) != impl::Literal_id) // not sure if this is always safe
|
||||||
return new ProcessingInstructionNodeTest<string_type>();
|
return new ProcessingInstructionNodeTest<string_type>();
|
||||||
|
|
||||||
string_type target(node->value.begin(), node->value.end());
|
string_type target(node->value.begin(), node->value.end());
|
||||||
|
@ -359,7 +359,7 @@ private:
|
||||||
|
|
||||||
case impl::NameTest_id:
|
case impl::NameTest_id:
|
||||||
{
|
{
|
||||||
node_iter_t prefixNode = node->children.begin();
|
typename types<string_type>::node_iter_t prefixNode = node->children.begin();
|
||||||
++node;
|
++node;
|
||||||
string_type prefix(prefixNode->value.begin(), prefixNode->value.end());
|
string_type prefix(prefixNode->value.begin(), prefixNode->value.end());
|
||||||
string_type uri = namespaceContext.namespaceURI(prefix);
|
string_type uri = namespaceContext.namespaceURI(prefix);
|
||||||
|
|
Loading…
Reference in a new issue