ddc
xpath_expression.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 __EXPR_H
26 #define __EXPR_H
27 
28 #include "tinyxpath_conf.h"
29 #include "tinyxml.h"
30 #include "node_set.h"
31 
32 //-- suppress irritating warnings from clang (moocow, Fri, 14 Feb 2020 12:55:42 +0100)
33 #ifdef __clang__
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wundefined-bool-conversion"
36 #endif
37 
38 namespace TinyXPath
39 {
40 
43 
46 {
47 protected :
50  #ifdef TINYXPATH_DEBUG
51  TIXML_STRING S_comment;
53  #endif
54  bool o_content;
57  int i_content;
59  double d_content;
62 
63 public :
65  e_expression_type e_type;
68  {
69  e_type = e_invalid;
70  o_content = false;
71  i_content = 0;
72  d_content = 0.0;
73  }
76  {
77  * this = er_2;
78  }
79 
81  {
82  e_type = er_2 . e_type;
83  switch (e_type)
84  {
85  case e_bool :
86  o_content = er_2 . o_content;
87  break;
88  case e_int :
89  i_content = er_2 . i_content;
90  break;
91  case e_string :
92  S_content = er_2 . S_content;
93  break;
94  case e_double :
95  d_content = er_2 . d_content;
96  break;
97  case e_node_set :
98  ns_set = er_2 . ns_set;
99  break;
100  default: break; //-- unhandled
101  }
102  #ifdef TINYXPATH_DEBUG
103  S_comment = er_2 . S_comment;
104  #endif
105  return * this;
106  }
108  void v_set_bool (bool o_in)
109  {
110  e_type = e_bool;
111  o_content = o_in;
112  }
114  void v_set_int (int i_in)
115  {
116  e_type = e_int;
117  i_content = i_in;
118  }
120  void v_set_string (const char * cp_in)
121  {
122  e_type = e_string;
123  S_content = cp_in;
124  }
127  {
128  e_type = e_string;
129  S_content = S_in;
130  }
132  void v_set_double (double d_in)
133  {
134  e_type = e_double;
135  d_content = d_in;
136  }
138  void v_set_comment (const char * cp_in)
139  {
140  #ifdef TINYXPATH_DEBUG
141  S_comment = cp_in;
142  #endif
143  }
144  int i_get_int ();
147  const char * cp_get_string ()
148  {
149  assert (e_type == e_string);
150  return S_content . c_str ();
151  }
152  bool o_get_bool ();
153  double d_get_double ();
155  void v_set_node_set (node_set * nsp_source)
156  {
157  e_type = e_node_set;
158  ns_set = * nsp_source;
159  }
161  void v_set_node_set (TiXmlNode * XNp_root)
162  {
163  e_type = e_node_set;
164  ns_set . v_copy_node_children (XNp_root);
165  }
167  void v_set_node_set (TiXmlNode * XNp_root, const char * cp_lookup)
168  {
169  e_type = e_node_set;
170  ns_set . v_copy_node_children (XNp_root, cp_lookup);
171  }
174  {
175  e_type = e_node_set;
176  ns_set . v_copy_selected_node_recursive (XNp_root);
177  }
179  void v_set_node_set_recursive (TiXmlNode * XNp_root, const char * cp_lookup)
180  {
181  e_type = e_node_set;
182  ns_set . v_copy_selected_node_recursive (XNp_root, cp_lookup);
183  }
186  {
187  e_type = e_node_set;
188  }
191  {
192  return & ns_set;
193  }
194  #ifdef TINYXPATH_DEBUG
195  void v_dump ();
196  #endif
197 } ;
198 
199 }
200 
201 #ifdef __clang__
202 #pragma clang diagnostic pop
203 #endif
204 
205 #endif
206 
207 /*--- emacs style variables ---
208  * Local Variables:
209  * mode: C++
210  * c-file-style: "ellemtel"
211  * c-basic-offset: 4
212  * tab-width: 8
213  * indent-tabs-mode: nil
214  * End:
215  */
expression_result & operator=(const expression_result &er_2)
Definition: xpath_expression.h:80
void v_set_bool(bool o_in)
Set expression_result to a bool.
Definition: xpath_expression.h:108
TiXmlString S_get_string()
Get the expression_result as a string.
Definition: xpath_expression.cpp:66
Definition: xpath_expression.h:42
void v_set_string(const char *cp_in)
Set expression_result to a string.
Definition: xpath_expression.h:120
double d_get_double()
Get the expression_result as a double.
Definition: xpath_expression.cpp:50
bool o_get_bool()
Definition: xpath_expression.cpp:117
Definition: xpath_expression.h:42
Definition: xpath_expression.h:42
expression_result()
Dummy constructor.
Definition: xpath_expression.h:67
Definition: action_store.cpp:32
node_set * nsp_get_node_set()
Get the expression_result as a node set.
Definition: xpath_expression.h:190
Definition: xpath_expression.h:42
void v_set_comment(const char *cp_in)
Set the comment associated with a stack element. This is for debuging.
Definition: xpath_expression.h:138
void v_set_string(TiXmlString S_in)
Set expression_result to a string.
Definition: xpath_expression.h:126
int i_get_int()
Get the expression_result as an int.
Definition: xpath_expression.cpp:34
Class holding the result of an expression (e_expression_type)
Definition: xpath_expression.h:45
Definition: xpath_expression.h:42
expression_result(const expression_result &er_2)
Copy constructor.
Definition: xpath_expression.h:75
const char * cp_get_string()
Get the expression_result as a string.
Definition: xpath_expression.h:147
bool o_content
bool content
Definition: xpath_expression.h:55
e_expression_type
Expression types.
Definition: xpath_expression.h:42
void v_set_node_set_recursive(TiXmlNode *XNp_root)
Set the expression_result as a node set.
Definition: xpath_expression.h:173
TiXmlString S_content
String content.
Definition: xpath_expression.h:49
void v_set_double(double d_in)
Set expression_result to a double.
Definition: xpath_expression.h:132
Definition: xpath_expression.h:42
double d_content
double content
Definition: xpath_expression.h:59
Node set class. A node set is an unordered collection of node.
Definition: node_set.h:34
void v_set_node_set(node_set *nsp_source)
Set the expression_result as a node set.
Definition: xpath_expression.h:155
Definition: tinyxml.h:363
int i_content
integer content
Definition: xpath_expression.h:57
void v_set_int(int i_in)
Set expression_result to an int.
Definition: xpath_expression.h:114
void v_set_node_set(TiXmlNode *XNp_root, const char *cp_lookup)
Set the expression_result as a node set.
Definition: xpath_expression.h:167
e_expression_type e_type
expression type
Definition: xpath_expression.h:65
node_set ns_set
node set content
Definition: xpath_expression.h:61
void v_set_node_set(TiXmlNode *XNp_root)
Set the expression_result as a node set.
Definition: xpath_expression.h:161
void v_set_node_set()
Set the expression_result as an empty node set.
Definition: xpath_expression.h:185
#define TIXML_STRING
Definition: tinyxml.h:67
void v_set_node_set_recursive(TiXmlNode *XNp_root, const char *cp_lookup)
Set the expression_result as a node set.
Definition: xpath_expression.h:179