<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>ANTLR Support Libraries 2.7.1+: antlr/CircularQueue.hpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/search.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body onload='searchBox.OnSelectItem(0);'> <!-- Generated by Doxygen 1.7.3 --> <script type="text/javascript"><!-- var searchBox = new SearchBox("searchBox", "search",false,'Search'); --></script> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">ANTLR Support Libraries 2.7.1+</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li id="searchli"> <div id="MSearchBox" class="MSearchBoxInactive"> <span class="left"> <img id="MSearchSelect" src="search/mag_sel.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/> <input type="text" id="MSearchField" value="Search" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/> </span><span class="right"> <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> </span> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <h1>antlr/CircularQueue.hpp</h1> </div> </div> <div class="contents"> <a href="CircularQueue_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef INC_CircularQueue_hpp__</span> <a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define INC_CircularQueue_hpp__</span> <a name="l00003"></a>00003 <span class="preprocessor"></span> <a name="l00004"></a>00004 <span class="comment">/* ANTLR Translator Generator</span> <a name="l00005"></a>00005 <span class="comment"> * Project led by Terence Parr at http://www.jGuru.com</span> <a name="l00006"></a>00006 <span class="comment"> * Software rights: http://www.antlr.org/license.html</span> <a name="l00007"></a>00007 <span class="comment"> *</span> <a name="l00008"></a>00008 <span class="comment"> * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/CircularQueue.hpp#2 $</span> <a name="l00009"></a>00009 <span class="comment"> */</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="preprocessor">#include <antlr/config.hpp></span> <a name="l00012"></a>00012 <span class="preprocessor">#include <antlr/Token.hpp></span> <a name="l00013"></a>00013 <span class="preprocessor">#include <vector></span> <a name="l00014"></a>00014 <span class="preprocessor">#include <cassert></span> <a name="l00015"></a>00015 <a name="l00016"></a>00016 <span class="preprocessor">#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE</span> <a name="l00017"></a>00017 <span class="preprocessor"></span><span class="keyword">namespace </span>antlr { <a name="l00018"></a>00018 <span class="preprocessor">#endif</span> <a name="l00019"></a>00019 <span class="preprocessor"></span> <a name="l00020"></a>00020 <span class="comment">// Resize every 5000 items</span> <a name="l00021"></a><a class="code" href="CircularQueue_8hpp.html#a2c874482105b2020baa78b12090c5eaa">00021</a> <span class="preprocessor">#define OFFSET_MAX_RESIZE 5000</span> <a name="l00022"></a>00022 <span class="preprocessor"></span> <a name="l00023"></a>00023 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00024"></a><a class="code" href="classCircularQueue.html">00024</a> <span class="keyword">class </span><a class="code" href="config_8hpp.html#ad583892c7af76867441115e41aa1ce52">ANTLR_API</a> <a class="code" href="classCircularQueue.html">CircularQueue</a> { <a name="l00025"></a>00025 <span class="keyword">public</span>: <a name="l00026"></a><a class="code" href="classCircularQueue.html#afb497745b3a1e472ec670345328301a3">00026</a> <a class="code" href="classCircularQueue.html">CircularQueue</a>() <a name="l00027"></a>00027 : storage() <a name="l00028"></a>00028 , m_offset(0) <a name="l00029"></a>00029 { <a name="l00030"></a>00030 } <a name="l00031"></a><a class="code" href="classCircularQueue.html#ae983345f91859f4d532749f0b44531df">00031</a> ~<a class="code" href="classCircularQueue.html">CircularQueue</a>() <a name="l00032"></a>00032 { <a name="l00033"></a>00033 } <a name="l00034"></a>00034 <a name="l00036"></a><a class="code" href="classCircularQueue.html#ad7e561e9d933428f8192caeac1a08799">00036</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> clear( <span class="keywordtype">void</span> ) <a name="l00037"></a>00037 { <a name="l00038"></a>00038 m_offset = 0; <a name="l00039"></a>00039 storage.<a class="code" href="classCircularQueue.html#ad7e561e9d933428f8192caeac1a08799" title="Clear the queue.">clear</a>(); <a name="l00040"></a>00040 } <a name="l00041"></a>00041 <a name="l00043"></a><a class="code" href="classCircularQueue.html#a38caa093ffd155a2a1b44cdad175a159">00043</a> <span class="keyword">inline</span> T elementAt( <span class="keywordtype">size_t</span> idx )<span class="keyword"> const</span> <a name="l00044"></a>00044 <span class="keyword"> </span>{ <a name="l00045"></a>00045 <span class="keywordflow">return</span> storage[idx+m_offset]; <a name="l00046"></a>00046 } <a name="l00047"></a><a class="code" href="classCircularQueue.html#a6cb5b4274276ba1f68c57d7fe5aa4564">00047</a> <span class="keywordtype">void</span> removeFirst() <a name="l00048"></a>00048 { <a name="l00049"></a>00049 <span class="keywordflow">if</span> (m_offset >= <a class="code" href="CircularQueue_8hpp.html#a2c874482105b2020baa78b12090c5eaa">OFFSET_MAX_RESIZE</a>) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 storage.erase( storage.begin(), storage.begin() + m_offset + 1 ); <a name="l00052"></a>00052 m_offset = 0; <a name="l00053"></a>00053 } <a name="l00054"></a>00054 <span class="keywordflow">else</span> <a name="l00055"></a>00055 ++m_offset; <a name="l00056"></a>00056 } <a name="l00057"></a><a class="code" href="classCircularQueue.html#a28c7ee9875555136b7fb9e45c62a1815">00057</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> removeItems( <span class="keywordtype">size_t</span> nb ) <a name="l00058"></a>00058 { <a name="l00059"></a>00059 <span class="comment">// it would be nice if we would not get called with nb > entries</span> <a name="l00060"></a>00060 <span class="comment">// (or to be precise when entries() == 0)</span> <a name="l00061"></a>00061 <span class="comment">// This case is possible when lexer/parser::recover() calls</span> <a name="l00062"></a>00062 <span class="comment">// consume+consumeUntil when the queue is empty.</span> <a name="l00063"></a>00063 <span class="comment">// In recover the consume says to prepare to read another</span> <a name="l00064"></a>00064 <span class="comment">// character/token. Then in the subsequent consumeUntil the</span> <a name="l00065"></a>00065 <span class="comment">// LA() call will trigger</span> <a name="l00066"></a>00066 <span class="comment">// syncConsume which calls this method *before* the same queue</span> <a name="l00067"></a>00067 <span class="comment">// has been sufficiently filled.</span> <a name="l00068"></a>00068 <span class="keywordflow">if</span>( nb > entries() ) <a name="l00069"></a>00069 nb = entries(); <a name="l00070"></a>00070 <a name="l00071"></a>00071 <span class="keywordflow">if</span> (m_offset >= <a class="code" href="CircularQueue_8hpp.html#a2c874482105b2020baa78b12090c5eaa">OFFSET_MAX_RESIZE</a>) <a name="l00072"></a>00072 { <a name="l00073"></a>00073 storage.erase( storage.begin(), storage.begin() + m_offset + nb ); <a name="l00074"></a>00074 m_offset = 0; <a name="l00075"></a>00075 } <a name="l00076"></a>00076 <span class="keywordflow">else</span> <a name="l00077"></a>00077 m_offset += nb; <a name="l00078"></a>00078 } <a name="l00079"></a><a class="code" href="classCircularQueue.html#ae7f30d29129bd056a7117901c20be924">00079</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> append(<span class="keyword">const</span> T& t) <a name="l00080"></a>00080 { <a name="l00081"></a>00081 storage.push_back(t); <a name="l00082"></a>00082 } <a name="l00083"></a><a class="code" href="classCircularQueue.html#af939afde7102473828ee9da6f7a10bd2">00083</a> <span class="keyword">inline</span> <span class="keywordtype">size_t</span> entries()<span class="keyword"> const</span> <a name="l00084"></a>00084 <span class="keyword"> </span>{ <a name="l00085"></a>00085 <span class="keywordflow">return</span> storage.size() - m_offset; <a name="l00086"></a>00086 } <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="keyword">private</span>: <a name="l00089"></a><a class="code" href="classCircularQueue.html#aef165383492ff44aa130d7c44e4885ab">00089</a> <a class="code" href="config_8hpp.html#ad1e4025d0db4046e6e85a46c92b7ff77">ANTLR_USE_NAMESPACE</a>(std)vector<T> storage; <a name="l00090"></a><a class="code" href="classCircularQueue.html#af8dc3a77badf84dae16a324d771afdee">00090</a> <span class="keywordtype">size_t</span> m_offset; <a name="l00091"></a>00091 <a name="l00092"></a>00092 <a class="code" href="classCircularQueue.html">CircularQueue</a>(const <a class="code" href="classCircularQueue.html">CircularQueue</a>&); <a name="l00093"></a>00093 const CircularQueue& operator=(const CircularQueue&); <a name="l00094"></a>00094 }; <a name="l00095"></a>00095 <a name="l00096"></a>00096 <span class="preprocessor">#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE</span> <a name="l00097"></a>00097 <span class="preprocessor"></span>} <a name="l00098"></a>00098 <span class="preprocessor">#endif</span> <a name="l00099"></a>00099 <span class="preprocessor"></span> <a name="l00100"></a>00100 <span class="preprocessor">#endif //INC_CircularQueue_hpp__</span> </pre></div></div> </div> <!--- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Defines</a></div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <hr class="footer"/><address class="footer"><small>Generated on Fri Mar 25 2011 for ANTLR Support Libraries 2.7.1+ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address> </body> </html>