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 #ifndef __TINYBYTESTREAM_H 00025 #define __TINYBYTESTREAM_H 00026 00027 #include <string.h> 00028 #include "lex_util.h" 00029 00030 namespace TinyXPath 00031 { 00032 00037 class byte_stream 00038 { 00040 unsigned u_length; 00042 _byte_ * bp_in; 00044 _byte_ * bp_current; 00046 _byte_ * bp_end; 00048 bool o_valid; 00049 public : 00051 byte_stream (const char * cp_in) 00052 { 00053 u_length = strlen (cp_in) + 1; 00054 bp_in = new _byte_ [u_length] ; 00055 memcpy (bp_in, cp_in, u_length); 00056 bp_current = bp_in; 00057 bp_end = bp_in + u_length - 1; 00058 o_valid = (bp_current != bp_end); 00059 } 00061 ~ byte_stream () 00062 { 00063 if (bp_in) 00064 delete [] bp_in; 00065 } 00067 _byte_ b_top () 00068 { 00069 return * bp_current; 00070 } 00072 _byte_ b_pop () 00073 { 00074 if (! o_is_valid ()) 00075 return 0; 00076 bp_current++; 00077 o_valid = (bp_current != bp_end); 00078 return * (bp_current - 1); 00079 } 00081 bool o_is_valid () 00082 { 00083 return o_valid; 00084 } 00086 unsigned u_remain () 00087 { 00088 return (unsigned) (bp_end - bp_current); 00089 } 00091 _byte_ b_forward (unsigned u_nb_char) 00092 { 00093 if (u_remain () > u_nb_char) 00094 return bp_current [u_nb_char]; 00095 return 0; 00096 } 00098 const _byte_ * bp_get_backward (unsigned u_amount) 00099 { 00100 return bp_current - u_amount + 1; 00101 } 00102 } ; 00103 00104 } 00105 00106 #endif