ddc
tokenlist.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 
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 
45 class token_list
46 {
47 protected :
55 public :
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  }
66  virtual ~ token_list ()
67  {
68  ltp_current = ltp_first -> ltp_get_next ();
69  while (ltp_current -> o_is_valid ())
71  delete ltp_first;
72  }
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 
88  {
89  ltp_current = ltp_first -> ltp_get_next (1);
90  }
91 
93  void v_set_current (lex_token * ltp_cur)
94  {
95  ltp_current = ltp_cur;
96  }
97 
100  {
101  return ltp_current;
102  }
103 
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 
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 
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 
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 
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
158 
159 /*--- emacs style variables ---
160  * Local Variables:
161  * mode: C++
162  * c-file-style: "ellemtel"
163  * c-basic-offset: 4
164  * tab-width: 8
165  * indent-tabs-mode: nil
166  * End:
167  */
Definition: tokenlist.h:45
void v_add_token(lexico l_in_enum, const _byte_ *bp_in_value, unsigned u_in_size)
Adds a lexical token.
Definition: tokenlist.h:74
void v_tokenize_expression()
Definition: tokenlist.cpp:39
token_list()
constructor
Definition: tokenlist.h:57
void v_set_current(lex_token *ltp_cur)
Set current.
Definition: tokenlist.h:93
Definition: action_store.cpp:32
void v_replace_current(lexico lex_in, const char *cp_rep)
Replaces the current element.
Definition: tokenlist.h:121
lex_token * ltp_first
Pointer to first element.
Definition: tokenlist.h:49
Definition: lex_util.h:50
lex_token * ltp_last
Pointer to last element.
Definition: tokenlist.h:51
unsigned char _byte_
Definition: lex_util.h:44
Definition: lex_token.h:38
lex_token * ltp_current
Definition: tokenlist.h:54
void v_inc_current(int i_rel)
Increments the linear counter.
Definition: tokenlist.h:113
void v_delete_next()
Deletes the next element.
Definition: tokenlist.h:142
lexico
Lexical XPath elements.
Definition: lex_util.h:47
lex_token * ltp_get(int i_offset)
Get next X linear token.
Definition: tokenlist.h:105
void v_set_current_top()
Set current to first real element.
Definition: tokenlist.h:87
void v_delete_current()
Deletes the current element.
Definition: tokenlist.h:129
virtual ~ token_list()
destructor
Definition: tokenlist.h:66
lex_token * ltp_freeze()
Return the current token.
Definition: tokenlist.h:99