OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
CharInputBuffer.hpp
1#ifndef INC_CharInputBuffer_hpp__
2# define INC_CharInputBuffer_hpp__
3
4/* ANTLR Translator Generator
5 * Project led by Terence Parr at http://www.jGuru.com
6 * Software rights: http://www.antlr.org/license.html
7 *
8 * $Id$
9 */
10
11# include <antlr/config.hpp>
12# include <antlr/InputBuffer.hpp>
13
14# ifdef HAS_NOT_CCTYPE_H
15# include <ctype.h>
16# else
17# include <cctype>
18# endif
19
20#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
21namespace antlr {
22#endif
23
24/** CharInputBuffer.hpp provides an InputBuffer for plain character arrays (buffers).
25 */
27{
28public:
29 /** Construct a CharInputBuffer.hpp object with a char* buffer of 'size'
30 * if 'owner' is true, then the buffer will be delete[]-ed on destruction.
31 * @note it is assumed the buffer was allocated with new[]!
32 */
33 CharInputBuffer( unsigned char* buf, size_t size, bool owner = false )
34 : buffer(buf)
35 , ptr(buf)
36 , end(buf + size)
37 , delete_buffer(owner)
38 {
39 }
40
41 /** Destructor
42 * @note If you're using malloced data, then you probably need to change
43 * this destructor. Or better use this class as template for your own.
44 */
46 {
47 if( delete_buffer && buffer )
48 delete [] buffer;
49 }
50
51 /** Reset the CharInputBuffer to initial state
52 * Called from LexerInputState::reset.
53 * @see LexerInputState
54 */
55 virtual inline void reset( void )
56 {
58 ptr = buffer;
59 }
60
61 virtual int getChar( void )
62 {
63 return (ptr < end) ? *ptr++ : EOF;
64 }
65
66protected:
67 unsigned char* buffer; ///< the buffer with data
68 unsigned char* ptr; ///< position ptr into the buffer
69 unsigned char* end; ///< end sentry for buffer
70 bool delete_buffer; ///< flag signifying if we have to delete the buffer
71};
72
73#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
74}
75#endif
76
77#endif
CharInputBuffer.hpp provides an InputBuffer for plain character arrays (buffers).
unsigned char * ptr
position ptr into the buffer
virtual void reset(void)
Reset the CharInputBuffer to initial state Called from LexerInputState::reset.
virtual int getChar(void)
Override this in subclasses to get the next character.
unsigned char * buffer
the buffer with data
bool delete_buffer
flag signifying if we have to delete the buffer
~CharInputBuffer(void)
Destructor.
CharInputBuffer(unsigned char *buf, size_t size, bool owner=false)
Construct a CharInputBuffer.hpp object with a char* buffer of 'size' if 'owner' is true,...
unsigned char * end
end sentry for buffer
A Stream of characters fed to the lexer from a InputStream that can be rewound via mark()/rewind() me...
virtual void reset(void)
Reset the input buffer to empty state.