Debian Codegraph @

src/tinyxpath/xpath_processor.h

raw symbols SCIP
1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin ([email protected])
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any
7 damages arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any
10 purpose, including commercial applications, and to alter it and
11 redistribute it freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must
14 not claim that you wrote the original software. If you use this
15 software in a product, an acknowledgment in the product documentation
16 would be appreciated but is not required.
17
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24
25 /**
26 \file xpath_processor.h
27 \author Yves Berquin
28 */
29
30 #ifndef __XPATH_PROCESSOR_H
31 #define __XPATH_PROCESSOR_H
32
33 #define ACTION_STACK 1
34
35 #ifdef ACTION_STACK
36 #include "action_store.h"
37 #endif
38 #include "xpath_expression.h"
39 #include "xpath_stream.h"
40 #include "xpath_stack.h"
41
42 namespace TinyXPath
43 {
44
45 /// Exceptions
46 class execution_error {public : execution_error (int i_) {i=i_;} int i;};
47 class error_not_yet : public execution_error {public : error_not_yet () : execution_error (-2){}};
48
49 /// XPath execution class
50 class xpath_processor : public xpath_stream
51 {
52 public :
53 /// Constructor
54 xpath_processor (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr);
55 virtual ~ xpath_processor () {}
56 expression_result er_compute_xpath ();
57 TIXML_STRING S_compute_xpath ();
58 int i_compute_xpath ();
59 bool o_compute_xpath ();
60 double d_compute_xpath ();
61 unsigned u_compute_xpath_node_set ();
62 void v_get_xpath_base (unsigned u_order, const TiXmlBase * & XBp_res, bool & o_attribute);
63 TiXmlNode * XNp_get_xpath_node (unsigned u_order);
64 TiXmlAttribute * XAp_get_xpath_attribute (unsigned u_order);
65 enum {e_no_error, e_error_syntax, e_error_overflow, e_error_execution, e_error_stack} e_error;
66
67 protected :
68 virtual void v_action (xpath_construct , unsigned , unsigned , const char * );
69 virtual int i_get_action_counter ();
70
71 xpath_stack xs_stack;
72 action_store as_action_store;
73 void v_execute_stack ();
74 void v_pop_one_action (xpath_construct & xc_action, unsigned & u_sub, unsigned & u_ref, TIXML_STRING & S_literal);
75 void v_execute_one (xpath_construct xc_rule, bool o_skip_only);
76
77 void v_execute_absolute_path (unsigned u_action_position, bool o_with_rel, bool o_everywhere);
78 void v_execute_step (int & i_relative_action, bool o_skip_only);
79 bool o_check_predicate (const TiXmlElement * XEp_child, bool o_by_name);
80
81 void v_execute_function (TIXML_STRING & S_name, unsigned u_nb_arg, expression_result ** erpp_arg);
82 void v_function_ceiling (unsigned u_nb_arg, expression_result ** erpp_arg);
83 void v_function_concat (unsigned u_nb_arg, expression_result ** erpp_arg);
84 void v_function_contains (unsigned u_nb_arg, expression_result ** erpp_arg);
85 void v_function_count (unsigned u_nb_arg, expression_result ** erpp_arg);
86 void v_function_false (unsigned u_nb_arg, expression_result ** erpp_arg);
87 void v_function_floor (unsigned u_nb_arg, expression_result ** erpp_arg);
88 void v_function_last (unsigned u_nb_arg, expression_result ** erpp_arg);
89 void v_function_name (unsigned u_nb_arg, expression_result ** erpp_arg);
90 void v_function_normalize_space (unsigned u_nb_arg, expression_result ** erpp_arg);
91 void v_function_not (unsigned u_nb_arg, expression_result ** erpp_arg);
92 void v_function_position (unsigned u_nb_arg, expression_result ** erpp_arg);
93 void v_function_starts_with (unsigned u_nb_arg, expression_result ** erpp_arg);
94 void v_function_string_length (unsigned u_nb_arg, expression_result ** erpp_arg);
95 void v_function_substring (unsigned u_nb_arg, expression_result ** erpp_arg);
96 void v_function_sum (unsigned u_nb_arg, expression_result ** erpp_arg);
97 void v_function_text (unsigned u_nb_arg, expression_result ** erpp_arg);
98 void v_function_true (unsigned u_nb_arg, expression_result ** erpp_arg);
99
100 void v_function_equal (expression_result ** erpp_arg);
101 void v_function_not_equal (expression_result ** erpp_arg);
102 void v_function_equal_node_and_other (expression_result * erp_node, expression_result * erp_non);
103 void v_function_equal_2_node (expression_result * erp_node_set_, expression_result * erp_node_set_2);
104 void v_function_union (node_set & ns_1, node_set & ns_2);
105 void v_function_minus (expression_result ** erpp_arg);
106 void v_function_plus (expression_result ** erpp_arg);
107 void v_function_or (expression_result ** erpp_arg);
108 void v_function_and (expression_result ** erpp_arg);
109 void v_function_relational (expression_result ** erpp_arg, unsigned u_sub);
110 void v_function_opposite ();
111 void v_function_mult (expression_result ** erpp_arg, unsigned u_sub);
112
113 /// flag that says if the tree has been ordered already. This is a rather slow process,
114 /// so we only do it if needed
115 void v_order_tree ();
116 void v_order_recurs (TiXmlNode * Np_base, int & i_current);
117
118 void v_push_int (int i_val, const char * cp_comment = "") {xs_stack . v_push_int (i_val, cp_comment);}
119 void v_push_string (TIXML_STRING S_val) {xs_stack . v_push_string (S_val);}
120 void v_push_bool (bool o_val) {xs_stack . v_push_bool (o_val);}
121 void v_push_double (double d_val) {xs_stack . v_push_double (d_val);}
122 void v_push_node_set (node_set * nsp_val) {xs_stack . v_push_node_set (nsp_val);}
123
124 bool o_pop_bool () {return xs_stack . o_pop_bool ();}
125 int i_pop_int () {return xs_stack . i_pop_int ();}
126 TIXML_STRING S_pop_string () {return xs_stack . S_pop_string ();}
127 node_set ns_pop_node_set () {return xs_stack . ns_pop_node_set ();}
128
129 void v_set_context (const TiXmlElement * XEp_in, bool o_by_name);
130 const TiXmlElement * XEp_get_context () {return XEp_context;}
131 /// Root, above the XML tree given as parameter to the xpath_processor object
132 TiXmlElement * XEp_root;
133 /// Current context
134 const TiXmlElement * XEp_context;
135 /// The result of the XPath evaluation, for further node retrieving by v_get_xpath_base
136 expression_result er_result;
137 bool o_is_context_by_name;
138
139 const TiXmlNode * XNp_caller_parent;
140 const TiXmlNode * XNp_caller_prev;
141 const TiXmlNode * XNp_caller_next;
142 const TiXmlNode * XNp_base;
143
144 void v_build_root ();
145 void v_remove_root ();
146
147 } ;
148
149 }
150
151 #endif