⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Crypto++: queue.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="namespaces.html"><span>Namespaces</span></a></li>    <li><a href="classes.html"><span>Classes</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>  </ul></div><div class="tabs">  <ul>    <li><a href="files.html"><span>File&nbsp;List</span></a></li>    <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>  </ul></div><h1>queue.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// queue.cpp - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#include "pch.h"</span><a name="l00004"></a>00004 <a name="l00005"></a>00005 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span><a name="l00006"></a>00006 <span class="preprocessor"></span><a name="l00007"></a>00007 <span class="preprocessor">#include "queue.h"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "filters.h"</span><a name="l00009"></a>00009 <a name="l00010"></a>00010 NAMESPACE_BEGIN(CryptoPP)<a name="l00011"></a>00011 <a name="l00012"></a>00012 static const <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> s_maxAutoNodeSize = 16*1024;<a name="l00013"></a>00013 <a name="l00014"></a>00014 <span class="comment">// this class for use by ByteQueue only</span><a name="l00015"></a><a class="code" href="class_byte_queue_node.html">00015</a> class <a class="code" href="class_byte_queue_node.html">ByteQueueNode</a><a name="l00016"></a>00016 {<a name="l00017"></a>00017 <span class="keyword">public</span>:<a name="l00018"></a><a class="code" href="class_byte_queue_node.html#e0d8aac35eb3d019cc116308816f52a1">00018</a>         ByteQueueNode(<span class="keywordtype">size_t</span> maxSize)<a name="l00019"></a>00019                 : buf(maxSize)<a name="l00020"></a>00020         {<a name="l00021"></a>00021                 m_head = m_tail = 0;<a name="l00022"></a>00022                 next = 0;<a name="l00023"></a>00023         }<a name="l00024"></a>00024 <a name="l00025"></a><a class="code" href="class_byte_queue_node.html#cc8554e4c27e116a3fcd3bb2dc8d1480">00025</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> MaxSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> buf.size();}<a name="l00026"></a>00026 <a name="l00027"></a><a class="code" href="class_byte_queue_node.html#82470c9722f07c056ed0b8c095daa340">00027</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> CurrentSize()<span class="keyword"> const</span><a name="l00028"></a>00028 <span class="keyword">        </span>{<a name="l00029"></a>00029                 <span class="keywordflow">return</span> m_tail-m_head;<a name="l00030"></a>00030         }<a name="l00031"></a>00031 <a name="l00032"></a><a class="code" href="class_byte_queue_node.html#b88fe4db23b9ca824a31b9ba0d0ad36d">00032</a>         <span class="keyword">inline</span> <span class="keywordtype">bool</span> UsedUp()<span class="keyword"> const</span><a name="l00033"></a>00033 <span class="keyword">        </span>{<a name="l00034"></a>00034                 <span class="keywordflow">return</span> (m_head==MaxSize());<a name="l00035"></a>00035         }<a name="l00036"></a>00036 <a name="l00037"></a><a class="code" href="class_byte_queue_node.html#33a21b84db215ff511912f77e8389f53">00037</a>         <span class="keyword">inline</span> <span class="keywordtype">void</span> Clear()<a name="l00038"></a>00038         {<a name="l00039"></a>00039                 m_head = m_tail = 0;<a name="l00040"></a>00040         }<a name="l00041"></a>00041 <a name="l00042"></a><a class="code" href="class_byte_queue_node.html#b27aedd63e91d00402d892a908842d6e">00042</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> Put(<span class="keyword">const</span> byte *begin, <span class="keywordtype">size_t</span> length)<a name="l00043"></a>00043         {<a name="l00044"></a>00044                 <span class="keywordtype">size_t</span> l = STDMIN(length, MaxSize()-m_tail);<a name="l00045"></a>00045                 <span class="keywordflow">if</span> (buf+m_tail != begin)<a name="l00046"></a>00046                         memcpy(buf+m_tail, begin, l);<a name="l00047"></a>00047                 m_tail += l;<a name="l00048"></a>00048                 <span class="keywordflow">return</span> l;<a name="l00049"></a>00049         }<a name="l00050"></a>00050 <a name="l00051"></a><a class="code" href="class_byte_queue_node.html#5c005b22bbd94d3cabb1c6a258731eda">00051</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> Peek(byte &amp;outByte)<span class="keyword"> const</span><a name="l00052"></a>00052 <span class="keyword">        </span>{<a name="l00053"></a>00053                 <span class="keywordflow">if</span> (m_tail==m_head)<a name="l00054"></a>00054                         <span class="keywordflow">return</span> 0;<a name="l00055"></a>00055 <a name="l00056"></a>00056                 outByte=buf[m_head];<a name="l00057"></a>00057                 <span class="keywordflow">return</span> 1;<a name="l00058"></a>00058         }<a name="l00059"></a>00059 <a name="l00060"></a><a class="code" href="class_byte_queue_node.html#e5a377f334c980ae0b8ecbfc929b61a1">00060</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> Peek(byte *target, <span class="keywordtype">size_t</span> copyMax)<span class="keyword"> const</span><a name="l00061"></a>00061 <span class="keyword">        </span>{<a name="l00062"></a>00062                 <span class="keywordtype">size_t</span> len = STDMIN(copyMax, m_tail-m_head);<a name="l00063"></a>00063                 memcpy(target, buf+m_head, len);<a name="l00064"></a>00064                 <span class="keywordflow">return</span> len;<a name="l00065"></a>00065         }<a name="l00066"></a>00066 <a name="l00067"></a><a class="code" href="class_byte_queue_node.html#9c66c32bfcee88712fb99ad9ef7f9eca">00067</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> CopyTo(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;target, <span class="keyword">const</span> std::string &amp;channel=<a class="code" href="class_buffered_transformation.html#5e938c68f2a5e32a03440b1dc2bdc74a">BufferedTransformation::NULL_CHANNEL</a>)<span class="keyword"> const</span><a name="l00068"></a>00068 <span class="keyword">        </span>{<a name="l00069"></a>00069                 <span class="keywordtype">size_t</span> len = m_tail-m_head;<a name="l00070"></a>00070                 target.<a class="code" href="class_buffered_transformation.html#97a60b54fafdb3df59e1457ef629fc5f">ChannelPut</a>(channel, buf+m_head, len);<a name="l00071"></a>00071                 <span class="keywordflow">return</span> len;<a name="l00072"></a>00072         }<a name="l00073"></a>00073 <a name="l00074"></a><a class="code" href="class_byte_queue_node.html#e604984430b4f7b4e0750f9a4c2547d4">00074</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> CopyTo(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;target, <span class="keywordtype">size_t</span> copyMax, <span class="keyword">const</span> std::string &amp;channel=<a class="code" href="class_buffered_transformation.html#5e938c68f2a5e32a03440b1dc2bdc74a">BufferedTransformation::NULL_CHANNEL</a>)<span class="keyword"> const</span><a name="l00075"></a>00075 <span class="keyword">        </span>{<a name="l00076"></a>00076                 <span class="keywordtype">size_t</span> len = STDMIN(copyMax, m_tail-m_head);<a name="l00077"></a>00077                 target.<a class="code" href="class_buffered_transformation.html#97a60b54fafdb3df59e1457ef629fc5f">ChannelPut</a>(channel, buf+m_head, len);<a name="l00078"></a>00078                 <span class="keywordflow">return</span> len;<a name="l00079"></a>00079         }<a name="l00080"></a>00080 <a name="l00081"></a><a class="code" href="class_byte_queue_node.html#92f03eddb50d7a03cb067dba18c7e3d3">00081</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> Get(byte &amp;outByte)<a name="l00082"></a>00082         {<a name="l00083"></a>00083                 <span class="keywordtype">size_t</span> len = Peek(outByte);<a name="l00084"></a>00084                 m_head += len;<a name="l00085"></a>00085                 <span class="keywordflow">return</span> len;<a name="l00086"></a>00086         }<a name="l00087"></a>00087 <a name="l00088"></a><a class="code" href="class_byte_queue_node.html#e8f0d77255c3d1d98d4931552873bc1f">00088</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> Get(byte *outString, <span class="keywordtype">size_t</span> getMax)<a name="l00089"></a>00089         {<a name="l00090"></a>00090                 <span class="keywordtype">size_t</span> len = Peek(outString, getMax);<a name="l00091"></a>00091                 m_head += len;<a name="l00092"></a>00092                 <span class="keywordflow">return</span> len;<a name="l00093"></a>00093         }<a name="l00094"></a>00094 <a name="l00095"></a><a class="code" href="class_byte_queue_node.html#de9228051bb35b138d3fc0bce483931a">00095</a>         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> TransferTo(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp;target, <span class="keyword">const</span> std::string &amp;channel=<a class="code" href="class_buffered_transformation.html#5e938c68f2a5e32a03440b1dc2bdc74a">BufferedTransformation::NULL_CHANNEL</a>)<a name="l00096"></a>00096         {<a name="l00097"></a>00097                 <span class="keywordtype">size_t</span> len = m_tail-m_head;<a name="l00098"></a>00098                 target.<a class="code" href="class_buffered_transformation.html#3dc27692b14108ed057beb4db67fed2f">ChannelPutModifiable</a>(channel, buf+m_head, len);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -