ANTLR Support Libraries 2.7.1+
antlr/TokenBuffer.hpp
Go to the documentation of this file.
00001 #ifndef INC_TokenBuffer_hpp__
00002 #define INC_TokenBuffer_hpp__
00003 
00004 /* ANTLR Translator Generator
00005  * Project led by Terence Parr at http://www.jGuru.com
00006  * Software rights: http://www.antlr.org/license.html
00007  *
00008  * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/TokenBuffer.hpp#2 $
00009  */
00010 
00011 #include <antlr/config.hpp>
00012 #include <antlr/TokenStream.hpp>
00013 #include <antlr/CircularQueue.hpp>
00014 
00015 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00016 namespace antlr {
00017 #endif
00018 
00036 class ANTLR_API TokenBuffer {
00037 public:
00039    TokenBuffer(TokenStream& input_);
00040    virtual ~TokenBuffer();
00041 
00043    inline void reset( void )
00044    {
00045       nMarkers = 0;
00046       markerOffset = 0;
00047       numToConsume = 0;
00048       queue.clear();
00049    }
00050 
00052    int LA( unsigned int i );
00053 
00055    RefToken LT( unsigned int i );
00056 
00060    unsigned int mark();
00061 
00065    void rewind(unsigned int mark);
00066 
00068    inline void consume()
00069    {
00070       numToConsume++;
00071    }
00072 
00074    virtual unsigned int entries() const;
00075 
00076 private:
00078    void fill(unsigned int amount);
00080    void syncConsume();
00081 
00082 protected:
00084    TokenStream& input;
00085 
00087    unsigned int nMarkers;
00088 
00090    unsigned int markerOffset;
00091 
00093    unsigned int numToConsume;
00094 
00096    CircularQueue<RefToken> queue;
00097 
00098 private:
00099    TokenBuffer(const TokenBuffer& other);
00100    const TokenBuffer& operator=(const TokenBuffer& other);
00101 };
00102 
00104 inline void TokenBuffer::syncConsume()
00105 {
00106    if (numToConsume > 0)
00107    {
00108       if (nMarkers > 0)
00109          markerOffset += numToConsume;
00110       else
00111          queue.removeItems( numToConsume );
00112 
00113       numToConsume = 0;
00114    }
00115 }
00116 
00117 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00118 }
00119 #endif
00120 
00121 #endif //INC_TokenBuffer_hpp__
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines