~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/antlr/antlr/CharInputBuffer.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/RIGHTS.html
 
7
 *
 
8
 */
 
9
 
 
10
# include <antlr/config.hpp>
 
11
# include <antlr/InputBuffer.hpp>
 
12
 
 
13
# ifdef HAS_NOT_CCTYPE_H
 
14
#       include <ctype.h>
 
15
# else
 
16
#       include <cctype>
 
17
# endif
 
18
 
 
19
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
 
20
namespace antlr {
 
21
#endif
 
22
 
 
23
/** CharInputBuffer.hpp provides an InputBuffer for plain character arrays (buffers).
 
24
 */
 
25
class CharInputBuffer : public InputBuffer
 
26
{
 
27
public:
 
28
        /** Construct a CharInputBuffer.hpp object with a char* buffer of 'size'
 
29
         * if 'owner' is true, then the buffer will be delete[]-ed on destruction.
 
30
         * @note it is assumed the buffer was allocated with new[]!
 
31
         */
 
32
        CharInputBuffer( unsigned char* buf, size_t size, bool owner = false )
 
33
        : buffer(buf)
 
34
        , ptr(buf)
 
35
        , end(buf + size)
 
36
        , delete_buffer(owner)
 
37
        {
 
38
        }
 
39
 
 
40
        /** Destructor
 
41
         * @note If you're using malloced data, then you probably need to change
 
42
         * this destructor. Or better use this class as template for your own.
 
43
         */
 
44
        ~CharInputBuffer( void )
 
45
        {
 
46
                if( delete_buffer && buffer )
 
47
                        delete [] buffer;
 
48
        }
 
49
 
 
50
        /** Reset the CharInputBuffer to initial state
 
51
         * Called from LexerInputState::reset.
 
52
         * @see LexerInputState
 
53
         */
 
54
        virtual inline void reset( void )
 
55
        {
 
56
                InputBuffer::reset();
 
57
                ptr = buffer;
 
58
        }
 
59
 
 
60
        virtual int getChar( void )
 
61
        {
 
62
                return (ptr < end) ? *ptr++ : EOF;
 
63
        }
 
64
 
 
65
protected:
 
66
        unsigned char* buffer;  ///< the buffer with data
 
67
        unsigned char* ptr;             ///< position ptr into the buffer
 
68
        unsigned char* end;             ///< end sentry for buffer
 
69
        bool delete_buffer;             ///< flag signifying if we have to delete the buffer
 
70
};
 
71
 
 
72
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
 
73
}
 
74
#endif
 
75
 
 
76
#endif