ddc
node_set.h
Go to the documentation of this file.
1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)
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 "tinyxml.h"
29 
30 namespace TinyXPath
31 {
32 
34 class node_set
35 {
36 public :
39  {
40  u_nb_node = 0;
41  vpp_node_set = NULL;
42  op_attrib = NULL;
43  }
45  node_set (const node_set & ns2);
48  {
49  if (u_nb_node && vpp_node_set)
50  delete [] vpp_node_set;
51  if (u_nb_node && op_attrib)
52  delete [] op_attrib;
53  u_nb_node = 0;
54  vpp_node_set = NULL;
55  op_attrib = NULL;
56  }
57 
58  node_set & operator = (const node_set & ns2);
59  void v_add_base_in_set (const TiXmlBase * XBp_member, bool o_attrib);
60 
62  void v_add_attrib_in_set (const TiXmlAttribute * XAp_attrib)
63  {
64  v_add_base_in_set (XAp_attrib, true);
65  }
66 
68  void v_add_node_in_set (const TiXmlNode * XNp_node)
69  {
70  v_add_base_in_set (XNp_node, false);
71  }
72 
73  bool o_exist_in_set (const TiXmlBase * XBp_member);
74  void v_add_all_foll_node (const TiXmlNode * XNp_node, const TIXML_STRING & S_name);
75  void v_add_all_prec_node (const TiXmlNode * XNp_node, const TIXML_STRING & S_name);
76 
78  void v_add_node_in_set_if_name_or_star (const TiXmlNode * XNp_node, const TIXML_STRING & S_name)
79  {
80  bool o_keep;
81  if (S_name == "*")
82  o_keep = true;
83  else
84  o_keep = ! strcmp (XNp_node -> Value (), S_name . c_str ());
85  if (o_keep)
86  v_add_base_in_set (XNp_node, false);
87  }
88 
90  void v_add_attrib_in_set_if_name_or_star (const TiXmlAttribute * XAp_attrib, const TIXML_STRING & S_name)
91  {
92  bool o_keep;
93  if (S_name == "*")
94  o_keep = true;
95  else
96  o_keep = ! strcmp (XAp_attrib -> Name (), S_name . c_str ());
97  if (o_keep)
98  v_add_base_in_set (XAp_attrib, true);
99  }
100 
102  unsigned u_get_nb_node_in_set () const
103  {
104  return u_nb_node;
105  }
106 
108  const TiXmlBase * XBp_get_base_in_set (unsigned u_which)
109  {
110  assert (u_which < u_nb_node);
111  return (const TiXmlBase *) vpp_node_set [u_which];
112  }
113 
115  const TiXmlNode * XNp_get_node_in_set (unsigned u_which)
116  {
117  assert (u_which < u_nb_node);
118  assert (! o_is_attrib (u_which));
119  return (const TiXmlNode *) vpp_node_set [u_which];
120  }
121 
123  const TiXmlAttribute * XAp_get_attribute_in_set (unsigned u_which)
124  {
125  assert (u_which < u_nb_node);
126  assert (o_is_attrib (u_which));
127  return (const TiXmlAttribute *) vpp_node_set [u_which];
128  }
129 
132  bool o_is_attrib (unsigned u_which)
133  {
134  assert (u_which < u_nb_node);
135  return op_attrib [u_which];
136  }
137 
139  TIXML_STRING S_get_value (unsigned u_which)
140  {
141  TIXML_STRING S_res;
142 
143  if (o_is_attrib (u_which))
144  S_res = XAp_get_attribute_in_set (u_which) -> Value ();
145  else
146  S_res = XNp_get_node_in_set (u_which) -> Value ();
147  return S_res;
148  }
149 
151  int i_get_value (unsigned u_which)
152  {
153  return atoi (S_get_value (u_which) . c_str ());
154  }
155 
157  double d_get_value (unsigned u_which)
158  {
159  return atof (S_get_value (u_which) . c_str ());
160  }
161 
162  void v_copy_node_children (const TiXmlNode * XNp_root);
163  void v_copy_node_children (const TiXmlNode * XNp_root, const char * cp_lookup);
164  void v_copy_selected_node_recursive (const TiXmlNode * XNp_root);
165  void v_copy_selected_node_recursive (const TiXmlNode * XNp_root, const char * cp_lookup);
166  void v_copy_selected_node_recursive_no_attrib (const TiXmlNode * XNp_root, const char * cp_lookup);
168  void v_dump ();
169  void v_document_sort ();
170 protected :
172  unsigned u_nb_node;
174  const void ** vpp_node_set;
176  bool * op_attrib;
177 } ;
178 
179 }
180 
181 #endif
182 
183 /*--- emacs style variables ---
184  * Local Variables:
185  * mode: C++
186  * c-file-style: "ellemtel"
187  * c-basic-offset: 4
188  * tab-width: 8
189  * indent-tabs-mode: nil
190  * End:
191  */
Definition: tinyxml.h:640
unsigned u_get_nb_node_in_set() const
Get nb of nodes in the node set.
Definition: node_set.h:102
void v_copy_selected_node_recursive(const TiXmlNode *XNp_root)
Copy all nodes in the tree to the node_set.
Definition: node_set.cpp:79
Definition: action_store.cpp:32
const TiXmlNode * XNp_get_node_in_set(unsigned u_which)
Get a node.
Definition: node_set.h:115
void v_add_node_in_set_if_name_or_star(const TiXmlNode *XNp_node, const TiXmlString &S_name)
Add a new node, if the name is "*" or if the name is the same as the node.
Definition: node_set.h:78
TiXmlString S_get_string_value() const
Return the string value aka concatenation of all text items.
Definition: node_set.cpp:130
bool o_exist_in_set(const TiXmlBase *XBp_member)
Checks if a node exist in the node set.
Definition: node_set.cpp:150
TiXmlString S_get_value(unsigned u_which)
Get a node value. The value is the name for an element, and the attribute value for an attribute...
Definition: node_set.h:139
void v_copy_selected_node_recursive_no_attrib(const TiXmlNode *XNp_root, const char *cp_lookup)
Copy all nodes in the tree to the node_set, excluding attributes.
Definition: node_set.cpp:113
const TiXmlBase * XBp_get_base_in_set(unsigned u_which)
Get a node or an attribute.
Definition: node_set.h:108
unsigned u_nb_node
Nb of nodes in the set.
Definition: node_set.h:172
void v_add_base_in_set(const TiXmlBase *XBp_member, bool o_attrib)
Adds a new node in the node set.
Definition: node_set.cpp:162
node_set & operator=(const node_set &ns2)
Assignation operator. Allows one to write expressions like ns_1 = ns_2;.
Definition: node_set.cpp:37
Node set class. A node set is an unordered collection of node.
Definition: node_set.h:34
void v_add_all_foll_node(const TiXmlNode *XNp_node, const TiXmlString &S_name)
Definition: node_set.cpp:192
void v_copy_node_children(const TiXmlNode *XNp_root)
Copy all element children of a node to the node_set.
Definition: node_set.cpp:56
void v_document_sort()
Definition: node_set.cpp:273
const void ** vpp_node_set
List of node pointers to the.
Definition: node_set.h:174
Definition: morph_const.h:107
Definition: tinyxml.h:138
Definition: tinyxml.h:363
bool o_is_attrib(unsigned u_which)
Definition: node_set.h:132
const TiXmlAttribute * XAp_get_attribute_in_set(unsigned u_which)
Get an attribute.
Definition: node_set.h:123
~ node_set()
destructor
Definition: node_set.h:47
bool * op_attrib
Attributes flag list.
Definition: node_set.h:176
void v_add_all_prec_node(const TiXmlNode *XNp_node, const TiXmlString &S_name)
Definition: node_set.cpp:220
void v_add_attrib_in_set(const TiXmlAttribute *XAp_attrib)
Adds an attribute in the node set.
Definition: node_set.h:62
node_set()
constructor : creates an empty set
Definition: node_set.h:38
int i_get_value(unsigned u_which)
Get the integer value of a node.
Definition: node_set.h:151
void v_add_node_in_set(const TiXmlNode *XNp_node)
Adds a node in the node set.
Definition: node_set.h:68
double d_get_value(unsigned u_which)
Get the real value of a node.
Definition: node_set.h:157
#define TIXML_STRING
Definition: tinyxml.h:67
void v_dump()
Debug function to print the content of a node set to stdout.
Definition: node_set.cpp:299
void v_add_attrib_in_set_if_name_or_star(const TiXmlAttribute *XAp_attrib, const TiXmlString &S_name)
Add a new attrib, if the name is "*" or if the name is the same as the node.
Definition: node_set.h:90