1 #ifndef INC_CircularQueue_hpp__
2 #define INC_CircularQueue_hpp__
4 /* ANTLR Translator Generator
5 * Project led by Terence Parr at http://www.jGuru.com
6 * Software rights: http://www.antlr.org/license.html
8 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/CircularQueue.hpp#2 $
11 #include <antlr/config.hpp>
12 #include <antlr/Token.hpp>
16 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
20 // Resize every 5000 items
21 #define OFFSET_MAX_RESIZE 5000
24 class ANTLR_API CircularQueue {
36 inline void clear( void )
42 /// @todo this should use at or should have a check
43 inline T elementAt( size_t idx ) const
45 return storage[idx+m_offset];
49 if (m_offset >= OFFSET_MAX_RESIZE)
51 storage.erase( storage.begin(), storage.begin() + m_offset + 1 );
57 inline void removeItems( size_t nb )
59 // it would be nice if we would not get called with nb > entries
60 // (or to be precise when entries() == 0)
61 // This case is possible when lexer/parser::recover() calls
62 // consume+consumeUntil when the queue is empty.
63 // In recover the consume says to prepare to read another
64 // character/token. Then in the subsequent consumeUntil the
65 // LA() call will trigger
66 // syncConsume which calls this method *before* the same queue
67 // has been sufficiently filled.
71 if (m_offset >= OFFSET_MAX_RESIZE)
73 storage.erase( storage.begin(), storage.begin() + m_offset + nb );
79 inline void append(const T& t)
83 inline size_t entries() const
85 return storage.size() - m_offset;
89 ANTLR_USE_NAMESPACE(std)vector<T> storage;
92 CircularQueue(const CircularQueue&);
93 const CircularQueue& operator=(const CircularQueue&);
96 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
100 #endif //INC_CircularQueue_hpp__