📄 queue_8cpp-source.html
字号:
<a name="l00218"></a>00218 <span class="keywordflow">if</span> (m_lazyLength > 0)<a name="l00219"></a>00219 <a class="code" href="class_byte_queue.html#6d004338c41f8e04a723c7adab5d0895">FinalizeLazyPut</a>();<a name="l00220"></a>00220 <a name="l00221"></a>00221 <span class="keywordtype">size_t</span> len;<a name="l00222"></a>00222 <span class="keywordflow">while</span> ((len=m_tail-><a class="code" href="class_byte_queue_node.html#b27aedd63e91d00402d892a908842d6e">Put</a>(inString, length)) < length)<a name="l00223"></a>00223 {<a name="l00224"></a>00224 inString += len;<a name="l00225"></a>00225 length -= len;<a name="l00226"></a>00226 <span class="keywordflow">if</span> (m_autoNodeSize && m_nodeSize < s_maxAutoNodeSize)<a name="l00227"></a>00227 <span class="keywordflow">do</span><a name="l00228"></a>00228 {<a name="l00229"></a>00229 m_nodeSize *= 2;<a name="l00230"></a>00230 }<a name="l00231"></a>00231 <span class="keywordflow">while</span> (m_nodeSize < length && m_nodeSize < s_maxAutoNodeSize);<a name="l00232"></a>00232 m_tail-><a class="code" href="class_byte_queue_node.html#ee1bdb525b2dd8c5d98de76949a85b1a">next</a> = <span class="keyword">new</span> <a class="code" href="class_byte_queue_node.html">ByteQueueNode</a>(STDMAX(m_nodeSize, length));<a name="l00233"></a>00233 m_tail = m_tail-><a class="code" href="class_byte_queue_node.html#ee1bdb525b2dd8c5d98de76949a85b1a">next</a>;<a name="l00234"></a>00234 }<a name="l00235"></a>00235 <a name="l00236"></a>00236 <span class="keywordflow">return</span> 0;<a name="l00237"></a>00237 }<a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="keywordtype">void</span> ByteQueue::CleanupUsedNodes()<a name="l00240"></a>00240 {<a name="l00241"></a>00241 <span class="keywordflow">while</span> (m_head != m_tail && m_head-><a class="code" href="class_byte_queue_node.html#b88fe4db23b9ca824a31b9ba0d0ad36d">UsedUp</a>())<a name="l00242"></a>00242 {<a name="l00243"></a>00243 <a class="code" href="class_byte_queue_node.html">ByteQueueNode</a> *temp=m_head;<a name="l00244"></a>00244 m_head=m_head-><a class="code" href="class_byte_queue_node.html#ee1bdb525b2dd8c5d98de76949a85b1a">next</a>;<a name="l00245"></a>00245 <span class="keyword">delete</span> temp;<a name="l00246"></a>00246 }<a name="l00247"></a>00247 <a name="l00248"></a>00248 <span class="keywordflow">if</span> (m_head-><a class="code" href="class_byte_queue_node.html#82470c9722f07c056ed0b8c095daa340">CurrentSize</a>() == 0)<a name="l00249"></a>00249 m_head-><a class="code" href="class_byte_queue_node.html#33a21b84db215ff511912f77e8389f53">Clear</a>();<a name="l00250"></a>00250 }<a name="l00251"></a>00251 <a name="l00252"></a><a class="code" href="class_byte_queue.html#127af9acc2ad34922953abd30447afa1">00252</a> <span class="keywordtype">void</span> <a class="code" href="class_byte_queue.html#127af9acc2ad34922953abd30447afa1">ByteQueue::LazyPut</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> size)<a name="l00253"></a>00253 {<a name="l00254"></a>00254 <span class="keywordflow">if</span> (m_lazyLength > 0)<a name="l00255"></a>00255 <a class="code" href="class_byte_queue.html#6d004338c41f8e04a723c7adab5d0895">FinalizeLazyPut</a>();<a name="l00256"></a>00256 <a name="l00257"></a>00257 <span class="keywordflow">if</span> (inString == m_tail-><a class="code" href="class_byte_queue_node.html#1872d9ce267ef28d540e3353d0bf6ce9">buf</a>+m_tail-><a class="code" href="class_byte_queue_node.html#fac0e8466bd492fb761f3cd6409c9077">m_tail</a>)<a name="l00258"></a>00258 <a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(inString, size);<a name="l00259"></a>00259 <span class="keywordflow">else</span><a name="l00260"></a>00260 {<a name="l00261"></a>00261 m_lazyString = <span class="keyword">const_cast<</span>byte *<span class="keyword">></span>(inString);<a name="l00262"></a>00262 m_lazyLength = size;<a name="l00263"></a>00263 m_lazyStringModifiable = <span class="keyword">false</span>;<a name="l00264"></a>00264 }<a name="l00265"></a>00265 }<a name="l00266"></a>00266 <a name="l00267"></a><a class="code" href="class_byte_queue.html#c90c40206fc9e8ae2c4fc984347a360a">00267</a> <span class="keywordtype">void</span> <a class="code" href="class_byte_queue.html#c90c40206fc9e8ae2c4fc984347a360a">ByteQueue::LazyPutModifiable</a>(byte *inString, <span class="keywordtype">size_t</span> size)<a name="l00268"></a>00268 {<a name="l00269"></a>00269 <span class="keywordflow">if</span> (m_lazyLength > 0)<a name="l00270"></a>00270 <a class="code" href="class_byte_queue.html#6d004338c41f8e04a723c7adab5d0895">FinalizeLazyPut</a>();<a name="l00271"></a>00271 m_lazyString = inString;<a name="l00272"></a>00272 m_lazyLength = size;<a name="l00273"></a>00273 m_lazyStringModifiable = <span class="keyword">true</span>;<a name="l00274"></a>00274 }<a name="l00275"></a>00275 <a name="l00276"></a><a class="code" href="class_byte_queue.html#9c7e4d3fa01a23314b7809885b770d23">00276</a> <span class="keywordtype">void</span> <a class="code" href="class_byte_queue.html#9c7e4d3fa01a23314b7809885b770d23">ByteQueue::UndoLazyPut</a>(<span class="keywordtype">size_t</span> size)<a name="l00277"></a>00277 {<a name="l00278"></a>00278 <span class="keywordflow">if</span> (m_lazyLength < size)<a name="l00279"></a>00279 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html" title="exception thrown when an invalid argument is detected">InvalidArgument</a>(<span class="stringliteral">"ByteQueue: size specified for UndoLazyPut is too large"</span>);<a name="l00280"></a>00280 <a name="l00281"></a>00281 m_lazyLength -= size;<a name="l00282"></a>00282 }<a name="l00283"></a>00283 <a name="l00284"></a><a class="code" href="class_byte_queue.html#6d004338c41f8e04a723c7adab5d0895">00284</a> <span class="keywordtype">void</span> <a class="code" href="class_byte_queue.html#6d004338c41f8e04a723c7adab5d0895">ByteQueue::FinalizeLazyPut</a>()<a name="l00285"></a>00285 {<a name="l00286"></a>00286 <span class="keywordtype">size_t</span> len = m_lazyLength;<a name="l00287"></a>00287 m_lazyLength = 0;<a name="l00288"></a>00288 <span class="keywordflow">if</span> (len)<a name="l00289"></a>00289 <a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(m_lazyString, len);<a name="l00290"></a>00290 }<a name="l00291"></a>00291 <a name="l00292"></a><a class="code" href="class_byte_queue.html#19413e3aa72b749e3771d617e8eca632">00292</a> <span class="keywordtype">size_t</span> <a class="code" href="class_byte_queue.html#19413e3aa72b749e3771d617e8eca632" title="try to retrieve a single byte">ByteQueue::Get</a>(byte &outByte)<a name="l00293"></a>00293 {<a name="l00294"></a>00294 <span class="keywordflow">if</span> (m_head-><a class="code" href="class_byte_queue_node.html#92f03eddb50d7a03cb067dba18c7e3d3">Get</a>(outByte))<a name="l00295"></a>00295 {<a name="l00296"></a>00296 <span class="keywordflow">if</span> (m_head-><a class="code" href="class_byte_queue_node.html#b88fe4db23b9ca824a31b9ba0d0ad36d">UsedUp</a>())<a name="l00297"></a>00297 CleanupUsedNodes();<a name="l00298"></a>00298 <span class="keywordflow">return</span> 1;<a name="l00299"></a>00299 }<a name="l00300"></a>00300 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m_lazyLength > 0)<a name="l00301"></a>00301 {<a name="l00302"></a>00302 outByte = *m_lazyString++;<a name="l00303"></a>00303 m_lazyLength--;<a name="l00304"></a>00304 <span class="keywordflow">return</span> 1;<a name="l00305"></a>00305 }<a name="l00306"></a>00306 <span class="keywordflow">else</span><a name="l00307"></a>00307 <span class="keywordflow">return</span> 0;<a name="l00308"></a>00308 }<a name="l00309"></a>00309 <a name="l00310"></a><a class="code" href="class_byte_queue.html#933457ad0a5a34fb5e7dc71b2a92c3a7">00310</a> <span class="keywordtype">size_t</span> <a class="code" href="class_byte_queue.html#19413e3aa72b749e3771d617e8eca632" title="try to retrieve a single byte">ByteQueue::Get</a>(byte *outString, <span class="keywordtype">size_t</span> getMax)<a name="l00311"></a>00311 {<a name="l00312"></a>00312 <a class="code" href="class_array_sink.html" title="Copy input to a memory buffer.">ArraySink</a> sink(outString, getMax);<a name="l00313"></a>00313 <span class="keywordflow">return</span> (<span class="keywordtype">size_t</span>)<a class="code" href="class_buffered_transformation.html#91c4526148274ae9cb68803bb2d2a2aa" title="move transferMax bytes of the buffered output to target as input">TransferTo</a>(sink, getMax);<a name="l00314"></a>00314 }<a name="l00315"></a>00315 <a name="l00316"></a><a class="code" href="class_byte_queue.html#67e9cc7f56a2be014ee4c9f033bb2ada">00316</a> <span class="keywordtype">size_t</span> <a class="code" href="class_byte_queue.html#67e9cc7f56a2be014ee4c9f033bb2ada" title="peek at the next byte without removing it from the output buffer">ByteQueue::Peek</a>(byte &outByte)<span class="keyword"> const</span><a name="l00317"></a>00317 <span class="keyword"></span>{<a name="l00318"></a>00318 <span class="keywordflow">if</span> (m_head-><a class="code" href="class_byte_queue_node.html#5c005b22bbd94d3cabb1c6a258731eda">Peek</a>(outByte))<a name="l00319"></a>00319 <span class="keywordflow">return</span> 1;<a name="l00320"></a>00320 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m_lazyLength > 0)<a name="l00321"></a>00321 {<a name="l00322"></a>00322 outByte = *m_lazyString;<a name="l00323"></a>00323 <span class="keywordflow">return</span> 1;<a name="l00324"></a>00324 }<a name="l00325"></a>00325 <span class="keywordflow">else</span><a name="l00326"></a>00326 <span class="keywordflow">return</span> 0;<a name="l00327"></a>00327 }<a name="l00328"></a>00328 <a name="l00329"></a><a class="code" href="class_byte_queue.html#b18a5abc1d881c014705a7ea0c467d81">00329</a> <span class="keywordtype">size_t</span> <a class="code" href="class_byte_queue.html#67e9cc7f56a2be014ee4c9f033bb2ada" title="peek at the next byte without removing it from the output buffer">ByteQueue::Peek</a>(byte *outString, <span class="keywordtype">size_t</span> peekMax)<span class="keyword"> const</span><a name="l00330"></a>00330 <span class="keyword"></span>{<a name="l00331"></a>00331 <a class="code" href="class_array_sink.html" title="Copy input to a memory buffer.">ArraySink</a> sink(outString, peekMax);<a name="l00332"></a>00332 <span class="keywordflow">return</span> (<span class="keywordtype">size_t</span>)<a class="code" href="class_buffered_transformation.html#8d4359262c67b3e10d193ba30ef193c5" title="copy copyMax bytes of the buffered output to target as input">CopyTo</a>(sink, peekMax);<a name="l00333"></a>00333 }<a name="l00334"></a>00334 <a name="l00335"></a><a class="code" href="class_byte_queue.html#35a4820b4ff8c30479423ac672cd264f">00335</a> <span class="keywordtype">size_t</span> <a class="code" href="class_byte_queue.html#35a4820b4ff8c30479423ac672cd264f" title="upon return, byteCount contains number of bytes that have finished being transfered...">ByteQueue::TransferTo2</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &target, lword &transferBytes, <span class="keyword">const</span> std::string &channel, <span class="keywordtype">bool</span> blocking)<a name="l00336"></a>00336 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -