forked from parsley72/tinyxpath2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpath_processor.h
174 lines (151 loc) · 6.58 KB
/
xpath_processor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
www.sourceforge.net/projects/tinyxpath
Copyright (c) 2002-2004 Yves Berquin ([email protected])
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/**
\file xpath_processor.h
\author Yves Berquin
*/
/*
@history:
Modified on 18 December 2006 by Aman Aggarwal
::Added support for translate()
*/
#ifndef __XPATH_PROCESSOR_H
#define __XPATH_PROCESSOR_H
#include "action_store.h"
#include "xpath_expression.h"
#include "xpath_stack.h"
#include "xpath_stream.h"
namespace TinyXPath {
/// Exceptions
class execution_error {
public:
execution_error(int i) {
_i = i;
}
int _i;
};
class error_not_yet : public execution_error {
public:
error_not_yet() : execution_error(-2) {
}
};
/// XPath execution class
class xpath_processor : public xpath_stream {
public:
/// Constructor
xpath_processor(const tinyxml2::XMLNode* XNp_source_tree, const char* cp_xpath_expr);
virtual ~xpath_processor() = default;
expression_result er_compute_xpath();
std::string S_compute_xpath();
int i_compute_xpath();
bool o_compute_xpath();
double d_compute_xpath();
unsigned u_compute_xpath_node_set();
const tinyxml2::XMLNode* XNp_get_xpath_node(unsigned u_order);
const tinyxml2::XMLAttribute* XAp_get_xpath_attribute(unsigned u_order);
enum { e_no_error, e_error_syntax, e_error_overflow, e_error_execution, e_error_stack } _e_error;
protected:
void v_action(xpath_construct, xpath_sub, lex, const char*) override;
int i_get_action_counter() override;
xpath_stack _xs_stack;
action_store _as_action_store;
void v_execute_stack();
void v_pop_one_action(xpath_construct& xc_action, xpath_sub& xp_sub, unsigned& u_ref, std::string& S_literal);
void v_execute_one(xpath_construct xc_rule, bool o_skip_only);
void v_execute_absolute_path(unsigned u_action_position, bool o_with_rel, bool o_everywhere);
void v_execute_step(int& i_relative_action, bool o_skip_only);
bool o_check_predicate(const tinyxml2::XMLElement* XEp_child, bool o_by_name);
void v_execute_function(std::string& S_name, unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_ceiling(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_concat(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_contains(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_count(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_false(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_floor(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_last(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_name(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_normalize_space(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_not(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_position(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_starts_with(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_string_length(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_substring(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_sum(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_text(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_translate(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_true(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_string(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_number(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_boolean(unsigned u_nb_arg, expression_result** erpp_arg);
void v_function_equal(expression_result** erpp_arg);
void v_function_not_equal(expression_result** erpp_arg);
void v_function_equal_node_and_other(expression_result* erp_node, expression_result* erp_non);
void v_function_equal_2_node(expression_result* erp_node_set_, expression_result* erp_node_set_2);
void v_function_union(node_set& ns_1, node_set& ns_2);
void v_function_minus(expression_result** erpp_arg);
void v_function_plus(expression_result** erpp_arg);
void v_function_or(expression_result** erpp_arg);
void v_function_and(expression_result** erpp_arg);
void v_function_relational(expression_result** erpp_arg, xpath_sub xp_sub);
void v_function_opposite();
void v_function_mult(expression_result** erpp_arg, xpath_sub xp_sub);
void v_push_int(int i_val, const char* cp_comment = "") {
_xs_stack.v_push_int(i_val, cp_comment);
}
void v_push_string(std::string S_val) {
_xs_stack.v_push_string(S_val);
}
void v_push_bool(bool o_val) {
_xs_stack.v_push_bool(o_val);
}
void v_push_double(double d_val) {
_xs_stack.v_push_double(d_val);
}
void v_push_node_set(node_set* nsp_val) {
_xs_stack.v_push_node_set(nsp_val);
}
bool o_pop_bool() {
return _xs_stack.o_pop_bool();
}
int i_pop_int() {
return _xs_stack.i_pop_int();
}
std::string S_pop_string() {
return _xs_stack.S_pop_string();
}
node_set ns_pop_node_set() {
return _xs_stack.ns_pop_node_set();
}
void v_set_context(const tinyxml2::XMLElement* XEp_in, bool o_by_name);
const tinyxml2::XMLElement* XEp_get_context() {
return _XEp_context;
}
/// Current context
const tinyxml2::XMLElement* _XEp_context;
/// The result of the XPath evaluation, for further node retrieving by v_get_xpath_base
expression_result _er_result;
bool _o_is_context_by_name;
/// Base node
const tinyxml2::XMLNode* _XNp_base;
/// Node above the caller:
const tinyxml2::XMLNode* _XNp_base_parent;
void v_build_root();
};
} // namespace TinyXPath
#endif // __XPATH_PROCESSOR_H