Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 3ebaf504d69f581a8834e53e04e712a5 > files > 99

gearbox-devel-9.11-6.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>GearBox Project</title>

<link rel="icon" href="gbx_icon_cardbox_sky.png" type="image/png">
<link rel="shortcut icon" href="gbx_icon_cardbox_sky.png" type="image/png">

<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<!-- Google Analytics -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3583782-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- Returning you to your regular programming -->
</head><body>

<!-- Header -->

<table border="0" cellspacing="0" cellpadding="0">

<tr><!-- create row -->

<!-- spacer cell -->
<!-- #CC CC CC -->
<td rowspan="1" colspan="1" bgcolor="#EEEEEE">&nbsp;&nbsp;&nbsp;&nbsp;</td>

<!-- menu cell -->
<td width="170" rowspan="1" colspan="1" align="left" valign="top" bgcolor="#EEEEEE">


<p>&nbsp;</p>
<p align="center"><a href="index.html"><img src="gbx_logo_cardbox_sky_150x150.png"></a></p><br>

<strong>INTRODUCTION</strong><br>
<strong><a href="gbx_doc_overview.html" style="text-decoration:none">Overview</a></strong><br>
<strong><a href="gbx_doc_getting.html" style="text-decoration:none">Download and Install</a></strong><br>
<!-- <strong><a href="gbx_doc_quickstart.html" style="text-decoration:none">Quick Start</a></strong><br> -->
<strong><a href="gbx_doc_documentation.html" style="text-decoration:none">Documentation</a></strong><br>
<strong><a href="gbx_doc_publications.html" style="text-decoration:none">Publications</a></strong><br>
<br>

<strong>REPOSITORY</strong><br>
<strong><a href="group__gbx__libs.html" style="text-decoration:none">Libraries</a></strong><br>
<!-- <strong><a href="group__gbx__utils.html" style="text-decoration:none">Utilities</a></strong><br> -->
<br>

<strong>DEVELOPER</strong><br>

<!--<strong><a href="gbx_doc_tutorials.html" style="text-decoration:none">Tutorials</a></strong><br>
<strong><a href="group__gbx__examples.html" style="text-decoration:none">Examples</a></strong><br>-->
<strong><a href="gbx_doc_devguide.html" style="text-decoration:none">Dev Guide</a></strong><br>
<!-- 
<strong><a href="gbx_doc_faq.html" style="text-decoration:none">FAQ</a></strong><br>
-->
<strong><a href="http://cdash.acfr.usyd.edu.au/index.php?project=Gearbox" style="text-decoration:none">Dashboard</a></strong><br>
<!--<strong><a href="http://wiki2.cas.edu.au/orca">Wiki</a></strong><br>
login/pass: orca/orca<br>-->
<br>

<strong>PEOPLE</strong><br>
<strong><a href="gbx_doc_contributors.html" style="text-decoration:none">Contributors</a></strong><br>
<strong><a href="gbx_doc_users.html" style="text-decoration:none">Users</a></strong><br>
<br>

<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=216468&amp;type=2" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a><br>
<strong><a href="http://sourceforge.net/projects/gearbox">Project</a></strong><br>
<strong><a href="http://sourceforge.net/project/showfiles.php?group_id=216468">Download</a></strong><br>
<!--<strong><a href="http://sourceforge.net/tracker/?group_id=216468">Bugs/Feedback</a></strong><br>-->
<strong><a href="http://sourceforge.net/mail/?group_id=216468">Mailing lists</a></strong></p>
<p>&nbsp;</p>

</td><!-- /menu cell -->

<!-- one grey spacer cells -->
<td rowspan="1" colspan="1" bgcolor="#EEEEEE">&nbsp;&nbsp;&nbsp;&nbsp;</td>

<!-- one white spacer cells -->
<td rowspan="1" colspan="1">&nbsp;&nbsp;&nbsp;&nbsp;</td>

<!-- main content cell -->
<td rowspan="1" colspan="1" align="left" valign="top">


<!-- Generated by Doxygen 1.6.2-20100208 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</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><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b8ba9ebcb71a95a44c4fd60b7d348fe1.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_e6faee39d20d45fac309cc35f2ddb285.html">gbxsickacfr</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_40c823cb7c24b596a1e1c0c483dfcd86.html">gbxiceutilacfr</a>
  </div>
</div>
<div class="contents">
<h1>buffer.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics</span>
<a name="l00003"></a>00003 <span class="comment"> *               http://gearbox.sf.net/</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * This distribution is licensed to you under the terms described in</span>
<a name="l00007"></a>00007 <span class="comment"> * the LICENSE file included in this distribution.</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#ifndef GBXICEUTILACFR_BUFFER_H</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="preprocessor">#define GBXICEUTILACFR_BUFFER_H</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;queue&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;gbxutilacfr/exceptions.h&gt;</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;IceUtil/Monitor.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;IceUtil/Mutex.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;IceUtil/Time.h&gt;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="namespacegbxiceutilacfr.html">00021</a> <span class="keyword">namespace </span>gbxiceutilacfr {
<a name="l00022"></a>00022 
<a name="l00024"></a><a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58">00024</a> <span class="keyword">enum</span> <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a>
<a name="l00025"></a>00025 {
<a name="l00028"></a><a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58a1d1af4db5a6306ef8ff06731810ea9b1">00028</a>     <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58a1d1af4db5a6306ef8ff06731810ea9b1">BufferTypeCircular</a>,
<a name="l00031"></a><a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58aace9508a711e08bfb1ee4c2ad809b68c">00031</a>     <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58aace9508a711e08bfb1ee4c2ad809b68c">BufferTypeQueue</a>
<a name="l00032"></a>00032 };
<a name="l00033"></a>00033 
<a name="l00044"></a>00044 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00045"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html">00045</a> <span class="keyword">class </span><a class="code" href="classgbxiceutilacfr_1_1Buffer.html" title="A thread-safe data pipe with buffer semantics.">Buffer</a> : <span class="keyword">public</span> IceUtil::Monitor&lt;IceUtil::Mutex&gt;
<a name="l00046"></a>00046 {
<a name="l00047"></a>00047 <span class="keyword">public</span>:
<a name="l00048"></a>00048 
<a name="l00055"></a>00055     <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ade9e7fbb73d6ab9efb8c46a04f06cc2c">Buffer</a>( <span class="keywordtype">int</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a68291e42a265c83d13d6715b370977ca" title="Returns buffer depth.">depth</a>, <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a9117f861cdeffa21bbe36e89a59ec3d5" title="Returns buffer type.">type</a> );
<a name="l00056"></a>00056 
<a name="l00057"></a>00057     <span class="keyword">virtual</span> ~<a class="code" href="classgbxiceutilacfr_1_1Buffer.html" title="A thread-safe data pipe with buffer semantics.">Buffer</a>();
<a name="l00058"></a>00058 
<a name="l00063"></a>00063     <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a133032d938830fd330c50af2694598e4">configure</a>( <span class="keywordtype">int</span> depth, <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> type=<a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58a1d1af4db5a6306ef8ff06731810ea9b1">BufferTypeCircular</a> );
<a name="l00064"></a>00064 
<a name="l00066"></a>00066     <span class="keywordtype">int</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a68291e42a265c83d13d6715b370977ca" title="Returns buffer depth.">depth</a>() <span class="keyword">const</span>;
<a name="l00067"></a>00067 
<a name="l00069"></a>00069     <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a9117f861cdeffa21bbe36e89a59ec3d5" title="Returns buffer type.">type</a>() <span class="keyword">const</span>;
<a name="l00070"></a>00070 
<a name="l00072"></a>00072     <span class="keywordtype">bool</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aa5187e7b11dfb84069136084a83c44c1" title="Returns FALSE if there&amp;#39;s something in the buffer.">isEmpty</a>() <span class="keyword">const</span>;
<a name="l00073"></a>00073 
<a name="l00075"></a>00075     <span class="keywordtype">int</span>  <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ad2865a87110cd362f4f4b4c96cab7ac7" title="Returns the number of items in the buffer.">size</a>() <span class="keyword">const</span>;
<a name="l00076"></a>00076 
<a name="l00078"></a>00078     <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a055045454d8463d3716cd96fd30d085e" title="Deletes all entries, makes the buffer empty.">purge</a>();
<a name="l00079"></a>00079 
<a name="l00086"></a>00086     <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ab73d1777d7a9593ece7c5935d4c1ffd2">push</a>( <span class="keyword">const</span> Type &amp; obj );
<a name="l00087"></a>00087 
<a name="l00092"></a>00092     <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a8ae4213513399b95d9c7e68bdab1e57a">pop</a>();
<a name="l00093"></a>00093 
<a name="l00100"></a>00100     <span class="keywordtype">void</span>  <span class="keyword">get</span>( Type &amp; obj ) <span class="keyword">const</span>;
<a name="l00101"></a>00101 
<a name="l00106"></a>00106     <span class="keywordtype">void</span>  <span class="keyword">get</span>( Type &amp; obj, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n ) <span class="keyword">const</span>;
<a name="l00107"></a>00107 
<a name="l00111"></a>00111     <span class="keywordtype">void</span>  <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aed2eef76f95e9a56b3bab8e3bf80d55c">getAndPop</a>( Type &amp; obj );
<a name="l00112"></a>00112 
<a name="l00124"></a>00124     <span class="keywordtype">int</span>  <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#af43d6c662de7dc14ab721a5d68a9e8fc">getWithTimeout</a>( Type &amp; obj, <span class="keywordtype">int</span> timeoutMs=-1 );
<a name="l00125"></a>00125 
<a name="l00129"></a>00129     <span class="keywordtype">int</span>  <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aa5c3d0b397d9c38add897b73e21ec1d6">getAndPopWithTimeout</a>( Type &amp; obj, <span class="keywordtype">int</span> timeoutMs=-1 );
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 <span class="keyword">protected</span>:
<a name="l00132"></a>00132     
<a name="l00133"></a>00133     <span class="comment">// The buffer itself</span>
<a name="l00134"></a>00134     std::deque&lt;Type&gt; queue_;
<a name="l00135"></a>00135 
<a name="l00136"></a>00136     <span class="comment">// Reimplement this function for non-standard types.</span>
<a name="l00137"></a>00137     <span class="keyword">virtual</span> <span class="keywordtype">void</span> internalGet( Type &amp; obj ) <span class="keyword">const</span> ;
<a name="l00138"></a>00138 
<a name="l00139"></a>00139     <span class="comment">// Reimplement this function for non-standard types.</span>
<a name="l00140"></a>00140     <span class="keyword">virtual</span> <span class="keywordtype">void</span> internalGet( Type &amp; obj, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n ) <span class="keyword">const</span> ;
<a name="l00141"></a>00141     
<a name="l00142"></a>00142     <span class="comment">// Reimplement this function for non-standard types.</span>
<a name="l00143"></a>00143     <span class="keyword">virtual</span> <span class="keywordtype">void</span> internalPush( <span class="keyword">const</span> Type &amp; obj );
<a name="l00144"></a>00144 
<a name="l00145"></a>00145 <span class="keyword">private</span>:
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     <span class="comment">// buffer depth:</span>
<a name="l00148"></a>00148     <span class="comment">//      positive numbers to specify finite depth,</span>
<a name="l00149"></a>00149     <span class="comment">//      negative numbers for infinite depth (memory size),</span>
<a name="l00150"></a>00150     <span class="comment">//      zero is undefined</span>
<a name="l00151"></a>00151     <span class="keywordtype">int</span> depth_;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">// buffer type (see type definitions in BufferType enum)</span>
<a name="l00154"></a>00154     <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> type_;
<a name="l00155"></a>00155 
<a name="l00156"></a>00156     <span class="comment">// internal implementation of getWithTimeout( obj, -1 );</span>
<a name="l00157"></a>00157     <span class="keywordtype">void</span> getWithInfiniteWait( Type &amp; obj );
<a name="l00158"></a>00158 };
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 
<a name="l00162"></a>00162 
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00165"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ade9e7fbb73d6ab9efb8c46a04f06cc2c">00165</a> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ade9e7fbb73d6ab9efb8c46a04f06cc2c">Buffer&lt;Type&gt;::Buffer</a>( <span class="keywordtype">int</span> depth, <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> type )
<a name="l00166"></a>00166     : depth_(depth),
<a name="l00167"></a>00167       type_(type)
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169     <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a055045454d8463d3716cd96fd30d085e" title="Deletes all entries, makes the buffer empty.">purge</a>();
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 
<a name="l00172"></a>00172 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00173"></a>00173 <a class="code" href="classgbxiceutilacfr_1_1Buffer.html" title="A thread-safe data pipe with buffer semantics.">Buffer&lt;Type&gt;::~Buffer</a>()
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00178"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a133032d938830fd330c50af2694598e4">00178</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a133032d938830fd330c50af2694598e4">Buffer&lt;Type&gt;::configure</a>( <span class="keywordtype">int</span> depth, <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> type )
<a name="l00179"></a>00179 {
<a name="l00180"></a>00180     <span class="comment">// all data is lost!</span>
<a name="l00181"></a>00181     <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a055045454d8463d3716cd96fd30d085e" title="Deletes all entries, makes the buffer empty.">purge</a>();
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00184"></a>00184     depth_ = depth;
<a name="l00185"></a>00185     type_ = type;
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187 
<a name="l00188"></a>00188 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00189"></a>00189 <span class="keywordtype">int</span> 
<a name="l00190"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a68291e42a265c83d13d6715b370977ca">00190</a> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a68291e42a265c83d13d6715b370977ca" title="Returns buffer depth.">Buffer&lt;Type&gt;::depth</a>()<span class="keyword"> const</span>
<a name="l00191"></a>00191 <span class="keyword"></span>{
<a name="l00192"></a>00192     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00193"></a>00193     <span class="keywordflow">return</span> depth_;
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00197"></a>00197 <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58" title="Buffer type defines behavior when the buffer is full">BufferType</a> 
<a name="l00198"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a9117f861cdeffa21bbe36e89a59ec3d5">00198</a> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a9117f861cdeffa21bbe36e89a59ec3d5" title="Returns buffer type.">Buffer&lt;Type&gt;::type</a>()<span class="keyword"> const</span>
<a name="l00199"></a>00199 <span class="keyword"></span>{
<a name="l00200"></a>00200     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00201"></a>00201     <span class="keywordflow">return</span> type_;
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00205"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a055045454d8463d3716cd96fd30d085e">00205</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a055045454d8463d3716cd96fd30d085e" title="Deletes all entries, makes the buffer empty.">Buffer&lt;Type&gt;::purge</a>()
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00208"></a>00208     queue_.resize(0);
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00212"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aa5187e7b11dfb84069136084a83c44c1">00212</a> <span class="keywordtype">bool</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aa5187e7b11dfb84069136084a83c44c1" title="Returns FALSE if there&amp;#39;s something in the buffer.">Buffer&lt;Type&gt;::isEmpty</a>()<span class="keyword"> const</span>
<a name="l00213"></a>00213 <span class="keyword"></span>{
<a name="l00214"></a>00214     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00215"></a>00215     <span class="keywordflow">return</span> queue_.empty();
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00219"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ad2865a87110cd362f4f4b4c96cab7ac7">00219</a> <span class="keywordtype">int</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ad2865a87110cd362f4f4b4c96cab7ac7" title="Returns the number of items in the buffer.">Buffer&lt;Type&gt;::size</a>()<span class="keyword"> const</span>
<a name="l00220"></a>00220 <span class="keyword"></span>{
<a name="l00221"></a>00221     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00222"></a>00222     <span class="keywordflow">return</span> queue_.size();
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00226"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a8ae4213513399b95d9c7e68bdab1e57a">00226</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a8ae4213513399b95d9c7e68bdab1e57a">Buffer&lt;Type&gt;::pop</a>()
<a name="l00227"></a>00227 {
<a name="l00228"></a>00228     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00229"></a>00229     <span class="keywordflow">if</span> ( queue_.empty() ) {
<a name="l00230"></a>00230         <span class="keywordflow">return</span>;
<a name="l00231"></a>00231     }
<a name="l00232"></a>00232     <span class="comment">// must check for empty queue above, otherwise get seg fault!</span>
<a name="l00233"></a>00233     queue_.pop_front();
<a name="l00234"></a>00234 }
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00237"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a2eb7b95fc8453ebf3801bbdf273a143c">00237</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a2eb7b95fc8453ebf3801bbdf273a143c">Buffer&lt;Type&gt;::get</a>( Type &amp;obj )<span class="keyword"> const</span>
<a name="l00238"></a>00238 <span class="keyword"></span>{
<a name="l00239"></a>00239     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00240"></a>00240     <span class="keywordflow">if</span> ( !queue_.empty() )
<a name="l00241"></a>00241     {
<a name="l00242"></a>00242         internalGet( obj );
<a name="l00243"></a>00243     }
<a name="l00244"></a>00244     <span class="keywordflow">else</span>
<a name="l00245"></a>00245     {
<a name="l00246"></a>00246         <span class="keywordflow">throw</span> <a class="code" href="classgbxutilacfr_1_1Exception.html" title="Base class for all GbxUtilAcfr exceptions.">gbxutilacfr::Exception</a>( ERROR_INFO, <span class="stringliteral">&quot;trying to read from an empty buffer.&quot;</span> );
<a name="l00247"></a>00247     }
<a name="l00248"></a>00248 }
<a name="l00249"></a>00249 
<a name="l00250"></a>00250 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00251"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#af69ea1ebcdb20bfcc1edac00e2537218">00251</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a2eb7b95fc8453ebf3801bbdf273a143c">Buffer&lt;Type&gt;::get</a>( Type &amp;obj, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n )<span class="keyword"> const</span>
<a name="l00252"></a>00252 <span class="keyword"></span>{
<a name="l00253"></a>00253     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00254"></a>00254     <span class="keywordflow">if</span> ( queue_.empty() ){
<a name="l00255"></a>00255         <span class="keywordflow">throw</span> <a class="code" href="classgbxutilacfr_1_1Exception.html" title="Base class for all GbxUtilAcfr exceptions.">gbxutilacfr::Exception</a>( ERROR_INFO, <span class="stringliteral">&quot;trying to read from an empty buffer.&quot;</span> );
<a name="l00256"></a>00256     }
<a name="l00257"></a>00257     <span class="keywordflow">else</span> <span class="keywordflow">if</span>( n &gt;= queue_.size()){
<a name="l00258"></a>00258         <span class="keywordflow">throw</span> <a class="code" href="classgbxutilacfr_1_1Exception.html" title="Base class for all GbxUtilAcfr exceptions.">gbxutilacfr::Exception</a>( ERROR_INFO, <span class="stringliteral">&quot;index out of bounds while trying to read buffer.&quot;</span> );
<a name="l00259"></a>00259     }
<a name="l00260"></a>00260     <span class="keywordflow">else</span>{
<a name="l00261"></a>00261         internalGet( obj ,n );
<a name="l00262"></a>00262     }
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00266"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aed2eef76f95e9a56b3bab8e3bf80d55c">00266</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aed2eef76f95e9a56b3bab8e3bf80d55c">Buffer&lt;Type&gt;::getAndPop</a>( Type &amp;obj )
<a name="l00267"></a>00267 {
<a name="l00268"></a>00268     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00269"></a>00269     <span class="keywordflow">if</span> ( !queue_.empty() )
<a name="l00270"></a>00270     {
<a name="l00271"></a>00271         internalGet( obj );
<a name="l00272"></a>00272     }
<a name="l00273"></a>00273     <span class="keywordflow">else</span>
<a name="l00274"></a>00274     {
<a name="l00275"></a>00275         <span class="keywordflow">throw</span> <a class="code" href="classgbxutilacfr_1_1Exception.html" title="Base class for all GbxUtilAcfr exceptions.">gbxutilacfr::Exception</a>( ERROR_INFO, <span class="stringliteral">&quot;trying to read from an empty buffer.&quot;</span> );
<a name="l00276"></a>00276     }
<a name="l00277"></a>00277     queue_.pop_front();
<a name="l00278"></a>00278 }
<a name="l00279"></a>00279 
<a name="l00280"></a>00280 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00281"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#af43d6c662de7dc14ab721a5d68a9e8fc">00281</a> <span class="keywordtype">int</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#af43d6c662de7dc14ab721a5d68a9e8fc">Buffer&lt;Type&gt;::getWithTimeout</a>( Type &amp;obj, <span class="keywordtype">int</span> timeoutMs )
<a name="l00282"></a>00282 {
<a name="l00283"></a>00283     <span class="comment">// special case: infinite wait time</span>
<a name="l00284"></a>00284     <span class="keywordflow">if</span> ( timeoutMs == -1 ) 
<a name="l00285"></a>00285     {
<a name="l00286"></a>00286         getWithInfiniteWait( obj );
<a name="l00287"></a>00287         <span class="keywordflow">return</span> 0;
<a name="l00288"></a>00288     }
<a name="l00289"></a>00289 
<a name="l00290"></a>00290     <span class="comment">// finite wait time</span>
<a name="l00291"></a>00291     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00292"></a>00292 
<a name="l00293"></a>00293     <span class="comment">// if already have data in the buffer, return it and get out</span>
<a name="l00294"></a>00294     <span class="keywordflow">if</span> ( !queue_.empty() )
<a name="l00295"></a>00295     {
<a name="l00296"></a>00296         internalGet( obj );
<a name="l00297"></a>00297         <span class="keywordflow">return</span> 0;
<a name="l00298"></a>00298     }
<a name="l00299"></a>00299 
<a name="l00300"></a>00300     <span class="comment">// empty buffer: figure out when to wake up</span>
<a name="l00301"></a>00301     <span class="comment">// notice that we are still holding the lock, so it&#39;s ok to call timedWait()</span>
<a name="l00302"></a>00302     <span class="keywordflow">if</span> (  this-&gt;timedWait( IceUtil::Time::milliSeconds( timeoutMs ) ) )  
<a name="l00303"></a>00303     {
<a name="l00304"></a>00304         <span class="comment">// someone woke us up, we are holding the lock again</span>
<a name="l00305"></a>00305         <span class="comment">// check new data again (could be a spurious wakeup)</span>
<a name="l00306"></a>00306         <span class="keywordflow">if</span> ( !queue_.empty() ) 
<a name="l00307"></a>00307         {
<a name="l00308"></a>00308             internalGet( obj );
<a name="l00309"></a>00309             <span class="keywordflow">return</span> 0;
<a name="l00310"></a>00310         }
<a name="l00311"></a>00311         <span class="keywordflow">else</span> {
<a name="l00312"></a>00312             <span class="comment">// spurious wakup, don&#39;t wait again, just return</span>
<a name="l00313"></a>00313             <span class="keywordflow">return</span> 1;
<a name="l00314"></a>00314         }
<a name="l00315"></a>00315     }
<a name="l00316"></a>00316     <span class="keywordflow">else</span> {
<a name="l00317"></a>00317         <span class="comment">// wait timedout, nobody woke us up</span>
<a name="l00318"></a>00318         <span class="keywordflow">return</span> -1;
<a name="l00319"></a>00319     }
<a name="l00320"></a>00320 }
<a name="l00321"></a>00321 
<a name="l00322"></a>00322 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00323"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aa5c3d0b397d9c38add897b73e21ec1d6">00323</a> <span class="keywordtype">int</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#aa5c3d0b397d9c38add897b73e21ec1d6">Buffer&lt;Type&gt;::getAndPopWithTimeout</a>( Type &amp;obj, <span class="keywordtype">int</span> timeoutMs )
<a name="l00324"></a>00324 {
<a name="l00325"></a>00325     <span class="keywordtype">int</span> ret = <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#af43d6c662de7dc14ab721a5d68a9e8fc">getWithTimeout</a>( obj, timeoutMs );
<a name="l00326"></a>00326     <span class="keywordflow">if</span> ( ret==0 ) {
<a name="l00327"></a>00327         <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#a8ae4213513399b95d9c7e68bdab1e57a">pop</a>();
<a name="l00328"></a>00328     }
<a name="l00329"></a>00329     <span class="keywordflow">return</span> ret;
<a name="l00330"></a>00330 }
<a name="l00331"></a>00331 
<a name="l00332"></a>00332 <span class="comment">// internal utility function (waits for update infinitely)</span>
<a name="l00333"></a>00333 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00334"></a>00334 <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html" title="A thread-safe data pipe with buffer semantics.">Buffer&lt;Type&gt;::getWithInfiniteWait</a>( Type &amp;obj )
<a name="l00335"></a>00335 {
<a name="l00336"></a>00336     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00337"></a>00337     
<a name="l00338"></a>00338     <span class="comment">// check the condition before and after waiting to deal with spurious wakeups</span>
<a name="l00339"></a>00339     <span class="comment">// (see Ice manual sec. 28.9.2)</span>
<a name="l00340"></a>00340     <span class="keywordflow">while</span> ( queue_.empty() ) 
<a name="l00341"></a>00341     {
<a name="l00342"></a>00342         this-&gt;wait();
<a name="l00343"></a>00343     }
<a name="l00344"></a>00344     
<a name="l00345"></a>00345     internalGet( obj );
<a name="l00346"></a>00346 }
<a name="l00347"></a>00347 
<a name="l00348"></a>00348 <span class="comment">// NOTE: see notes on efficient notification in Ice sec. 28.9.3</span>
<a name="l00349"></a>00349 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00350"></a><a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ab73d1777d7a9593ece7c5935d4c1ffd2">00350</a> <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html#ab73d1777d7a9593ece7c5935d4c1ffd2">Buffer&lt;Type&gt;::push</a>( <span class="keyword">const</span> Type &amp; obj )
<a name="l00351"></a>00351 {
<a name="l00352"></a>00352     IceUtil::Monitor&lt;IceUtil::Mutex&gt;::Lock lock(*<span class="keyword">this</span>);
<a name="l00353"></a>00353 
<a name="l00354"></a>00354     <span class="comment">// buffer is not full, or buffer is configured to be of infinite size (at least for STL)</span>
<a name="l00355"></a>00355     <span class="keywordflow">if</span> ( (<span class="keywordtype">int</span>)queue_.size() &lt; depth_ || depth_&lt;0 )
<a name="l00356"></a>00356     {
<a name="l00357"></a>00357         internalPush( obj );
<a name="l00358"></a>00358     }
<a name="l00359"></a>00359     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( type_ == <a class="code" href="namespacegbxiceutilacfr.html#adb63e22074734759c387bf1494c39d58a1d1af4db5a6306ef8ff06731810ea9b1">BufferTypeCircular</a> )
<a name="l00360"></a>00360     {
<a name="l00361"></a>00361         <span class="comment">// pop the oldest entry</span>
<a name="l00362"></a>00362         queue_.pop_front();
<a name="l00363"></a>00363         <span class="comment">// push the new enty</span>
<a name="l00364"></a>00364         internalPush( obj );
<a name="l00365"></a>00365     }
<a name="l00366"></a>00366     <span class="keywordflow">else</span> <span class="comment">// we have a full, non-circular buffer</span>
<a name="l00367"></a>00367     {
<a name="l00368"></a>00368         <span class="comment">// do nothing, the new object is lost</span>
<a name="l00369"></a>00369     }
<a name="l00370"></a>00370 
<a name="l00371"></a>00371     <span class="comment">// wakeup someone who&#39;s waiting for an update</span>
<a name="l00372"></a>00372     this-&gt;notify();
<a name="l00373"></a>00373 }
<a name="l00374"></a>00374 
<a name="l00375"></a>00375 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00376"></a>00376 <span class="keywordtype">void</span> <a class="code" href="classgbxiceutilacfr_1_1Buffer.html" title="A thread-safe data pipe with buffer semantics.">Buffer&lt;Type&gt;::internalGet</a>( Type &amp; obj )<span class="keyword"> const</span>
<a name="l00377"></a>00377 <span class="keyword"></span>{
<a name="l00378"></a>00378     obj = queue_.front();
<a name="l00379"></a>00379 }
<a name="l00380"></a>00380 
<a name="l00381"></a>00381 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;
<a name="l00382"></a>00382 <span class="keywordtype">void</span> Buffer&lt;Type&gt;::internalGet( Type &amp; obj, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n )<span class="keyword"> const</span>
<a name="l00383"></a>00383 <span class="keyword"></span>{
<a name="l00384"></a>00384     obj = queue_[n];
<a name="l00385"></a>00385 }
<a name="l00386"></a>00386 
<a name="l00387"></a>00387 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Type&gt;    
<a name="l00388"></a>00388 <span class="keywordtype">void</span> Buffer&lt;Type&gt;::internalPush( <span class="keyword">const</span> Type &amp; obj )
<a name="l00389"></a>00389 {
<a name="l00390"></a>00390     queue_.push_back( obj );
<a name="l00391"></a>00391 }
<a name="l00392"></a>00392 
<a name="l00393"></a>00393 } <span class="comment">// end namespace</span>
<a name="l00394"></a>00394 
<a name="l00395"></a>00395 <span class="preprocessor">#endif</span>
</pre></div></div>

            </td>
            <td colspan="1">&nbsp;</td>
         </tr>
        </table>
<!-- end of table -->

 <hr size="1"><address style="align: right;"><small>Generated for GearBox by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.5 </small></address>
</body>
</html>