Welcome to mirror list, hosted at ThFree Co, Russian Federation.

xpath_expression.h « tinyxpath « 3rdparty - github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08662904d1db3163628328bd1a5561892e723cd2 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
www.sourceforge.net/projects/tinyxpath
Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
*/

#ifndef __EXPR_H
#define __EXPR_H

#include "tinyxpath_conf.h"
#include "tinyxml.h"
#include "node_set.h"

namespace TinyXPath
{

/// Expression types
typedef enum {e_bool, e_string, e_int, e_double, e_node_set, e_invalid} e_expression_type;

/// Class holding the result of an expression (e_expression_type)
class expression_result
{
protected :	
   /// String content
	TIXML_STRING S_content;
   #ifdef TINYXPATH_DEBUG
      /// Comment. This is for debuging only, for stack dump 
	   TIXML_STRING S_comment;
   #endif
   /// bool content
	bool o_content;
   /// integer content
	int i_content;
   /// double content
	double d_content;
   /// node set content
   node_set ns_set;
   /// Ptr to the root node
   const TiXmlNode * XNp_root;

public :
   /// expression type
	e_expression_type e_type;
   /// Dummy constructor
 	expression_result (const TiXmlNode * XNp_in_root) : XNp_root (XNp_in_root)
	{
		e_type = e_invalid;
      o_content = false;
      i_content = 0;
      d_content = 0.0;
	}

   expression_result ()
	{
	   XNp_root = NULL;
		e_type = e_invalid;
      o_content = false;
      i_content = 0;
      d_content = 0.0;
	}
	
	void v_set_root (const TiXmlNode * XNp_in) {XNp_root = XNp_in;}

   /// Copy constructor
	expression_result (const expression_result & er_2)
	{
      * this = er_2;
	}

   expression_result & operator = (const expression_result & er_2)
   {
      XNp_root = er_2 . XNp_root;
		e_type = er_2 . e_type;
      switch (e_type)
      {
         case e_bool :
            o_content = er_2 . o_content;
            break;
         case e_int :
            i_content = er_2 . i_content;
            break;
         case e_string :
            S_content = er_2 . S_content;
            break;
         case e_double :
            d_content = er_2 . d_content;
            break;
         case e_node_set :
            ns_set = er_2 . ns_set;
            break;
      }
      #ifdef TINYXPATH_DEBUG
         S_comment = er_2 . S_comment;
      #endif
      return * this;
   }
   /// Set expression_result to a bool
	void v_set_bool (bool o_in)
	{
		e_type = e_bool;
		o_content = o_in;
	}
   /// Set expression_result to an int
	void v_set_int (int i_in)
	{
		e_type = e_int;
		i_content = i_in;
	}
   /// Set expression_result to a string
	void v_set_string (const char * cp_in)
	{
		e_type = e_string;
		S_content = cp_in;
	}
   /// Set expression_result to a string
	void v_set_string (TIXML_STRING S_in)
	{
		e_type = e_string;
		S_content = S_in;
	}
   /// Set expression_result to a double
	void v_set_double (double d_in)
	{
		e_type = e_double;
		d_content = d_in;
	}
   /// Set the comment associated with a stack element. This is for debuging
	void v_set_comment (const char * cp_in)
	{
      #ifdef TINYXPATH_DEBUG
		   S_comment = cp_in;
      #endif
	}
	int i_get_int ();
	TIXML_STRING S_get_string ();
   /// Get the expression_result as a string
	const char * cp_get_string ()
	{
		assert (e_type == e_string);
		return S_content . c_str ();
	}	
	bool o_get_bool ();
	double d_get_double ();
   /// Set the expression_result as a node set
	void v_set_node_set (node_set * nsp_source)
	{
		e_type = e_node_set;
      ns_set = * nsp_source;
	}
   /// Set the expression_result as a node set
	void v_set_node_set (TiXmlNode * XNp_root)
	{
		e_type = e_node_set;
      ns_set . v_copy_node_children (XNp_root);
	}
   /// Set the expression_result as a node set
	void v_set_node_set (TiXmlNode * XNp_root, const char * cp_lookup)
	{
		e_type = e_node_set;
      ns_set . v_copy_node_children (XNp_root, cp_lookup);
	}
   /// Set the expression_result as a node set
	void v_set_node_set_recursive (TiXmlNode * XNp_root)
	{
		e_type = e_node_set;
      ns_set . v_copy_selected_node_recursive (XNp_root);
	}
   /// Set the expression_result as a node set
	void v_set_node_set_recursive (TiXmlNode * XNp_root, const char * cp_lookup)
	{
		e_type = e_node_set;
      ns_set . v_copy_selected_node_recursive (XNp_root, cp_lookup);
	}
   /// Set the expression_result as an empty node set
	void v_set_node_set ()
   {
      e_type = e_node_set;
   }
   /// Get the expression_result as a node set
   node_set * nsp_get_node_set ()
   {
      return & ns_set;
   }
   #ifdef TINYXPATH_DEBUG
      void v_dump ();
   #endif
} ;

}

#endif