ddc
xpath_processor.h
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)
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 
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 
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 
51 {
52 public :
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 
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 (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 
115  void v_order_tree ();
116  void v_order_recurs (TiXmlNode * Np_base, /*int*/ size_t & 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 (TiXmlElement * XEp_in, bool o_by_name);
130  const TiXmlElement * XEp_get_context () {return XEp_context;}
138 
143 
144  void v_build_root ();
145  void v_remove_root ();
146 
147 } ;
148 
149 }
150 
151 #endif
152 
153 /*--- emacs style variables ---
154  * Local Variables:
155  * mode: C++
156  * c-file-style: "ellemtel"
157  * c-basic-offset: 4
158  * tab-width: 8
159  * indent-tabs-mode: nil
160  * End:
161  */
bool o_is_context_by_name
Definition: xpath_processor.h:137
Definition: xpath_processor.h:47
Definition: tinyxml.h:640
const TiXmlNode * XNp_caller_prev
Definition: xpath_processor.h:140
Definition: xpath_stack.h:44
int i_pop_int()
Definition: xpath_processor.h:125
xpath_construct
XPath constructions. The ordinals are rules of XPath or XML definitions in w3c.
Definition: lex_util.h:78
Definition: action_store.h:68
Definition: xpath_stream.h:51
void v_push_double(double d_val)
Definition: xpath_processor.h:121
Definition: action_store.cpp:32
XPath execution class.
Definition: xpath_processor.h:50
error_not_yet()
Definition: xpath_processor.h:47
Class holding the result of an expression (e_expression_type)
Definition: xpath_expression.h:45
const TiXmlNode * XNp_caller_parent
Definition: xpath_processor.h:139
Exceptions.
Definition: xpath_processor.h:46
void v_push_string(TiXmlString S_val)
Definition: xpath_processor.h:119
const TiXmlElement * XEp_context
Current context.
Definition: xpath_processor.h:134
int i
Definition: xpath_processor.h:46
virtual ~ xpath_processor()
Definition: xpath_processor.h:55
void v_push_int(int i_val, const char *cp_comment="")
Definition: xpath_processor.h:118
expression_result er_result
The result of the XPath evaluation, for further node retrieving by v_get_xpath_base.
Definition: xpath_processor.h:136
action_store as_action_store
Definition: xpath_processor.h:72
node_set ns_pop_node_set()
Definition: xpath_processor.h:127
const TiXmlNode * XNp_base
Definition: xpath_processor.h:142
void v_push_bool(bool o_val)
Definition: xpath_processor.h:120
xpath_stack xs_stack
Definition: xpath_processor.h:71
bool o_pop_bool()
Definition: xpath_processor.h:124
Definition: xpath_processor.h:65
Node set class. A node set is an unordered collection of node.
Definition: node_set.h:34
Definition: tinyxml.h:138
Definition: tinyxml.h:363
const TiXmlElement * XEp_get_context()
Definition: xpath_processor.h:130
TiXmlElement * XEp_root
Root, above the XML tree given as parameter to the xpath_processor object.
Definition: xpath_processor.h:132
execution_error(int i_)
Definition: xpath_processor.h:46
const TiXmlNode * XNp_caller_next
Definition: xpath_processor.h:141
TiXmlString S_pop_string()
Definition: xpath_processor.h:126
#define TIXML_STRING
Definition: tinyxml.h:67
Definition: tinyxml.h:779
void v_push_node_set(node_set *nsp_val)
Definition: xpath_processor.h:122