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 00025 #ifndef __EXPR_H 00026 #define __EXPR_H 00027 00028 #include "tinyxpath_conf.h" 00029 #include "tinyxml.h" 00030 #include "node_set.h" 00031 00032 namespace TinyXPath 00033 { 00034 00036 typedef enum {e_bool, e_string, e_int, e_double, e_node_set, e_invalid} e_expression_type; 00037 00039 class expression_result 00040 { 00041 protected : 00043 TIXML_STRING S_content; 00044 #ifdef TINYXPATH_DEBUG 00045 00046 TIXML_STRING S_comment; 00047 #endif 00048 00049 bool o_content; 00051 int i_content; 00053 double d_content; 00055 node_set ns_set; 00056 00057 public : 00059 e_expression_type e_type; 00061 expression_result () 00062 { 00063 e_type = e_invalid; 00064 o_content = false; 00065 i_content = 0; 00066 d_content = 0.0; 00067 } 00069 expression_result (const expression_result & er_2) 00070 { 00071 * this = er_2; 00072 } 00073 00074 expression_result & operator = (const expression_result & er_2) 00075 { 00076 e_type = er_2 . e_type; 00077 switch (e_type) 00078 { 00079 case e_bool : 00080 o_content = er_2 . o_content; 00081 break; 00082 case e_int : 00083 i_content = er_2 . i_content; 00084 break; 00085 case e_string : 00086 S_content = er_2 . S_content; 00087 break; 00088 case e_double : 00089 d_content = er_2 . d_content; 00090 break; 00091 case e_node_set : 00092 ns_set = er_2 . ns_set; 00093 break; 00094 } 00095 #ifdef TINYXPATH_DEBUG 00096 S_comment = er_2 . S_comment; 00097 #endif 00098 return * this; 00099 } 00101 void v_set_bool (bool o_in) 00102 { 00103 e_type = e_bool; 00104 o_content = o_in; 00105 } 00107 void v_set_int (int i_in) 00108 { 00109 e_type = e_int; 00110 i_content = i_in; 00111 } 00113 void v_set_string (const char * cp_in) 00114 { 00115 e_type = e_string; 00116 S_content = cp_in; 00117 } 00119 void v_set_string (TIXML_STRING S_in) 00120 { 00121 e_type = e_string; 00122 S_content = S_in; 00123 } 00125 void v_set_double (double d_in) 00126 { 00127 e_type = e_double; 00128 d_content = d_in; 00129 } 00131 void v_set_comment (const char * cp_in) 00132 { 00133 #ifdef TINYXPATH_DEBUG 00134 S_comment = cp_in; 00135 #endif 00136 } 00137 int i_get_int (); 00138 TIXML_STRING S_get_string (); 00140 const char * cp_get_string () 00141 { 00142 assert (e_type == e_string); 00143 return S_content . c_str (); 00144 } 00145 bool o_get_bool (); 00146 double d_get_double (); 00148 void v_set_node_set (node_set * nsp_source) 00149 { 00150 e_type = e_node_set; 00151 ns_set = * nsp_source; 00152 } 00154 void v_set_node_set (TiXmlNode * XNp_root) 00155 { 00156 e_type = e_node_set; 00157 ns_set . v_copy_node_children (XNp_root); 00158 } 00160 void v_set_node_set (TiXmlNode * XNp_root, const char * cp_lookup) 00161 { 00162 e_type = e_node_set; 00163 ns_set . v_copy_node_children (XNp_root, cp_lookup); 00164 } 00166 void v_set_node_set_recursive (TiXmlNode * XNp_root) 00167 { 00168 e_type = e_node_set; 00169 ns_set . v_copy_selected_node_recursive (XNp_root); 00170 } 00172 void v_set_node_set_recursive (TiXmlNode * XNp_root, const char * cp_lookup) 00173 { 00174 e_type = e_node_set; 00175 ns_set . v_copy_selected_node_recursive (XNp_root, cp_lookup); 00176 } 00178 void v_set_node_set () 00179 { 00180 e_type = e_node_set; 00181 } 00183 node_set * nsp_get_node_set () 00184 { 00185 return & ns_set; 00186 } 00187 #ifdef TINYXPATH_DEBUG 00188 void v_dump (); 00189 #endif 00190 } ; 00191 00192 } 00193 00194 #endif