00001 /* 00002 www.sourceforge.net/projects/tinyxpath 00003 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net) 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to anyone to use this software for any 00010 purpose, including commercial applications, and to alter it and 00011 redistribute it freely, subject to the following restrictions: 00012 00013 1. The origin of this software must not be misrepresented; you must 00014 not claim that you wrote the original software. If you use this 00015 software in a product, an acknowledgment in the product documentation 00016 would be appreciated but is not required. 00017 00018 2. Altered source versions must be plainly marked as such, and 00019 must not be misrepresented as being the original software. 00020 00021 3. This notice may not be removed or altered from any source 00022 distribution. 00023 */ 00024 00031 #ifndef __TOKENLIST_H 00032 #define __TOKENLIST_H 00033 00034 #include "lex_util.h" 00035 #include "lex_token.h" 00036 00037 namespace TinyXPath 00038 { 00039 00045 class token_list 00046 { 00047 protected : 00049 lex_token * ltp_first; 00051 lex_token * ltp_last; 00054 lex_token * ltp_current; 00055 public : 00057 token_list () 00058 { 00059 ltp_first = new lex_token (lex_null, NULL, 0); 00060 ltp_last = ltp_first; 00061 ltp_first -> v_set_prev (ltp_first); 00062 ltp_first -> v_set_next (ltp_first); 00063 ltp_current = NULL; 00064 } 00066 virtual ~ token_list () 00067 { 00068 ltp_current = ltp_first -> ltp_get_next (); 00069 while (ltp_current -> o_is_valid ()) 00070 v_delete_current (); 00071 delete ltp_first; 00072 } 00074 void v_add_token (lexico l_in_enum, const _byte_ * bp_in_value, unsigned u_in_size) 00075 { 00076 lex_token * ltp_new; 00077 00078 ltp_new = new lex_token (l_in_enum, bp_in_value, u_in_size); 00079 ltp_last -> v_set_next (ltp_new); 00080 ltp_new -> v_set_next (ltp_first); 00081 ltp_first -> v_set_prev (ltp_new); 00082 ltp_new -> v_set_prev (ltp_last); 00083 ltp_last = ltp_new; 00084 } 00085 00087 void v_set_current_top () 00088 { 00089 ltp_current = ltp_first -> ltp_get_next (1); 00090 } 00091 00093 void v_set_current (lex_token * ltp_cur) 00094 { 00095 ltp_current = ltp_cur; 00096 } 00097 00099 lex_token * ltp_freeze () 00100 { 00101 return ltp_current; 00102 } 00103 00105 lex_token * ltp_get (int i_offset) 00106 { 00107 if (! ltp_current) 00108 return NULL; 00109 return ltp_current -> ltp_get_next (i_offset); 00110 } 00111 00113 void v_inc_current (int i_rel) 00114 { 00115 if (! ltp_current) 00116 return; 00117 ltp_current = ltp_current -> ltp_get_next (i_rel); 00118 } 00119 00121 void v_replace_current (lexico lex_in, const char * cp_rep) 00122 { 00123 if (! ltp_current) 00124 return; 00125 ltp_current -> v_set (lex_in, cp_rep); 00126 } 00127 00129 void v_delete_current () 00130 { 00131 lex_token * ltp_temp; 00132 00133 assert (ltp_current); 00134 ltp_temp = ltp_current; 00135 ltp_temp -> ltp_get_prev () -> v_set_next (ltp_temp -> ltp_get_next ()); 00136 ltp_temp -> ltp_get_next () -> v_set_prev (ltp_temp -> ltp_get_prev ()); 00137 ltp_current = ltp_temp -> ltp_get_next (); 00138 delete ltp_temp; 00139 } 00140 00142 void v_delete_next () 00143 { 00144 lex_token * ltp_temp; 00145 00146 assert (ltp_current); 00147 ltp_temp = ltp_current -> ltp_get_next (); 00148 ltp_current -> v_set_next (ltp_temp -> ltp_get_next ()); 00149 ltp_temp -> ltp_get_next () -> v_set_prev (ltp_current); 00150 delete ltp_temp; 00151 } 00152 void v_tokenize_expression (); 00153 } ; 00154 00155 } 00156 00157 #endif