| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#ifndef __NODE_SET_H |
| 26 |
#define __NODE_SET_H |
| 27 |
|
| 28 |
#include <cstring> |
| 29 |
|
| 30 |
#include "tinyxml.h" |
| 31 |
|
| 32 |
namespace TinyXPath |
| 33 |
{ |
| 34 |
|
| 35 |
|
| 36 |
class node_set |
| 37 |
{ |
| 38 |
public : |
| 39 |
|
| 40 |
node_set () |
| 41 |
{ |
| 42 |
u_nb_node = 0; |
| 43 |
vpp_node_set = NULL; |
| 44 |
op_attrib = NULL; |
| 45 |
} |
| 46 |
|
| 47 |
node_set (const node_set & ns2); |
| 48 |
|
| 49 |
~ node_set () |
| 50 |
{ |
| 51 |
if (u_nb_node && vpp_node_set) |
| 52 |
delete [] vpp_node_set; |
| 53 |
if (u_nb_node && op_attrib) |
| 54 |
delete [] op_attrib; |
| 55 |
u_nb_node = 0; |
| 56 |
vpp_node_set = NULL; |
| 57 |
op_attrib = NULL; |
| 58 |
} |
| 59 |
|
| 60 |
node_set & operator = (const node_set & ns2); |
| 61 |
void v_add_base_in_set (const TiXmlBase * XBp_member, bool o_attrib); |
| 62 |
|
| 63 |
|
| 64 |
void v_add_attrib_in_set (const TiXmlAttribute * XAp_attrib) |
| 65 |
{ |
| 66 |
v_add_base_in_set (XAp_attrib, true); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
void v_add_node_in_set (const TiXmlNode * XNp_node) |
| 71 |
{ |
| 72 |
v_add_base_in_set (XNp_node, false); |
| 73 |
} |
| 74 |
|
| 75 |
bool o_exist_in_set (const TiXmlBase * XBp_member); |
| 76 |
void v_add_all_foll_node (const TiXmlNode * XNp_node, const TIXML_STRING & S_name); |
| 77 |
void v_add_all_prec_node (const TiXmlNode * XNp_node, const TIXML_STRING & S_name); |
| 78 |
|
| 79 |
|
| 80 |
void v_add_node_in_set_if_name_or_star (const TiXmlNode * XNp_node, const TIXML_STRING & S_name) |
| 81 |
{ |
| 82 |
bool o_keep; |
| 83 |
if (S_name == "*") |
| 84 |
o_keep = true; |
| 85 |
else |
| 86 |
o_keep = ! strcmp (XNp_node -> Value (), S_name . c_str ()); |
| 87 |
if (o_keep) |
| 88 |
v_add_base_in_set (XNp_node, false); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
void v_add_attrib_in_set_if_name_or_star (const TiXmlAttribute * XAp_attrib, const TIXML_STRING & S_name) |
| 93 |
{ |
| 94 |
bool o_keep; |
| 95 |
if (S_name == "*") |
| 96 |
o_keep = true; |
| 97 |
else |
| 98 |
o_keep = ! strcmp (XAp_attrib -> Name (), S_name . c_str ()); |
| 99 |
if (o_keep) |
| 100 |
v_add_base_in_set (XAp_attrib, true); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
unsigned u_get_nb_node_in_set () const |
| 105 |
{ |
| 106 |
return u_nb_node; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
const TiXmlBase * XBp_get_base_in_set (unsigned u_which) |
| 111 |
{ |
| 112 |
assert (u_which < u_nb_node); |
| 113 |
return (const TiXmlBase *) vpp_node_set [u_which]; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
const TiXmlNode * XNp_get_node_in_set (unsigned u_which) |
| 118 |
{ |
| 119 |
assert (u_which < u_nb_node); |
| 120 |
assert (! o_is_attrib (u_which)); |
| 121 |
return (const TiXmlNode *) vpp_node_set [u_which]; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
const TiXmlAttribute * XAp_get_attribute_in_set (unsigned u_which) |
| 126 |
{ |
| 127 |
assert (u_which < u_nb_node); |
| 128 |
assert (o_is_attrib (u_which)); |
| 129 |
return (const TiXmlAttribute *) vpp_node_set [u_which]; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
bool o_is_attrib (unsigned u_which) |
| 135 |
{ |
| 136 |
assert (u_which < u_nb_node); |
| 137 |
return op_attrib [u_which]; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
TIXML_STRING S_get_value (unsigned u_which) |
| 142 |
{ |
| 143 |
TIXML_STRING S_res; |
| 144 |
|
| 145 |
if (o_is_attrib (u_which)) |
| 146 |
S_res = XAp_get_attribute_in_set (u_which) -> Value (); |
| 147 |
else |
| 148 |
S_res = XNp_get_node_in_set (u_which) -> Value (); |
| 149 |
return S_res; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
int i_get_value (unsigned u_which) |
| 154 |
{ |
| 155 |
return atoi (S_get_value (u_which) . c_str ()); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
double d_get_value (unsigned u_which) |
| 160 |
{ |
| 161 |
return atof (S_get_value (u_which) . c_str ()); |
| 162 |
} |
| 163 |
|
| 164 |
void v_copy_node_children (const TiXmlNode * XNp_root); |
| 165 |
void v_copy_node_children (const TiXmlNode * XNp_root, const char * cp_lookup); |
| 166 |
void v_copy_selected_node_recursive (const TiXmlNode * XNp_root); |
| 167 |
void v_copy_selected_node_recursive (const TiXmlNode * XNp_root, const char * cp_lookup); |
| 168 |
void v_copy_selected_node_recursive_no_attrib (const TiXmlNode * XNp_root, const char * cp_lookup); |
| 169 |
TIXML_STRING S_get_string_value () const; |
| 170 |
void v_dump (); |
| 171 |
void v_document_sort (); |
| 172 |
protected : |
| 173 |
|
| 174 |
unsigned u_nb_node; |
| 175 |
|
| 176 |
const void ** vpp_node_set; |
| 177 |
|
| 178 |
bool * op_attrib; |
| 179 |
} ; |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
#endif |