OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
InputBuffer.cpp
1/* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
4 *
5 * $Id$
6 */
7
8#include "antlr/config.hpp"
9#include "antlr/InputBuffer.hpp"
10#include <iostream>
11#ifdef IS_MPI
12#include "mpi.h"
13#endif
14
15
16#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
17namespace antlr {
18#endif
19
20/** Ensure that the character buffer is sufficiently full */
21void InputBuffer::fill(unsigned int amount)
22{
24
25 // Fill the buffer sufficiently to hold needed characters
26 while (queue.entries() < amount + markerOffset)
27 {
28 // Append the next character
29 queue.append(getChar());
30 }
31}
32
33/** get the current lookahead characters as a string
34 * @warning it may treat 0 and EOF values wrong
35 */
36ANTLR_USE_NAMESPACE(std)string InputBuffer::getLAChars( void ) const
37{
38 ANTLR_USE_NAMESPACE(std)string ret;
39
40 for(unsigned int i = markerOffset; i < queue.entries(); i++)
41 ret += queue.elementAt(i);
42
43 return ret;
44}
45
46/** get the current marked characters as a string
47 * @warning it may treat 0 and EOF values wrong
48 */
49ANTLR_USE_NAMESPACE(std)string InputBuffer::getMarkedChars( void ) const
50{
51 ANTLR_USE_NAMESPACE(std)string ret;
52
53 for(unsigned int i = 0; i < markerOffset; i++)
54 ret += queue.elementAt(i);
55
56 return ret;
57}
58
59/** Return an integer marker that can be used to rewind the buffer to
60 * its current state.
61 */
62unsigned int InputBuffer::mark()
63{
65 nMarkers++;
66 return markerOffset;
67}
68
69/** Rewind the character buffer to a marker.
70 * @param mark Marker returned previously from mark()
71 */
72void InputBuffer::rewind(unsigned int mark)
73{
75 markerOffset = mark;
76 nMarkers--;
77}
78
79unsigned int InputBuffer::entries() const
80{
81 //assert(queue.entries() >= markerOffset);
82 return queue.entries() - markerOffset;
83}
84
85#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
86}
87#endif
std::string getMarkedChars() const
get the current marked characters as a string
virtual unsigned int entries() const
Get the number of non-consumed characters.
void syncConsume()
Sync up deferred consumption.
virtual void fill(unsigned int amount)
Ensure that the character buffer is sufficiently full.
virtual void rewind(unsigned int mark)
Rewind the character buffer to a marker.
virtual unsigned int mark()
Return an integer marker that can be used to rewind the buffer to its current state.
virtual int getChar()=0
Override this in subclasses to get the next character.
std::string getLAChars() const
get the current lookahead characters as a string