Debian Codegraph @

src/tinyxpath/node_set.h

raw symbols SCIP
1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin ([email protected])
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
25 #ifndef __NODE_SET_H
26 #define __NODE_SET_H
27
28 #include <cstring> // Added by neoneurone on 27th november, 2007
29
30 #include "tinyxml.h"
31
32 namespace TinyXPath
33 {
34
35 /// Node set class. A node set is an unordered collection of node
36 class node_set
37 {
38 public :
39 /// constructor : creates an empty set
40 node_set ()
41 {
42 u_nb_node = 0;
43 vpp_node_set = NULL;
44 op_attrib = NULL;
45 }
46 /// copy constructor
47 node_set (const node_set & ns2);
48 /// destructor
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 /// Adds an attribute in the node set
64 void v_add_attrib_in_set (const TiXmlAttribute * XAp_attrib)
65 {
66 v_add_base_in_set (XAp_attrib, true);
67 }
68
69 /// Adds a node in the node set
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 /// Add a new node, if the name is "*" or if the name is the same as the node
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 /// Add a new attrib, if the name is "*" or if the name is the same as the node
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 /// Get nb of nodes in the node set
104 unsigned u_get_nb_node_in_set () const
105 {
106 return u_nb_node;
107 }
108
109 /// Get a node or an attribute
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 /// Get a node
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 /// Get an attribute
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 /// Check if a node is an attribute or another node. This is needed because TinyXML has a weird exception for
133 /// attributes not being children of TiXmlNode
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 /// Get a node value. The value is the name for an element, and the attribute value for an attribute
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 /// Get the integer value of a node
153 int i_get_value (unsigned u_which)
154 {
155 return atoi (S_get_value (u_which) . c_str ());
156 }
157
158 /// Get the real value of a node
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 /// Nb of nodes in the set
174 unsigned u_nb_node;
175 /// List of node pointers to the
176 const void ** vpp_node_set;
177 /// Attributes flag list
178 bool * op_attrib;
179 } ;
180
181 }
182
183 #endif