Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CircularQueue.hpp

Go to the documentation of this file.
00001 #ifndef INC_CircularQueue_hpp__
00002 #define INC_CircularQueue_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: CircularQueue.hpp,v 1.1 2004/10/08 16:27:34 dfisher Exp $
00009  */
00010 
00011 #include <antlr/config.hpp>
00012 #include <antlr/Token.hpp>
00013 #include <vector>
00014 
00015 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00016 namespace antlr {
00017 #endif
00018 
00019 // Resize every 5000 items
00020 #define OFFSET_MAX_RESIZE 5000
00021 
00022 template <class T>
00023 class ANTLR_API CircularQueue {
00024 public:
00025         CircularQueue()
00026         : storage()
00027         , m_offset(0)
00028         {
00029         }
00030         ~CircularQueue()
00031         {
00032         }
00033 
00035         inline void clear( void )
00036         {
00037                 m_offset = 0;
00038                 storage.clear();
00039         }
00040 
00042         inline T elementAt( unsigned int idx ) const
00043         {
00044                 return storage[idx+m_offset];
00045         }
00046         void removeFirst()
00047         {
00048                 if (m_offset >= OFFSET_MAX_RESIZE)
00049                 {
00050                         storage.erase( storage.begin(), storage.begin() + m_offset + 1 );
00051                         m_offset = 0;
00052                 }
00053                 else
00054                         ++m_offset;
00055         }
00056         inline void removeItems( unsigned int nb )
00057         {
00058                 if (m_offset >= OFFSET_MAX_RESIZE)
00059                 {
00060                         storage.erase( storage.begin(), storage.begin() + m_offset + nb );
00061                         m_offset = 0;
00062                 }
00063                 else
00064                         m_offset += nb;
00065         }
00066         inline void append(const T& t)
00067         {
00068                 storage.push_back(t);
00069         }
00070         inline unsigned int entries() const
00071         {
00072                 return storage.size() - m_offset;
00073         }
00074 
00075 private:
00076         typename ANTLR_USE_NAMESPACE(std)vector<T> storage;
00077         unsigned int m_offset;
00078 
00079         CircularQueue(const CircularQueue&);
00080         const CircularQueue& operator=(const CircularQueue&);
00081 };
00082 
00083 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00084 }
00085 #endif
00086 
00087 #endif //INC_CircularQueue_hpp__

Generated on Wed Nov 3 12:58:52 2004 for Lemur Toolkit by doxygen1.2.18