00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __NODE_SET_H
00026 #define __NODE_SET_H
00027
00028 #include "tinyxml.h"
00029
00030 namespace TinyXPath
00031 {
00032
00034 class node_set
00035 {
00036 public :
00038 node_set ()
00039 {
00040 u_nb_node = 0;
00041 vpp_node_set = NULL;
00042 op_attrib = NULL;
00043 }
00045 node_set (const node_set & ns2);
00047 ~ node_set ()
00048 {
00049 if (u_nb_node && vpp_node_set)
00050 delete [] vpp_node_set;
00051 if (u_nb_node && op_attrib)
00052 delete [] op_attrib;
00053 u_nb_node = 0;
00054 vpp_node_set = NULL;
00055 op_attrib = NULL;
00056 }
00057
00058 node_set & operator = (const node_set & ns2);
00059 void v_add_base_in_set (const TiXmlBase * XBp_member, bool o_attrib);
00060
00062 void v_add_attrib_in_set (const TiXmlAttribute * XAp_attrib)
00063 {
00064 v_add_base_in_set (XAp_attrib, true);
00065 }
00066
00068 void v_add_node_in_set (const TiXmlNode * XNp_node)
00069 {
00070 v_add_base_in_set (XNp_node, false);
00071 }
00072
00073 bool o_exist_in_set (const TiXmlBase * XBp_member);
00074 void v_add_all_foll_node (const TiXmlNode * XNp_node, const TIXML_STRING & S_name);
00075 void v_add_all_prec_node (const TiXmlNode * XNp_node, const TIXML_STRING & S_name);
00076
00078 void v_add_node_in_set_if_name_or_star (const TiXmlNode * XNp_node, const TIXML_STRING & S_name)
00079 {
00080 bool o_keep;
00081 if (S_name == "*")
00082 o_keep = true;
00083 else
00084 o_keep = ! strcmp (XNp_node -> Value (), S_name . c_str ());
00085 if (o_keep)
00086 v_add_base_in_set (XNp_node, false);
00087 }
00088
00090 void v_add_attrib_in_set_if_name_or_star (const TiXmlAttribute * XAp_attrib, const TIXML_STRING & S_name)
00091 {
00092 bool o_keep;
00093 if (S_name == "*")
00094 o_keep = true;
00095 else
00096 o_keep = ! strcmp (XAp_attrib -> Name (), S_name . c_str ());
00097 if (o_keep)
00098 v_add_base_in_set (XAp_attrib, true);
00099 }
00100
00102 unsigned u_get_nb_node_in_set () const
00103 {
00104 return u_nb_node;
00105 }
00106
00108 const TiXmlBase * XBp_get_base_in_set (unsigned u_which)
00109 {
00110 assert (u_which < u_nb_node);
00111 return (const TiXmlBase *) vpp_node_set [u_which];
00112 }
00113
00115 const TiXmlNode * XNp_get_node_in_set (unsigned u_which)
00116 {
00117 assert (u_which < u_nb_node);
00118 assert (! o_is_attrib (u_which));
00119 return (const TiXmlNode *) vpp_node_set [u_which];
00120 }
00121
00123 const TiXmlAttribute * XAp_get_attribute_in_set (unsigned u_which)
00124 {
00125 assert (u_which < u_nb_node);
00126 assert (o_is_attrib (u_which));
00127 return (const TiXmlAttribute *) vpp_node_set [u_which];
00128 }
00129
00132 bool o_is_attrib (unsigned u_which)
00133 {
00134 assert (u_which < u_nb_node);
00135 return op_attrib [u_which];
00136 }
00137
00139 TIXML_STRING S_get_value (unsigned u_which)
00140 {
00141 TIXML_STRING S_res;
00142
00143 if (o_is_attrib (u_which))
00144 S_res = XAp_get_attribute_in_set (u_which) -> Value ();
00145 else
00146 S_res = XNp_get_node_in_set (u_which) -> Value ();
00147 return S_res;
00148 }
00149
00151 int i_get_value (unsigned u_which)
00152 {
00153 return atoi (S_get_value (u_which) . c_str ());
00154 }
00155
00157 double d_get_value (unsigned u_which)
00158 {
00159 return atof (S_get_value (u_which) . c_str ());
00160 }
00161
00162 void v_copy_node_children (const TiXmlNode * XNp_root);
00163 void v_copy_node_children (const TiXmlNode * XNp_root, const char * cp_lookup);
00164 void v_copy_selected_node_recursive (const TiXmlNode * XNp_root);
00165 void v_copy_selected_node_recursive (const TiXmlNode * XNp_root, const char * cp_lookup);
00166 void v_copy_selected_node_recursive_no_attrib (const TiXmlNode * XNp_root, const char * cp_lookup);
00167 TIXML_STRING S_get_string_value () const;
00168 void v_dump ();
00169 void v_document_sort ();
00170 protected :
00172 unsigned u_nb_node;
00174 const void ** vpp_node_set;
00176 bool * op_attrib;
00177 } ;
00178
00179 }
00180
00181 #endif