Debian Codegraph @

src/tinyxpath/tokenlist.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 /**
26 \file tokenlist.h
27 \author Yves Berquin
28 XPath Syntax analyzer for TinyXPath project : token list handling
29 */
30
31 #ifndef __TOKENLIST_H
32 #define __TOKENLIST_H
33
34 #include "lex_util.h"
35 #include "lex_token.h"
36
37 namespace TinyXPath
38 {
39
40 /**
41 A token list class. This is the output of the lexical analysis \n
42 Note that the empty list consist of a single null element in order to speed
43 up later insertions
44 */
45 class token_list
46 {
47 protected :
48 /// Pointer to first element
49 lex_token * ltp_first;
50 /// Pointer to last element
51 lex_token * ltp_last;
52 /// Pointer to current element. This is for external usage : we keep track of where it
53 /// is, but it's not needed to manage the list structure
54 lex_token * ltp_current;
55 public :
56 /// constructor
57 token_list ()
58 {
59 ltp_first = new lex_token (lex_null, NULL, 0);
60 ltp_last = ltp_first;
61 ltp_first -> v_set_prev (ltp_first);
62 ltp_first -> v_set_next (ltp_first);
63 ltp_current = NULL;
64 }
65 /// destructor
66 virtual ~ token_list ()
67 {
68 ltp_current = ltp_first -> ltp_get_next ();
69 while (ltp_current -> o_is_valid ())
70 v_delete_current ();
71 delete ltp_first;
72 }
73 /// Adds a lexical token
74 void v_add_token (lexico l_in_enum, const _byte_ * bp_in_value, unsigned u_in_size)
75 {
76 lex_token * ltp_new;
77
78 ltp_new = new lex_token (l_in_enum, bp_in_value, u_in_size);
79 ltp_last -> v_set_next (ltp_new);
80 ltp_new -> v_set_next (ltp_first);
81 ltp_first -> v_set_prev (ltp_new);
82 ltp_new -> v_set_prev (ltp_last);
83 ltp_last = ltp_new;
84 }
85
86 /// Set current to first real element
87 void v_set_current_top ()
88 {
89 ltp_current = ltp_first -> ltp_get_next (1);
90 }
91
92 /// Set current
93 void v_set_current (lex_token * ltp_cur)
94 {
95 ltp_current = ltp_cur;
96 }
97
98 /// Return the current token
99 lex_token * ltp_freeze ()
100 {
101 return ltp_current;
102 }
103
104 /// Get next X linear token
105 lex_token * ltp_get (int i_offset)
106 {
107 if (! ltp_current)
108 return NULL;
109 return ltp_current -> ltp_get_next (i_offset);
110 }
111
112 /// Increments the linear counter
113 void v_inc_current (int i_rel)
114 {
115 if (! ltp_current)
116 return;
117 ltp_current = ltp_current -> ltp_get_next (i_rel);
118 }
119
120 /// Replaces the current element
121 void v_replace_current (lexico lex_in, const char * cp_rep)
122 {
123 if (! ltp_current)
124 return;
125 ltp_current -> v_set (lex_in, cp_rep);
126 }
127
128 /// Deletes the current element
129 void v_delete_current ()
130 {
131 lex_token * ltp_temp;
132
133 assert (ltp_current);
134 ltp_temp = ltp_current;
135 ltp_temp -> ltp_get_prev () -> v_set_next (ltp_temp -> ltp_get_next ());
136 ltp_temp -> ltp_get_next () -> v_set_prev (ltp_temp -> ltp_get_prev ());
137 ltp_current = ltp_temp -> ltp_get_next ();
138 delete ltp_temp;
139 }
140
141 /// Deletes the next element
142 void v_delete_next ()
143 {
144 lex_token * ltp_temp;
145
146 assert (ltp_current);
147 ltp_temp = ltp_current -> ltp_get_next ();
148 ltp_current -> v_set_next (ltp_temp -> ltp_get_next ());
149 ltp_temp -> ltp_get_next () -> v_set_prev (ltp_current);
150 delete ltp_temp;
151 }
152 void v_tokenize_expression ();
153 } ;
154
155 }
156
157 #endif