Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

xpath_processor.h

Go to the documentation of this file.
00001 /*
00002 www.sourceforge.net/projects/tinyxpath
00003 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)
00004 
00005 This software is provided 'as-is', without any express or implied
00006 warranty. In no event will the authors be held liable for any
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to anyone to use this software for any
00010 purpose, including commercial applications, and to alter it and
00011 redistribute it freely, subject to the following restrictions:
00012 
00013 1. The origin of this software must not be misrepresented; you must
00014 not claim that you wrote the original software. If you use this
00015 software in a product, an acknowledgment in the product documentation
00016 would be appreciated but is not required.
00017 
00018 2. Altered source versions must be plainly marked as such, and
00019 must not be misrepresented as being the original software.
00020 
00021 3. This notice may not be removed or altered from any source
00022 distribution.
00023 */
00024 
00030 #ifndef __XPATH_PROCESSOR_H
00031 #define __XPATH_PROCESSOR_H
00032 
00033 #define ACTION_STACK 1
00034 
00035 #ifdef ACTION_STACK
00036    #include "action_store.h"
00037 #endif
00038 #include "xpath_expression.h"
00039 #include "xpath_stream.h"
00040 #include "xpath_stack.h"
00041 
00042 namespace TinyXPath
00043 {
00044 
00046 class execution_error {public : execution_error (int i_) {i=i_;} int i;};
00047 class error_not_yet : public execution_error {public : error_not_yet () : execution_error (-2){}};
00048 
00050 class xpath_processor : public xpath_stream
00051 {
00052 public :
00054    xpath_processor (const TiXmlNode * XNp_source_tree, const char * cp_xpath_expr);
00055    virtual ~ xpath_processor () {}
00056    expression_result er_compute_xpath ();
00057    TIXML_STRING S_compute_xpath ();
00058    int i_compute_xpath ();
00059    bool o_compute_xpath ();
00060    double d_compute_xpath ();
00061    unsigned u_compute_xpath_node_set ();
00062    void v_get_xpath_base (unsigned u_order, const TiXmlBase * & XBp_res, bool & o_attribute);
00063    TiXmlNode * XNp_get_xpath_node (unsigned u_order);
00064    TiXmlAttribute * XAp_get_xpath_attribute (unsigned u_order);
00065    enum {e_no_error, e_error_syntax, e_error_overflow, e_error_execution, e_error_stack} e_error;
00066 
00067 protected :
00068    virtual void v_action (xpath_construct , unsigned , unsigned , const char * );
00069    virtual int i_get_action_counter ();
00070 
00071    xpath_stack xs_stack;
00072    action_store as_action_store;
00073    void v_execute_stack ();
00074    void v_pop_one_action (xpath_construct & xc_action, unsigned & u_sub, unsigned & u_ref, TIXML_STRING & S_literal);
00075    void v_execute_one (xpath_construct xc_rule, bool o_skip_only);
00076 
00077    void v_execute_absolute_path (unsigned u_action_position, bool o_with_rel, bool o_everywhere);
00078    void v_execute_step (int & i_relative_action, bool o_skip_only);
00079    bool o_check_predicate (const TiXmlElement * XEp_child, bool o_by_name);
00080 
00081    void v_execute_function (TIXML_STRING & S_name, unsigned u_nb_arg, expression_result ** erpp_arg);
00082    void v_function_ceiling (unsigned u_nb_arg, expression_result ** erpp_arg);
00083    void v_function_concat (unsigned u_nb_arg, expression_result ** erpp_arg);
00084    void v_function_contains (unsigned u_nb_arg, expression_result ** erpp_arg);
00085    void v_function_count (unsigned u_nb_arg, expression_result ** erpp_arg);
00086    void v_function_false (unsigned u_nb_arg, expression_result ** erpp_arg);
00087    void v_function_floor (unsigned u_nb_arg, expression_result ** erpp_arg);
00088    void v_function_last (unsigned u_nb_arg, expression_result ** erpp_arg);
00089    void v_function_name (unsigned u_nb_arg, expression_result ** erpp_arg);
00090    void v_function_normalize_space (unsigned u_nb_arg, expression_result ** erpp_arg);
00091    void v_function_not (unsigned u_nb_arg, expression_result ** erpp_arg);
00092    void v_function_position (unsigned u_nb_arg, expression_result ** erpp_arg);
00093    void v_function_starts_with (unsigned u_nb_arg, expression_result ** erpp_arg);
00094    void v_function_string_length (unsigned u_nb_arg, expression_result ** erpp_arg);
00095    void v_function_substring (unsigned u_nb_arg, expression_result ** erpp_arg);
00096    void v_function_sum (unsigned u_nb_arg, expression_result ** erpp_arg);
00097    void v_function_text (unsigned u_nb_arg, expression_result ** erpp_arg);
00098    void v_function_true (unsigned u_nb_arg, expression_result ** erpp_arg);
00099 
00100    void v_function_equal (expression_result ** erpp_arg);
00101    void v_function_not_equal (expression_result ** erpp_arg);
00102    void v_function_equal_node_and_other (expression_result * erp_node, expression_result * erp_non);
00103    void v_function_equal_2_node (expression_result * erp_node_set_, expression_result * erp_node_set_2);
00104    void v_function_union (node_set & ns_1, node_set & ns_2);
00105    void v_function_minus (expression_result ** erpp_arg);
00106    void v_function_plus (expression_result ** erpp_arg);
00107    void v_function_or (expression_result ** erpp_arg);
00108    void v_function_and (expression_result ** erpp_arg);
00109    void v_function_relational (expression_result ** erpp_arg, unsigned u_sub);
00110    void v_function_opposite ();
00111    void v_function_mult (expression_result ** erpp_arg, unsigned u_sub);
00112 
00115    void v_order_tree ();
00116    void v_order_recurs (TiXmlNode * Np_base, int & i_current);
00117 
00118    void v_push_int (int i_val, const char * cp_comment = "")   {xs_stack . v_push_int (i_val, cp_comment);}
00119    void v_push_string (TIXML_STRING S_val)   {xs_stack . v_push_string (S_val);}
00120    void v_push_bool (bool o_val)   {xs_stack . v_push_bool (o_val);}
00121    void v_push_double (double d_val)   {xs_stack . v_push_double (d_val);}
00122    void v_push_node_set (node_set * nsp_val)   {xs_stack . v_push_node_set (nsp_val);}
00123 
00124    bool o_pop_bool () {return xs_stack . o_pop_bool ();}
00125    int i_pop_int () {return xs_stack . i_pop_int ();}
00126    TIXML_STRING S_pop_string () {return xs_stack . S_pop_string ();}
00127    node_set ns_pop_node_set () {return xs_stack . ns_pop_node_set ();}
00128 
00129    void v_set_context (const TiXmlElement * XEp_in, bool o_by_name);
00130    const TiXmlElement * XEp_get_context () {return XEp_context;}
00132    TiXmlElement * XEp_root;
00134    const TiXmlElement * XEp_context;
00136    expression_result er_result;
00137    bool o_is_context_by_name;
00138 
00139    const TiXmlNode * XNp_caller_parent;
00140    const TiXmlNode * XNp_caller_prev;
00141    const TiXmlNode * XNp_caller_next;
00142    const TiXmlNode * XNp_base;
00143 
00144    void v_build_root ();
00145    void v_remove_root ();
00146 
00147 } ;
00148 
00149 }
00150 
00151 #endif

Generated for TinyXPath by doxygen SourceForge Logo