1
2
3
4
5
6 #include <sngxml/xpath/XPathEvaluate.hpp>
7 #include <sngxml/xpath/XPathContext.hpp>
8 #include <sngxml/xpath/XPathParser.hpp>
9 #include <sngxml/xpath/XPathLexer.hpp>
10 #include <sngxml/xpath/XPathDebug.hpp>
11 #include <sngxml/dom/Document.hpp>
12 #include <soulng/lexer/XmlParsingLog.hpp>
13 #include <iostream>
14 #include <chrono>
15
16 namespace sngxml { namespace xpath {
17
18 std::std::unique_ptr<XPathObject>Evaluate(conststd::u32string&xpathExpression, sngxml::dom::Node*node)
19 {
20 soulng::lexer::XmlParsingLog debugLog(std::cerr);
21 std::chrono::time_point<std::chrono::steady_clock> startQuery = std::chrono::steady_clock::now();
22 XPathLexer xpathLexer(xpathExpression, "", 0);
23 if (XPathDebugParsing())
24 {
25 xpathLexer.SetLog(&debugLog);
26 }
27 std::unique_ptr<XPathExpr> xpathExpr(XPathParser::Parse(xpathLexer));
28 std::chrono::time_point<std::chrono::steady_clock> endQuery = std::chrono::steady_clock::now();
29 if (XPathDebugQuery())
30 {
31 std::unique_ptr<dom::Node> queryDom = xpathExpr->ToDom();
32 SetXPathQueryDom(std::move(queryDom));
33 SetXPathQueryDuration(std::chrono::nanoseconds(endQuery - startQuery));
34 }
35 std::chrono::time_point<std::chrono::steady_clock> startEvaluate = std::chrono::steady_clock::now();
36 XPathContext context(node, 1, 1);
37 std::unique_ptr<XPathObject> result = xpathExpr->Evaluate(context);
38 std::chrono::time_point<std::chrono::steady_clock> endEvaluate = std::chrono::steady_clock::now();
39 if (XPathDebugQuery())
40 {
41 SetXPathExecuteDuration(endEvaluate - startEvaluate);
42 }
43 return result;
44 }
45
46 std::std::unique_ptr<XPathObject>Evaluate(conststd::u32string&xpathExpression, sngxml::dom::Document*document)
47 {
48 return Evaluate(xpathExpression, static_cast<sngxml::dom::Node*>(document));
49 }
50
51 } }