1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: circular_buffer.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>circular_buffer.h</h1><a href="circular__buffer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00035"></a>00035 <span class="preprocessor">#ifndef CIRCULAR_BUFFER_H</span> |
---|
67 | <a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define CIRCULAR_BUFFER_H</span> |
---|
68 | <a name="l00037"></a>00037 <span class="preprocessor"></span> |
---|
69 | <a name="l00038"></a>00038 <span class="preprocessor">#include <<a class="code" href="vec_8h.html" title="Templated Vector Class Definitions.">itpp/base/vec.h</a>></span> |
---|
70 | <a name="l00039"></a>00039 <span class="preprocessor">#include <<a class="code" href="array_8h.html" title="Definition of Array class (container).">itpp/base/array.h</a>></span> |
---|
71 | <a name="l00040"></a>00040 |
---|
72 | <a name="l00041"></a>00041 |
---|
73 | <a name="l00042"></a>00042 <span class="keyword">namespace </span>itpp |
---|
74 | <a name="l00043"></a>00043 { |
---|
75 | <a name="l00044"></a>00044 |
---|
76 | <a name="l00091"></a>00091 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
77 | <a name="l00092"></a><a class="code" href="classitpp_1_1Circular__Buffer.html">00092</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1Circular__Buffer.html" title="General circular buffer class.">Circular_Buffer</a> |
---|
78 | <a name="l00093"></a>00093 { |
---|
79 | <a name="l00094"></a>00094 <span class="keyword">public</span>: |
---|
80 | <a name="l00096"></a>00096 <a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101" title="Default constructor.">Circular_Buffer</a>(); |
---|
81 | <a name="l00097"></a>00097 |
---|
82 | <a name="l00099"></a>00099 <a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101" title="Default constructor.">Circular_Buffer</a>(<span class="keywordtype">int</span> n); |
---|
83 | <a name="l00100"></a>00100 |
---|
84 | <a name="l00102"></a>00102 <a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101" title="Default constructor.">Circular_Buffer</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Circular__Buffer.html" title="General circular buffer class.">Circular_Buffer<T></a> &s); |
---|
85 | <a name="l00103"></a>00103 |
---|
86 | <a name="l00105"></a>00105 <span class="keyword">virtual</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#b20850719e0b2b50c89ab73891b3e07e" title="Default destructor.">~Circular_Buffer</a>(); |
---|
87 | <a name="l00106"></a>00106 |
---|
88 | <a name="l00108"></a>00108 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">put</a>(<span class="keyword">const</span> T& in); |
---|
89 | <a name="l00109"></a>00109 |
---|
90 | <a name="l00111"></a>00111 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">put</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& in); |
---|
91 | <a name="l00112"></a>00112 |
---|
92 | <a name="l00114"></a>00114 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">put</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& in); |
---|
93 | <a name="l00115"></a>00115 |
---|
94 | <a name="l00117"></a>00117 <span class="keywordtype">void</span> <span class="keyword">get</span>(T& out); |
---|
95 | <a name="l00118"></a>00118 |
---|
96 | <a name="l00120"></a>00120 T <span class="keyword">get</span>(); |
---|
97 | <a name="l00121"></a>00121 |
---|
98 | <a name="l00123"></a>00123 <span class="keywordtype">void</span> <span class="keyword">get</span>(<a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N = -1); |
---|
99 | <a name="l00124"></a>00124 |
---|
100 | <a name="l00126"></a>00126 <span class="keywordtype">void</span> <span class="keyword">get</span>(<a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N = -1); |
---|
101 | <a name="l00127"></a>00127 |
---|
102 | <a name="l00129"></a>00129 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(T& out) <span class="keyword">const</span>; |
---|
103 | <a name="l00130"></a>00130 |
---|
104 | <a name="l00132"></a>00132 T <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>() <span class="keyword">const</span>; |
---|
105 | <a name="l00133"></a>00133 |
---|
106 | <a name="l00135"></a>00135 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> index, T& out) <span class="keyword">const</span>; |
---|
107 | <a name="l00136"></a>00136 |
---|
108 | <a name="l00138"></a>00138 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(<a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N = -1) <span class="keyword">const</span>; |
---|
109 | <a name="l00139"></a>00139 |
---|
110 | <a name="l00141"></a>00141 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(<span class="keyword">const</span> ivec& index, <a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out) <span class="keyword">const</span>; |
---|
111 | <a name="l00142"></a>00142 |
---|
112 | <a name="l00144"></a>00144 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(<a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N = -1) <span class="keyword">const</span>; |
---|
113 | <a name="l00145"></a>00145 |
---|
114 | <a name="l00147"></a>00147 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(<span class="keyword">const</span> ivec& index, <a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out) <span class="keyword">const</span>; |
---|
115 | <a name="l00148"></a>00148 |
---|
116 | <a name="l00150"></a>00150 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">peek_reverse</a>(T& out) <span class="keyword">const</span>; |
---|
117 | <a name="l00151"></a>00151 |
---|
118 | <a name="l00153"></a>00153 T <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">peek_reverse</a>() <span class="keyword">const</span>; |
---|
119 | <a name="l00154"></a>00154 |
---|
120 | <a name="l00156"></a>00156 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">peek_reverse</a>(<a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N = -1) <span class="keyword">const</span>; |
---|
121 | <a name="l00157"></a>00157 |
---|
122 | <a name="l00159"></a>00159 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">peek_reverse</a>(<a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N = -1) <span class="keyword">const</span>; |
---|
123 | <a name="l00160"></a>00160 |
---|
124 | <a name="l00162"></a>00162 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#15da2e68939407a13dde647afcb56529" title="Empty the circular buffer.">clear</a>(); |
---|
125 | <a name="l00163"></a>00163 |
---|
126 | <a name="l00165"></a>00165 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#625975c59def123a1531949583d52393" title="Assignment operator.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Circular__Buffer.html" title="General circular buffer class.">Circular_Buffer<T></a> &s); |
---|
127 | <a name="l00166"></a>00166 |
---|
128 | <a name="l00168"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#0b6b10852c6f944ef07bd9252a973002">00168</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#0b6b10852c6f944ef07bd9252a973002" title="Returns the maximum number of data elements the circular buffer can store.">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _ndata; } |
---|
129 | <a name="l00169"></a>00169 |
---|
130 | <a name="l00171"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#54d8aac5494015926458d97529a620c4">00171</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#54d8aac5494015926458d97529a620c4" title="Returns the number of data elements currently stored in the circular buffer.">nrof_elements</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _rw_dist; } |
---|
131 | <a name="l00172"></a>00172 |
---|
132 | <a name="l00174"></a>00174 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#71666739dc1f890cba5b973ff3f045b7" title="Resizing a Circular_Buffer&lt;T&gt;.">set_size</a>(<span class="keywordtype">int</span> n, <span class="keywordtype">bool</span> copy = <span class="keyword">false</span>); |
---|
133 | <a name="l00175"></a>00175 |
---|
134 | <a name="l00176"></a>00176 <span class="keyword">private</span>: |
---|
135 | <a name="l00177"></a>00177 |
---|
136 | <a name="l00178"></a>00178 <span class="keywordtype">int</span> _write; |
---|
137 | <a name="l00179"></a>00179 <span class="keywordtype">int</span> _read; |
---|
138 | <a name="l00180"></a>00180 <span class="keywordtype">int</span> _ndata; |
---|
139 | <a name="l00181"></a>00181 <span class="keywordtype">int</span> _rw_dist; |
---|
140 | <a name="l00182"></a>00182 T *_data; |
---|
141 | <a name="l00183"></a>00183 |
---|
142 | <a name="l00184"></a>00184 <span class="keywordtype">void</span> alloc(<span class="keywordtype">int</span> n); |
---|
143 | <a name="l00185"></a>00185 <span class="keywordtype">void</span> free(); |
---|
144 | <a name="l00186"></a>00186 |
---|
145 | <a name="l00187"></a>00187 }; |
---|
146 | <a name="l00188"></a>00188 |
---|
147 | <a name="l00189"></a>00189 <span class="comment">// --------------------------- Implementation starts here ----------------------------------</span> |
---|
148 | <a name="l00190"></a>00190 |
---|
149 | <a name="l00191"></a>00191 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
150 | <a name="l00192"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101">00192</a> <a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101" title="Default constructor.">Circular_Buffer<T>::Circular_Buffer</a>() |
---|
151 | <a name="l00193"></a>00193 { |
---|
152 | <a name="l00194"></a>00194 _data = 0; |
---|
153 | <a name="l00195"></a>00195 _ndata = 0; |
---|
154 | <a name="l00196"></a>00196 _rw_dist = 0; |
---|
155 | <a name="l00197"></a>00197 _read = 0; |
---|
156 | <a name="l00198"></a>00198 _write = 0; |
---|
157 | <a name="l00199"></a>00199 } |
---|
158 | <a name="l00200"></a>00200 |
---|
159 | <a name="l00201"></a>00201 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
160 | <a name="l00202"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#b654a46913bea47e210e263737bf104d">00202</a> <a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101" title="Default constructor.">Circular_Buffer<T>::Circular_Buffer</a>(<span class="keywordtype">int</span> n) |
---|
161 | <a name="l00203"></a>00203 { |
---|
162 | <a name="l00204"></a>00204 alloc(n); |
---|
163 | <a name="l00205"></a>00205 _read = 0; |
---|
164 | <a name="l00206"></a>00206 _write = 0; |
---|
165 | <a name="l00207"></a>00207 _rw_dist = 0; |
---|
166 | <a name="l00208"></a>00208 } |
---|
167 | <a name="l00209"></a>00209 |
---|
168 | <a name="l00210"></a>00210 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
169 | <a name="l00211"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#64a7e0608208d189423d2e2f68351b5e">00211</a> <a class="code" href="classitpp_1_1Circular__Buffer.html#facfe1f87533c5a3eeb07d409b058101" title="Default constructor.">Circular_Buffer<T>::Circular_Buffer</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Circular__Buffer.html" title="General circular buffer class.">Circular_Buffer<T></a> &cb) |
---|
170 | <a name="l00212"></a>00212 { |
---|
171 | <a name="l00213"></a>00213 _data = NULL; |
---|
172 | <a name="l00214"></a>00214 _ndata = 0; |
---|
173 | <a name="l00215"></a>00215 _read = cb.<a class="code" href="classitpp_1_1Circular__Buffer.html#232185b0ea445ec74037e0d8dc5bd2c1">_read</a>; |
---|
174 | <a name="l00216"></a>00216 _write = cb.<a class="code" href="classitpp_1_1Circular__Buffer.html#6d88fb1ce4d845a34618627df4008333">_write</a>; |
---|
175 | <a name="l00217"></a>00217 _rw_dist = cb.<a class="code" href="classitpp_1_1Circular__Buffer.html#0866c8f3b8896b74c3e25caa542ffacd">_rw_dist</a>; |
---|
176 | <a name="l00218"></a>00218 |
---|
177 | <a name="l00219"></a>00219 alloc(cb.<a class="code" href="classitpp_1_1Circular__Buffer.html#8f8e598cd1ff98d7ae0141495fef14c4">_ndata</a>); |
---|
178 | <a name="l00220"></a>00220 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < cb.<a class="code" href="classitpp_1_1Circular__Buffer.html#8f8e598cd1ff98d7ae0141495fef14c4">_ndata</a>; i++) { _data[i] = cb.<a class="code" href="classitpp_1_1Circular__Buffer.html#2a7411750051641aa717feb3e16d513f">_data</a>[i]; } |
---|
179 | <a name="l00221"></a>00221 } |
---|
180 | <a name="l00222"></a>00222 |
---|
181 | <a name="l00223"></a>00223 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
182 | <a name="l00224"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#b20850719e0b2b50c89ab73891b3e07e">00224</a> <a class="code" href="classitpp_1_1Circular__Buffer.html#b20850719e0b2b50c89ab73891b3e07e" title="Default destructor.">Circular_Buffer<T>::~Circular_Buffer</a>() |
---|
183 | <a name="l00225"></a>00225 { |
---|
184 | <a name="l00226"></a>00226 free(); |
---|
185 | <a name="l00227"></a>00227 } |
---|
186 | <a name="l00228"></a>00228 |
---|
187 | <a name="l00229"></a>00229 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
188 | <a name="l00230"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#e780e614fc4add0df984152c851b7e82">00230</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#e4e7aa878c4a3aacf2cb5b942f5be939" title="Get the oldest element in the circular buffer.">Circular_Buffer<T>::get</a>(T& out) |
---|
189 | <a name="l00231"></a>00231 { |
---|
190 | <a name="l00232"></a>00232 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist > 0, <span class="stringliteral">"Buffer empty. No data left to read from the buffer."</span>); |
---|
191 | <a name="l00233"></a>00233 out = _data[_read]; |
---|
192 | <a name="l00234"></a>00234 _read++; |
---|
193 | <a name="l00235"></a>00235 _rw_dist--; |
---|
194 | <a name="l00236"></a>00236 |
---|
195 | <a name="l00237"></a>00237 <span class="keywordflow">if</span> (_read == _ndata) { _read = 0; } |
---|
196 | <a name="l00238"></a>00238 } |
---|
197 | <a name="l00239"></a>00239 |
---|
198 | <a name="l00240"></a>00240 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
199 | <a name="l00241"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#e4e7aa878c4a3aacf2cb5b942f5be939">00241</a> T <a class="code" href="classitpp_1_1Circular__Buffer.html#e4e7aa878c4a3aacf2cb5b942f5be939" title="Get the oldest element in the circular buffer.">Circular_Buffer<T>::get</a>() |
---|
200 | <a name="l00242"></a>00242 { |
---|
201 | <a name="l00243"></a>00243 T out; |
---|
202 | <a name="l00244"></a>00244 |
---|
203 | <a name="l00245"></a>00245 <span class="keyword">get</span>(out); |
---|
204 | <a name="l00246"></a>00246 <span class="keywordflow">return</span> out; |
---|
205 | <a name="l00247"></a>00247 } |
---|
206 | <a name="l00248"></a>00248 |
---|
207 | <a name="l00249"></a>00249 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
208 | <a name="l00250"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#2503913b027197bb6c3c3023b728862f">00250</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#e4e7aa878c4a3aacf2cb5b942f5be939" title="Get the oldest element in the circular buffer.">Circular_Buffer<T>::get</a>(<a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N) |
---|
209 | <a name="l00251"></a>00251 { |
---|
210 | <a name="l00252"></a>00252 <span class="keywordtype">int</span> N_out; |
---|
211 | <a name="l00253"></a>00253 |
---|
212 | <a name="l00254"></a>00254 <span class="keywordflow">if</span> (N == -1) |
---|
213 | <a name="l00255"></a>00255 N_out = _rw_dist; |
---|
214 | <a name="l00256"></a>00256 <span class="keywordflow">else</span> |
---|
215 | <a name="l00257"></a>00257 N_out = N; |
---|
216 | <a name="l00258"></a>00258 |
---|
217 | <a name="l00259"></a>00259 out.<a class="code" href="classitpp_1_1Vec.html#a4b02b7819e540bb3853c15e6480ada6" title="Set length of vector. if copy = true then keeping the old values.">set_size</a>(N_out); |
---|
218 | <a name="l00260"></a>00260 |
---|
219 | <a name="l00261"></a>00261 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < N_out;i++) { |
---|
220 | <a name="l00262"></a>00262 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist > 0, <span class="stringliteral">"Buffer empty. No data left to read from the buffer."</span>); |
---|
221 | <a name="l00263"></a>00263 out(i) = _data[_read]; |
---|
222 | <a name="l00264"></a>00264 _read++; |
---|
223 | <a name="l00265"></a>00265 _rw_dist--; |
---|
224 | <a name="l00266"></a>00266 |
---|
225 | <a name="l00267"></a>00267 <span class="keywordflow">if</span> (_read == _ndata) |
---|
226 | <a name="l00268"></a>00268 _read = 0; |
---|
227 | <a name="l00269"></a>00269 } |
---|
228 | <a name="l00270"></a>00270 } |
---|
229 | <a name="l00271"></a>00271 |
---|
230 | <a name="l00272"></a>00272 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
231 | <a name="l00273"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#87dac11564185e418ae7650b5c503123">00273</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#e4e7aa878c4a3aacf2cb5b942f5be939" title="Get the oldest element in the circular buffer.">Circular_Buffer<T>::get</a>(<a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N) |
---|
232 | <a name="l00274"></a>00274 { |
---|
233 | <a name="l00275"></a>00275 <span class="keywordtype">int</span> N_out; |
---|
234 | <a name="l00276"></a>00276 |
---|
235 | <a name="l00277"></a>00277 <span class="keywordflow">if</span> (N == -1) |
---|
236 | <a name="l00278"></a>00278 N_out = _rw_dist; |
---|
237 | <a name="l00279"></a>00279 <span class="keywordflow">else</span> |
---|
238 | <a name="l00280"></a>00280 N_out = N; |
---|
239 | <a name="l00281"></a>00281 |
---|
240 | <a name="l00282"></a>00282 out.<a class="code" href="classitpp_1_1Array.html#dbf76c71f29014a4d53f254e83f3ff1c" title="Resizing an Array&lt;T&gt;.">set_size</a>(N_out); |
---|
241 | <a name="l00283"></a>00283 |
---|
242 | <a name="l00284"></a>00284 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < N_out;i++) { |
---|
243 | <a name="l00285"></a>00285 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist > 0, <span class="stringliteral">"Buffer empty. No data left to read from the buffer."</span>); |
---|
244 | <a name="l00286"></a>00286 out(i) = _data[_read]; |
---|
245 | <a name="l00287"></a>00287 _read++; |
---|
246 | <a name="l00288"></a>00288 _rw_dist--; |
---|
247 | <a name="l00289"></a>00289 |
---|
248 | <a name="l00290"></a>00290 <span class="keywordflow">if</span> (_read == _ndata) |
---|
249 | <a name="l00291"></a>00291 _read = 0; |
---|
250 | <a name="l00292"></a>00292 } |
---|
251 | <a name="l00293"></a>00293 } |
---|
252 | <a name="l00294"></a>00294 |
---|
253 | <a name="l00295"></a>00295 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
254 | <a name="l00296"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#2f5fe49bcdfb038831eace4f4466fc9b">00296</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>(T& out)<span class="keyword"> const</span> |
---|
255 | <a name="l00297"></a>00297 <span class="keyword"></span>{ |
---|
256 | <a name="l00298"></a>00298 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist > 0, <span class="stringliteral">"Attempted to peek at an empty buffer."</span>); |
---|
257 | <a name="l00299"></a>00299 out = _data[_read]; |
---|
258 | <a name="l00300"></a>00300 } |
---|
259 | <a name="l00301"></a>00301 |
---|
260 | <a name="l00302"></a>00302 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
261 | <a name="l00303"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549">00303</a> T <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>()<span class="keyword"> const</span> |
---|
262 | <a name="l00304"></a>00304 <span class="keyword"></span>{ |
---|
263 | <a name="l00305"></a>00305 T out; |
---|
264 | <a name="l00306"></a>00306 |
---|
265 | <a name="l00307"></a>00307 <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">peek</a>(out); |
---|
266 | <a name="l00308"></a>00308 <span class="keywordflow">return</span> out; |
---|
267 | <a name="l00309"></a>00309 } |
---|
268 | <a name="l00310"></a>00310 |
---|
269 | <a name="l00311"></a>00311 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
270 | <a name="l00312"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#13bca849dbeb71d243eeede5f157a227">00312</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> index, T& out)<span class="keyword"> const</span> |
---|
271 | <a name="l00313"></a>00313 <span class="keyword"></span>{ |
---|
272 | <a name="l00314"></a>00314 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist > index && index >= 0, <span class="stringliteral">"The index exceeds the number of elements stored in the buffer."</span>); |
---|
273 | <a name="l00315"></a>00315 out = _data[(_read+index)%_ndata]; |
---|
274 | <a name="l00316"></a>00316 } |
---|
275 | <a name="l00317"></a>00317 |
---|
276 | <a name="l00318"></a>00318 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
277 | <a name="l00319"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#4a1698d3de757f7157c654bd28f7222c">00319</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>(<a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N)<span class="keyword"> const</span> |
---|
278 | <a name="l00320"></a>00320 <span class="keyword"></span>{ |
---|
279 | <a name="l00321"></a>00321 <span class="keywordtype">int</span> N_out; |
---|
280 | <a name="l00322"></a>00322 <span class="keywordtype">int</span> read_tmp = _read; |
---|
281 | <a name="l00323"></a>00323 |
---|
282 | <a name="l00324"></a>00324 <span class="keywordflow">if</span> (N == -1) |
---|
283 | <a name="l00325"></a>00325 N_out = _rw_dist; |
---|
284 | <a name="l00326"></a>00326 <span class="keywordflow">else</span> |
---|
285 | <a name="l00327"></a>00327 N_out = N; |
---|
286 | <a name="l00328"></a>00328 |
---|
287 | <a name="l00329"></a>00329 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist >= N_out, <span class="stringliteral">"Attempted to peek at more elements than there are stored in the buffer."</span>); |
---|
288 | <a name="l00330"></a>00330 out.<a class="code" href="classitpp_1_1Vec.html#a4b02b7819e540bb3853c15e6480ada6" title="Set length of vector. if copy = true then keeping the old values.">set_size</a>(N_out); |
---|
289 | <a name="l00331"></a>00331 |
---|
290 | <a name="l00332"></a>00332 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < N_out;i++) { |
---|
291 | <a name="l00333"></a>00333 out(i) = _data[read_tmp]; |
---|
292 | <a name="l00334"></a>00334 read_tmp++; |
---|
293 | <a name="l00335"></a>00335 <span class="keywordflow">if</span> (read_tmp == _ndata) |
---|
294 | <a name="l00336"></a>00336 read_tmp = 0; |
---|
295 | <a name="l00337"></a>00337 } |
---|
296 | <a name="l00338"></a>00338 } |
---|
297 | <a name="l00339"></a>00339 |
---|
298 | <a name="l00340"></a>00340 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
299 | <a name="l00341"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#ca93e92932bf160f6bbeea39a98defda">00341</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>(<span class="keyword">const</span> ivec& index, <a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out)<span class="keyword"> const</span> |
---|
300 | <a name="l00342"></a>00342 <span class="keyword"></span>{ |
---|
301 | <a name="l00343"></a>00343 out.<a class="code" href="classitpp_1_1Vec.html#a4b02b7819e540bb3853c15e6480ada6" title="Set length of vector. if copy = true then keeping the old values.">set_size</a>(index.size()); |
---|
302 | <a name="l00344"></a>00344 |
---|
303 | <a name="l00345"></a>00345 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < index.size();i++) { |
---|
304 | <a name="l00346"></a>00346 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist >= index(i) && index(i) >= 0, <span class="stringliteral">"Attempted to peek at an element, whose index exceeds the number of buffered elements."</span>); |
---|
305 | <a name="l00347"></a>00347 out(i) = _data[(_read+index(i))%_ndata]; |
---|
306 | <a name="l00348"></a>00348 } |
---|
307 | <a name="l00349"></a>00349 } |
---|
308 | <a name="l00350"></a>00350 |
---|
309 | <a name="l00351"></a>00351 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
310 | <a name="l00352"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#685da19384f131995ef4841b3f11587a">00352</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>(<a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N)<span class="keyword"> const</span> |
---|
311 | <a name="l00353"></a>00353 <span class="keyword"></span>{ |
---|
312 | <a name="l00354"></a>00354 <span class="keywordtype">int</span> N_out; |
---|
313 | <a name="l00355"></a>00355 <span class="keywordtype">int</span> read_tmp = _read; |
---|
314 | <a name="l00356"></a>00356 |
---|
315 | <a name="l00357"></a>00357 <span class="keywordflow">if</span> (N == -1) |
---|
316 | <a name="l00358"></a>00358 N_out = _rw_dist; |
---|
317 | <a name="l00359"></a>00359 <span class="keywordflow">else</span> |
---|
318 | <a name="l00360"></a>00360 N_out = N; |
---|
319 | <a name="l00361"></a>00361 |
---|
320 | <a name="l00362"></a>00362 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist >= N_out, <span class="stringliteral">"Attempted to peek at more elements than there are stored in the buffer."</span>); |
---|
321 | <a name="l00363"></a>00363 out.<a class="code" href="classitpp_1_1Array.html#dbf76c71f29014a4d53f254e83f3ff1c" title="Resizing an Array&lt;T&gt;.">set_size</a>(N_out); |
---|
322 | <a name="l00364"></a>00364 |
---|
323 | <a name="l00365"></a>00365 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < N_out;i++) { |
---|
324 | <a name="l00366"></a>00366 out(i) = _data[read_tmp]; |
---|
325 | <a name="l00367"></a>00367 read_tmp++; |
---|
326 | <a name="l00368"></a>00368 <span class="keywordflow">if</span> (read_tmp == _ndata) |
---|
327 | <a name="l00369"></a>00369 read_tmp = 0; |
---|
328 | <a name="l00370"></a>00370 } |
---|
329 | <a name="l00371"></a>00371 } |
---|
330 | <a name="l00372"></a>00372 |
---|
331 | <a name="l00373"></a>00373 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
332 | <a name="l00374"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#0628353cd43b1fdb3e5a52fda3f5ba8d">00374</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#d20356855fe0667656dbf25221722549" title="Peek at the oldest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek</a>(<span class="keyword">const</span> ivec& index, <a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out)<span class="keyword"> const</span> |
---|
333 | <a name="l00375"></a>00375 <span class="keyword"></span>{ |
---|
334 | <a name="l00376"></a>00376 out.<a class="code" href="classitpp_1_1Array.html#dbf76c71f29014a4d53f254e83f3ff1c" title="Resizing an Array&lt;T&gt;.">set_size</a>(index.size()); |
---|
335 | <a name="l00377"></a>00377 |
---|
336 | <a name="l00378"></a>00378 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < index.size();i++) { |
---|
337 | <a name="l00379"></a>00379 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist >= index(i) && index(i) >= 0, <span class="stringliteral">"Attempted to peek at an element, whose index exceeds the number of buffered elements."</span>); |
---|
338 | <a name="l00380"></a>00380 out(i) = _data[(_read+index(i))%_ndata]; |
---|
339 | <a name="l00381"></a>00381 } |
---|
340 | <a name="l00382"></a>00382 } |
---|
341 | <a name="l00383"></a>00383 |
---|
342 | <a name="l00384"></a>00384 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
343 | <a name="l00385"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#9ff08a09d34e31c7c5b8ead37aa9bf77">00385</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek_reverse</a>(T& out)<span class="keyword"> const</span> |
---|
344 | <a name="l00386"></a>00386 <span class="keyword"></span>{ |
---|
345 | <a name="l00387"></a>00387 <span class="keywordtype">int</span> read_tmp; |
---|
346 | <a name="l00388"></a>00388 |
---|
347 | <a name="l00389"></a>00389 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist > 0, <span class="stringliteral">"Attempted to peek at an empty buffer."</span>); |
---|
348 | <a name="l00390"></a>00390 |
---|
349 | <a name="l00391"></a>00391 <span class="keywordflow">if</span> (_write > 0) |
---|
350 | <a name="l00392"></a>00392 read_tmp = _write - 1; |
---|
351 | <a name="l00393"></a>00393 <span class="keywordflow">else</span> |
---|
352 | <a name="l00394"></a>00394 read_tmp = _ndata - 1; |
---|
353 | <a name="l00395"></a>00395 |
---|
354 | <a name="l00396"></a>00396 out = _data[read_tmp]; |
---|
355 | <a name="l00397"></a>00397 } |
---|
356 | <a name="l00398"></a>00398 |
---|
357 | <a name="l00399"></a>00399 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
358 | <a name="l00400"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef">00400</a> T <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek_reverse</a>()<span class="keyword"> const</span> |
---|
359 | <a name="l00401"></a>00401 <span class="keyword"></span>{ |
---|
360 | <a name="l00402"></a>00402 T out; |
---|
361 | <a name="l00403"></a>00403 |
---|
362 | <a name="l00404"></a>00404 <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">peek_reverse</a>(out); |
---|
363 | <a name="l00405"></a>00405 <span class="keywordflow">return</span> out; |
---|
364 | <a name="l00406"></a>00406 } |
---|
365 | <a name="l00407"></a>00407 |
---|
366 | <a name="l00408"></a>00408 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
367 | <a name="l00409"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#5d5e04e774f9389743c9c05d24929107">00409</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek_reverse</a>(<a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N)<span class="keyword"> const</span> |
---|
368 | <a name="l00410"></a>00410 <span class="keyword"></span>{ |
---|
369 | <a name="l00411"></a>00411 <span class="keywordtype">int</span> N_out; |
---|
370 | <a name="l00412"></a>00412 <span class="keywordtype">int</span> read_tmp; |
---|
371 | <a name="l00413"></a>00413 |
---|
372 | <a name="l00414"></a>00414 <span class="keywordflow">if</span> (N == -1) |
---|
373 | <a name="l00415"></a>00415 N_out = _rw_dist; |
---|
374 | <a name="l00416"></a>00416 <span class="keywordflow">else</span> |
---|
375 | <a name="l00417"></a>00417 N_out = N; |
---|
376 | <a name="l00418"></a>00418 |
---|
377 | <a name="l00419"></a>00419 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist >= N_out, <span class="stringliteral">"Attempted to peek at more elements than there are stored in the buffer."</span>); |
---|
378 | <a name="l00420"></a>00420 out.<a class="code" href="classitpp_1_1Vec.html#a4b02b7819e540bb3853c15e6480ada6" title="Set length of vector. if copy = true then keeping the old values.">set_size</a>(N_out); |
---|
379 | <a name="l00421"></a>00421 |
---|
380 | <a name="l00422"></a>00422 <span class="keywordflow">if</span> (_write > 0) |
---|
381 | <a name="l00423"></a>00423 read_tmp = _write - 1; |
---|
382 | <a name="l00424"></a>00424 <span class="keywordflow">else</span> |
---|
383 | <a name="l00425"></a>00425 read_tmp = _ndata - 1; |
---|
384 | <a name="l00426"></a>00426 |
---|
385 | <a name="l00427"></a>00427 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < N_out;i++) { |
---|
386 | <a name="l00428"></a>00428 out(i) = _data[read_tmp]; |
---|
387 | <a name="l00429"></a>00429 read_tmp--; |
---|
388 | <a name="l00430"></a>00430 <span class="keywordflow">if</span> (read_tmp < 0) |
---|
389 | <a name="l00431"></a>00431 read_tmp = _ndata - 1; |
---|
390 | <a name="l00432"></a>00432 } |
---|
391 | <a name="l00433"></a>00433 } |
---|
392 | <a name="l00434"></a>00434 |
---|
393 | <a name="l00435"></a>00435 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
394 | <a name="l00436"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#2903e9dac4afbb8d6a2fcbd299c1e3cf">00436</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">Circular_Buffer<T>::peek_reverse</a>(<a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& out, <span class="keyword">const</span> <span class="keywordtype">int</span> N)<span class="keyword"> const</span> |
---|
395 | <a name="l00437"></a>00437 <span class="keyword"></span>{ |
---|
396 | <a name="l00438"></a>00438 <span class="keywordtype">int</span> N_out; |
---|
397 | <a name="l00439"></a>00439 <span class="keywordtype">int</span> read_tmp; |
---|
398 | <a name="l00440"></a>00440 |
---|
399 | <a name="l00441"></a>00441 <span class="keywordflow">if</span> (N == -1) |
---|
400 | <a name="l00442"></a>00442 N_out = _rw_dist; |
---|
401 | <a name="l00443"></a>00443 <span class="keywordflow">else</span> |
---|
402 | <a name="l00444"></a>00444 N_out = N; |
---|
403 | <a name="l00445"></a>00445 |
---|
404 | <a name="l00446"></a>00446 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(_rw_dist >= N_out, <span class="stringliteral">"Attempted to peek at more elements than there are stored in the buffer."</span>); |
---|
405 | <a name="l00447"></a>00447 out.<a class="code" href="classitpp_1_1Array.html#dbf76c71f29014a4d53f254e83f3ff1c" title="Resizing an Array&lt;T&gt;.">set_size</a>(N_out); |
---|
406 | <a name="l00448"></a>00448 |
---|
407 | <a name="l00449"></a>00449 <span class="keywordflow">if</span> (_write > 0) |
---|
408 | <a name="l00450"></a>00450 read_tmp = _write - 1; |
---|
409 | <a name="l00451"></a>00451 <span class="keywordflow">else</span> |
---|
410 | <a name="l00452"></a>00452 read_tmp = _ndata - 1; |
---|
411 | <a name="l00453"></a>00453 |
---|
412 | <a name="l00454"></a>00454 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < N_out;i++) { |
---|
413 | <a name="l00455"></a>00455 out(i) = _data[read_tmp]; |
---|
414 | <a name="l00456"></a>00456 read_tmp--; |
---|
415 | <a name="l00457"></a>00457 <span class="keywordflow">if</span> (read_tmp < 0) |
---|
416 | <a name="l00458"></a>00458 read_tmp = _ndata - 1; |
---|
417 | <a name="l00459"></a>00459 } |
---|
418 | <a name="l00460"></a>00460 } |
---|
419 | <a name="l00461"></a>00461 |
---|
420 | <a name="l00462"></a>00462 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
421 | <a name="l00463"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758">00463</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">Circular_Buffer<T>::put</a>(<span class="keyword">const</span> T& in) |
---|
422 | <a name="l00464"></a>00464 { |
---|
423 | <a name="l00465"></a>00465 <span class="comment">//Remove the oldest element of the buffer if the buffer is full</span> |
---|
424 | <a name="l00466"></a>00466 <span class="keywordflow">if</span> (_rw_dist >= _ndata) { |
---|
425 | <a name="l00467"></a>00467 T dummy; |
---|
426 | <a name="l00468"></a>00468 <span class="keyword">get</span>(dummy); |
---|
427 | <a name="l00469"></a>00469 } |
---|
428 | <a name="l00470"></a>00470 |
---|
429 | <a name="l00471"></a>00471 <span class="comment">//Write data to the buffer and move the pointer to the next buffer slot</span> |
---|
430 | <a name="l00472"></a>00472 _data[_write] = in; |
---|
431 | <a name="l00473"></a>00473 _write++; |
---|
432 | <a name="l00474"></a>00474 _rw_dist++; |
---|
433 | <a name="l00475"></a>00475 |
---|
434 | <a name="l00476"></a>00476 <span class="comment">//Check if the pointer in the circular buffer should go back to zero</span> |
---|
435 | <a name="l00477"></a>00477 <span class="keywordflow">if</span> (_write >= _ndata) |
---|
436 | <a name="l00478"></a>00478 _write = 0; |
---|
437 | <a name="l00479"></a>00479 |
---|
438 | <a name="l00480"></a>00480 } |
---|
439 | <a name="l00481"></a>00481 |
---|
440 | <a name="l00482"></a>00482 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
441 | <a name="l00483"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#9ea0ad44cc98912ae6c98fa0ee64c2d4">00483</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">Circular_Buffer<T>::put</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a>& in) |
---|
442 | <a name="l00484"></a>00484 { |
---|
443 | <a name="l00485"></a>00485 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < in.<a class="code" href="classitpp_1_1Vec.html#a906c893cd6184a774e4da8a47217d6a" title="The size of the vector.">size</a>();i++) { |
---|
444 | <a name="l00486"></a>00486 <span class="comment">//Remove the oldest element of the buffer if the buffer is full</span> |
---|
445 | <a name="l00487"></a>00487 <span class="keywordflow">if</span> (_rw_dist >= _ndata) { |
---|
446 | <a name="l00488"></a>00488 T dummy; |
---|
447 | <a name="l00489"></a>00489 <span class="keyword">get</span>(dummy); |
---|
448 | <a name="l00490"></a>00490 } |
---|
449 | <a name="l00491"></a>00491 |
---|
450 | <a name="l00492"></a>00492 <span class="comment">//Write data to the buffer and move the pointer to the next buffer slot</span> |
---|
451 | <a name="l00493"></a>00493 _data[_write] = in(i); |
---|
452 | <a name="l00494"></a>00494 _write++; |
---|
453 | <a name="l00495"></a>00495 _rw_dist++; |
---|
454 | <a name="l00496"></a>00496 |
---|
455 | <a name="l00497"></a>00497 <span class="comment">//Check if the pointer in the circular buffer should go back to zero</span> |
---|
456 | <a name="l00498"></a>00498 <span class="keywordflow">if</span> (_write >= _ndata) |
---|
457 | <a name="l00499"></a>00499 _write = 0; |
---|
458 | <a name="l00500"></a>00500 } |
---|
459 | <a name="l00501"></a>00501 |
---|
460 | <a name="l00502"></a>00502 } |
---|
461 | <a name="l00503"></a>00503 |
---|
462 | <a name="l00504"></a>00504 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
463 | <a name="l00505"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#9197d0b15e58119f445fc10a95f45e54">00505</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">Circular_Buffer<T>::put</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Array.html" title="General array class.">Array<T></a>& in) |
---|
464 | <a name="l00506"></a>00506 { |
---|
465 | <a name="l00507"></a>00507 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < in.<a class="code" href="classitpp_1_1Array.html#ce6bb3089de6f3ff86806d78f35505a4" title="Returns the number of data elements in the array object.">size</a>();i++) { |
---|
466 | <a name="l00508"></a>00508 <span class="comment">//Remove the oldest element of the buffer if the buffer is full</span> |
---|
467 | <a name="l00509"></a>00509 <span class="keywordflow">if</span> (_rw_dist >= _ndata) { |
---|
468 | <a name="l00510"></a>00510 T dummy; |
---|
469 | <a name="l00511"></a>00511 <span class="keyword">get</span>(dummy); |
---|
470 | <a name="l00512"></a>00512 } |
---|
471 | <a name="l00513"></a>00513 |
---|
472 | <a name="l00514"></a>00514 <span class="comment">//Write data to the buffer and move the pointer to the next buffer slot</span> |
---|
473 | <a name="l00515"></a>00515 _data[_write] = in(i); |
---|
474 | <a name="l00516"></a>00516 _write++; |
---|
475 | <a name="l00517"></a>00517 _rw_dist++; |
---|
476 | <a name="l00518"></a>00518 |
---|
477 | <a name="l00519"></a>00519 <span class="comment">//Check if the pointer in the circular buffer should go back to zero</span> |
---|
478 | <a name="l00520"></a>00520 <span class="keywordflow">if</span> (_write >= _ndata) |
---|
479 | <a name="l00521"></a>00521 _write = 0; |
---|
480 | <a name="l00522"></a>00522 } |
---|
481 | <a name="l00523"></a>00523 } |
---|
482 | <a name="l00524"></a>00524 |
---|
483 | <a name="l00525"></a>00525 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
484 | <a name="l00526"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#15da2e68939407a13dde647afcb56529">00526</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#15da2e68939407a13dde647afcb56529" title="Empty the circular buffer.">Circular_Buffer<T>::clear</a>() |
---|
485 | <a name="l00527"></a>00527 { |
---|
486 | <a name="l00528"></a>00528 _write = 0; |
---|
487 | <a name="l00529"></a>00529 _read = 0; |
---|
488 | <a name="l00530"></a>00530 _rw_dist = 0; |
---|
489 | <a name="l00531"></a>00531 } |
---|
490 | <a name="l00532"></a>00532 |
---|
491 | <a name="l00533"></a>00533 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
492 | <a name="l00534"></a>00534 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html" title="General circular buffer class.">Circular_Buffer<T>::alloc</a>(<span class="keywordtype">int</span> n) |
---|
493 | <a name="l00535"></a>00535 { |
---|
494 | <a name="l00536"></a>00536 <span class="keywordflow">if</span> (n == 0) { |
---|
495 | <a name="l00537"></a>00537 _ndata = 0; |
---|
496 | <a name="l00538"></a>00538 _data = NULL; |
---|
497 | <a name="l00539"></a>00539 } |
---|
498 | <a name="l00540"></a>00540 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n > 0) { |
---|
499 | <a name="l00541"></a>00541 _ndata = n; |
---|
500 | <a name="l00542"></a>00542 _data = <span class="keyword">new</span> T[_ndata]; |
---|
501 | <a name="l00543"></a>00543 <a class="code" href="group__errorhandlingfunc.html#gd5c34b291e5018534fd2344486e2b5a1" title="Abort if t is not true.">it_assert</a>(_data != 0, <span class="stringliteral">"Out of memory in Circular_Buffer::alloc"</span>); |
---|
502 | <a name="l00544"></a>00544 } |
---|
503 | <a name="l00545"></a>00545 <span class="keywordflow">else</span> { |
---|
504 | <a name="l00546"></a>00546 <a class="code" href="group__errorhandlingfunc.html#g22d38e98332f9edff88cc501463eedce" title="Abort unconditionally.">it_error</a>(<span class="stringliteral">"Circular_Buffer<T>::alloc(int n): n must be positive"</span>); |
---|
505 | <a name="l00547"></a>00547 } |
---|
506 | <a name="l00548"></a>00548 } |
---|
507 | <a name="l00549"></a>00549 |
---|
508 | <a name="l00550"></a>00550 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
509 | <a name="l00551"></a>00551 <span class="keywordtype">void</span> Circular_Buffer<T>::free() |
---|
510 | <a name="l00552"></a>00552 { |
---|
511 | <a name="l00553"></a>00553 <span class="keyword">delete</span> [] _data; |
---|
512 | <a name="l00554"></a>00554 |
---|
513 | <a name="l00555"></a>00555 _data = NULL; |
---|
514 | <a name="l00556"></a>00556 _ndata = 0; |
---|
515 | <a name="l00557"></a>00557 _write = 0; |
---|
516 | <a name="l00558"></a>00558 _read = 0; |
---|
517 | <a name="l00559"></a>00559 _rw_dist = 0; |
---|
518 | <a name="l00560"></a>00560 } |
---|
519 | <a name="l00561"></a>00561 |
---|
520 | <a name="l00562"></a>00562 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
521 | <a name="l00563"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#625975c59def123a1531949583d52393">00563</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#625975c59def123a1531949583d52393" title="Assignment operator.">Circular_Buffer<T>::operator=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Circular__Buffer.html" title="General circular buffer class.">Circular_Buffer<T></a> &s) |
---|
522 | <a name="l00564"></a>00564 { |
---|
523 | <a name="l00565"></a>00565 <a class="code" href="classitpp_1_1Circular__Buffer.html#71666739dc1f890cba5b973ff3f045b7" title="Resizing a Circular_Buffer&lt;T&gt;.">set_size</a>(s.<a class="code" href="classitpp_1_1Circular__Buffer.html#8f8e598cd1ff98d7ae0141495fef14c4">_ndata</a>); |
---|
524 | <a name="l00566"></a>00566 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < _ndata; i++) |
---|
525 | <a name="l00567"></a>00567 _data[i] = s.<a class="code" href="classitpp_1_1Circular__Buffer.html#2a7411750051641aa717feb3e16d513f">_data</a>[i]; |
---|
526 | <a name="l00568"></a>00568 _read = s.<a class="code" href="classitpp_1_1Circular__Buffer.html#232185b0ea445ec74037e0d8dc5bd2c1">_read</a>; |
---|
527 | <a name="l00569"></a>00569 _write = s.<a class="code" href="classitpp_1_1Circular__Buffer.html#6d88fb1ce4d845a34618627df4008333">_write</a>; |
---|
528 | <a name="l00570"></a>00570 _rw_dist = _write - _read; |
---|
529 | <a name="l00571"></a>00571 } |
---|
530 | <a name="l00572"></a>00572 |
---|
531 | <a name="l00573"></a>00573 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
532 | <a name="l00574"></a><a class="code" href="classitpp_1_1Circular__Buffer.html#71666739dc1f890cba5b973ff3f045b7">00574</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Circular__Buffer.html#71666739dc1f890cba5b973ff3f045b7" title="Resizing a Circular_Buffer&lt;T&gt;.">Circular_Buffer<T>::set_size</a>(<span class="keywordtype">int</span> sz, <span class="keywordtype">bool</span> copy) |
---|
533 | <a name="l00575"></a>00575 { |
---|
534 | <a name="l00576"></a>00576 <span class="keywordtype">int</span> i, min_nrof_elem; |
---|
535 | <a name="l00577"></a>00577 <span class="comment">//T *tmp;</span> |
---|
536 | <a name="l00578"></a>00578 <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> tmp; |
---|
537 | <a name="l00579"></a>00579 |
---|
538 | <a name="l00580"></a>00580 <span class="keywordflow">if</span> (_ndata == sz) |
---|
539 | <a name="l00581"></a>00581 <span class="keywordflow">return</span>; |
---|
540 | <a name="l00582"></a>00582 |
---|
541 | <a name="l00583"></a>00583 <span class="keywordflow">if</span> (copy) { |
---|
542 | <a name="l00584"></a>00584 <a class="code" href="classitpp_1_1Circular__Buffer.html#427c129a3322d3f30cce928046ab48ef" title="Peek at the latest element in the circular buffer, without removing it.">peek_reverse</a>(tmp, -1); |
---|
543 | <a name="l00585"></a>00585 min_nrof_elem = _rw_dist < sz ? _rw_dist : sz; |
---|
544 | <a name="l00586"></a>00586 alloc(sz); |
---|
545 | <a name="l00587"></a>00587 <a class="code" href="classitpp_1_1Circular__Buffer.html#15da2e68939407a13dde647afcb56529" title="Empty the circular buffer.">clear</a>(); |
---|
546 | <a name="l00588"></a>00588 <span class="keywordflow">for</span> (i = 0; i < min_nrof_elem; i++) |
---|
547 | <a name="l00589"></a>00589 <a class="code" href="classitpp_1_1Circular__Buffer.html#2f0d27553c66c278fe8d35b6a1bfa758" title="Write the element in to the buffer.">put</a>(tmp(min_nrof_elem - 1 - i)); |
---|
548 | <a name="l00590"></a>00590 } |
---|
549 | <a name="l00591"></a>00591 <span class="keywordflow">else</span> { |
---|
550 | <a name="l00592"></a>00592 free(); |
---|
551 | <a name="l00593"></a>00593 alloc(sz); |
---|
552 | <a name="l00594"></a>00594 } |
---|
553 | <a name="l00595"></a>00595 |
---|
554 | <a name="l00596"></a>00596 _ndata = sz; |
---|
555 | <a name="l00597"></a>00597 } |
---|
556 | <a name="l00598"></a>00598 |
---|
557 | <a name="l00599"></a>00599 } <span class="comment">// namespace itpp</span> |
---|
558 | <a name="l00600"></a>00600 |
---|
559 | <a name="l00601"></a>00601 <span class="preprocessor">#endif // #ifndef CIRCULAR_BUFFER_H</span> |
---|
560 | </pre></div></div> |
---|
561 | <hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:11 2009 for mixpp by |
---|
562 | <a href="http://www.doxygen.org/index.html"> |
---|
563 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
564 | </body> |
---|
565 | </html> |
---|