Debian Codegraph @

src/tinyxpath/xpath_expression.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 __EXPR_H
26 #define __EXPR_H
27
28 #include "tinyxpath_conf.h"
29 #include "tinyxml.h"
30 #include "node_set.h"
31
32 namespace TinyXPath
33 {
34
35 /// Expression types
36 typedef enum {e_bool, e_string, e_int, e_double, e_node_set, e_invalid} e_expression_type;
37
38 /// Class holding the result of an expression (e_expression_type)
39 class expression_result
40 {
41 protected :
42 /// String content
43 TIXML_STRING S_content;
44 #ifdef TINYXPATH_DEBUG
45 /// Comment. This is for debuging only, for stack dump
46 TIXML_STRING S_comment;
47 #endif
48 /// bool content
49 bool o_content;
50 /// integer content
51 int i_content;
52 /// double content
53 double d_content;
54 /// node set content
55 node_set ns_set;
56
57 public :
58 /// expression type
59 e_expression_type e_type;
60 /// Dummy constructor
61 expression_result ()
62 {
63 e_type = e_invalid;
64 o_content = false;
65 i_content = 0;
66 d_content = 0.0;
67 }
68 /// Copy constructor
69 expression_result (const expression_result & er_2)
70 {
71 * this = er_2;
72 }
73
74 expression_result & operator = (const expression_result & er_2)
75 {
76 e_type = er_2 . e_type;
77 switch (e_type)
78 {
79 case e_bool :
80 o_content = er_2 . o_content;
81 break;
82 case e_int :
83 i_content = er_2 . i_content;
84 break;
85 case e_string :
86 S_content = er_2 . S_content;
87 break;
88 case e_double :
89 d_content = er_2 . d_content;
90 break;
91 case e_node_set :
92 ns_set = er_2 . ns_set;
93 break;
94
95 // jan 21th, 07 - neoneurone: silently ignore the other cases
96 default:
97 break;
98 }
99 #ifdef TINYXPATH_DEBUG
100 S_comment = er_2 . S_comment;
101 #endif
102 return * this;
103 }
104 /// Set expression_result to a bool
105 void v_set_bool (bool o_in)
106 {
107 e_type = e_bool;
108 o_content = o_in;
109 }
110 /// Set expression_result to an int
111 void v_set_int (int i_in)
112 {
113 e_type = e_int;
114 i_content = i_in;
115 }
116 /// Set expression_result to a string
117 void v_set_string (const char * cp_in)
118 {
119 e_type = e_string;
120 S_content = cp_in;
121 }
122 /// Set expression_result to a string
123 void v_set_string (TIXML_STRING S_in)
124 {
125 e_type = e_string;
126 S_content = S_in;
127 }
128 /// Set expression_result to a double
129 void v_set_double (double d_in)
130 {
131 e_type = e_double;
132 d_content = d_in;
133 }
134 /// Set the comment associated with a stack element. This is for debuging
135 void v_set_comment (const char * cp_in)
136 {
137 #ifdef TINYXPATH_DEBUG
138 S_comment = cp_in;
139 #endif
140 }
141 int i_get_int ();
142 TIXML_STRING S_get_string ();
143 /// Get the expression_result as a string
144 const char * cp_get_string ()
145 {
146 assert (e_type == e_string);
147 return S_content . c_str ();
148 }
149 bool o_get_bool ();
150 double d_get_double ();
151 /// Set the expression_result as a node set
152 void v_set_node_set (node_set * nsp_source)
153 {
154 e_type = e_node_set;
155 ns_set = * nsp_source;
156 }
157 /// Set the expression_result as a node set
158 void v_set_node_set (TiXmlNode * XNp_root)
159 {
160 e_type = e_node_set;
161 ns_set . v_copy_node_children (XNp_root);
162 }
163 /// Set the expression_result as a node set
164 void v_set_node_set (TiXmlNode * XNp_root, const char * cp_lookup)
165 {
166 e_type = e_node_set;
167 ns_set . v_copy_node_children (XNp_root, cp_lookup);
168 }
169 /// Set the expression_result as a node set
170 void v_set_node_set_recursive (TiXmlNode * XNp_root)
171 {
172 e_type = e_node_set;
173 ns_set . v_copy_selected_node_recursive (XNp_root);
174 }
175 /// Set the expression_result as a node set
176 void v_set_node_set_recursive (TiXmlNode * XNp_root, const char * cp_lookup)
177 {
178 e_type = e_node_set;
179 ns_set . v_copy_selected_node_recursive (XNp_root, cp_lookup);
180 }
181 /// Set the expression_result as an empty node set
182 void v_set_node_set ()
183 {
184 e_type = e_node_set;
185 }
186 /// Get the expression_result as a node set
187 node_set * nsp_get_node_set ()
188 {
189 return & ns_set;
190 }
191 #ifdef TINYXPATH_DEBUG
192 void v_dump ();
193 #endif
194 } ;
195
196 }
197
198 #endif