ddc
byte_stream.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 #ifndef __TINYBYTESTREAM_H
25 #define __TINYBYTESTREAM_H
26 
27 #include <string.h>
28 #include "lex_util.h"
29 
30 namespace TinyXPath
31 {
32 
38 {
40  unsigned u_length;
48  bool o_valid;
49 public :
51  byte_stream (const char * cp_in)
52  {
53  u_length = strlen (cp_in) + 1;
54  bp_in = new _byte_ [u_length] ;
55  memcpy (bp_in, cp_in, u_length);
56  bp_current = bp_in;
57  bp_end = bp_in + u_length - 1;
58  o_valid = (bp_current != bp_end);
59  }
62  {
63  if (bp_in)
64  delete [] bp_in;
65  }
68  {
69  return * bp_current;
70  }
73  {
74  if (! o_is_valid ())
75  return 0;
76  bp_current++;
77  o_valid = (bp_current != bp_end);
78  return * (bp_current - 1);
79  }
81  bool o_is_valid ()
82  {
83  return o_valid;
84  }
86  unsigned u_remain ()
87  {
88  return (unsigned) (bp_end - bp_current);
89  }
91  _byte_ b_forward (unsigned u_nb_char)
92  {
93  if (u_remain () > u_nb_char)
94  return bp_current [u_nb_char];
95  return 0;
96  }
98  const _byte_ * bp_get_backward (unsigned u_amount)
99  {
100  return bp_current - u_amount + 1;
101  }
102 } ;
103 
104 }
105 
106 #endif
107 
108 /*--- emacs style variables ---
109  * Local Variables:
110  * mode: C++
111  * c-file-style: "ellemtel"
112  * c-basic-offset: 4
113  * tab-width: 8
114  * indent-tabs-mode: nil
115  * End:
116  */
_byte_ b_top()
Returns the byte on top.
Definition: byte_stream.h:67
_byte_ b_forward(unsigned u_nb_char)
peek a byte a little further down the stream
Definition: byte_stream.h:91
unsigned u_remain()
number of bytes still to consume
Definition: byte_stream.h:86
Definition: action_store.cpp:32
_byte_ * bp_current
Current read position.
Definition: byte_stream.h:44
unsigned char _byte_
Definition: lex_util.h:44
~ byte_stream()
destructor
Definition: byte_stream.h:61
_byte_ * bp_in
Total string.
Definition: byte_stream.h:42
_byte_ * bp_end
First invalid position.
Definition: byte_stream.h:46
bool o_is_valid()
true if there are still some byte to consume
Definition: byte_stream.h:81
unsigned u_length
Length of the total string, + 1.
Definition: byte_stream.h:40
byte_stream(const char *cp_in)
constructor
Definition: byte_stream.h:51
const _byte_ * bp_get_backward(unsigned u_amount)
get a byte backward pointer to the stream
Definition: byte_stream.h:98
bool o_valid
true when there are still some byte to read
Definition: byte_stream.h:48
_byte_ b_pop()
Consumes one byte.
Definition: byte_stream.h:72
Definition: byte_stream.h:37