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

📄 zdeflate_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++: zdeflate.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>zdeflate.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// zdeflate.cpp - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="comment">// Many of the algorithms and tables used here came from the deflate implementation</span><a name="l00004"></a>00004 <span class="comment">// by Jean-loup Gailly, which was included in Crypto++ 4.0 and earlier. I completely</span><a name="l00005"></a>00005 <span class="comment">// rewrote it in order to fix a bug that I could not figure out. This code</span><a name="l00006"></a>00006 <span class="comment">// is less clever, but hopefully more understandable and maintainable.</span><a name="l00007"></a>00007 <a name="l00008"></a>00008 <span class="preprocessor">#include "pch.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "zdeflate.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include &lt;functional&gt;</span><a name="l00011"></a>00011 <a name="l00012"></a>00012 NAMESPACE_BEGIN(CryptoPP)<a name="l00013"></a>00013 <a name="l00014"></a>00014 using namespace std;<a name="l00015"></a>00015 <a name="l00016"></a><a class="code" href="class_low_first_bit_writer.html#8d67445920583ea9223ee504d190a8ec">00016</a> <a class="code" href="class_low_first_bit_writer.html" title="_">LowFirstBitWriter</a>::<a class="code" href="class_low_first_bit_writer.html" title="_">LowFirstBitWriter</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment)<a name="l00017"></a>00017         : <a class="code" href="class_filter.html" title="provides an implementation of BufferedTransformation's attachment interface">Filter</a>(attachment), m_counting(false), m_buffer(0), m_bitsBuffered(0), m_bytesBuffered(0)<a name="l00018"></a>00018 {<a name="l00019"></a>00019 }<a name="l00020"></a>00020 <a name="l00021"></a><a class="code" href="class_low_first_bit_writer.html#b5e98d9da5beda8cf6b1e33001ce598a">00021</a> <span class="keywordtype">void</span> <a class="code" href="class_low_first_bit_writer.html#b5e98d9da5beda8cf6b1e33001ce598a">LowFirstBitWriter::StartCounting</a>()<a name="l00022"></a>00022 {<a name="l00023"></a>00023         assert(!<a class="code" href="class_low_first_bit_writer.html#58294b1ee6610ff1ac6ead1beb31bace">m_counting</a>);<a name="l00024"></a>00024         <a class="code" href="class_low_first_bit_writer.html#58294b1ee6610ff1ac6ead1beb31bace">m_counting</a> = <span class="keyword">true</span>;<a name="l00025"></a>00025         <a class="code" href="class_low_first_bit_writer.html#98734af15461d4d8783b822efb1af291">m_bitCount</a> = 0;<a name="l00026"></a>00026 }<a name="l00027"></a>00027 <a name="l00028"></a><a class="code" href="class_low_first_bit_writer.html#d1f9f0d2d34b06f074ad5de42e59348f">00028</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="class_low_first_bit_writer.html#d1f9f0d2d34b06f074ad5de42e59348f">LowFirstBitWriter::FinishCounting</a>()<a name="l00029"></a>00029 {<a name="l00030"></a>00030         assert(<a class="code" href="class_low_first_bit_writer.html#58294b1ee6610ff1ac6ead1beb31bace">m_counting</a>);<a name="l00031"></a>00031         <a class="code" href="class_low_first_bit_writer.html#58294b1ee6610ff1ac6ead1beb31bace">m_counting</a> = <span class="keyword">false</span>;<a name="l00032"></a>00032         <span class="keywordflow">return</span> <a class="code" href="class_low_first_bit_writer.html#98734af15461d4d8783b822efb1af291">m_bitCount</a>;<a name="l00033"></a>00033 }<a name="l00034"></a>00034 <a name="l00035"></a><a class="code" href="class_low_first_bit_writer.html#8554aa2126e1236fbcf8956ef98664bc">00035</a> <span class="keywordtype">void</span> <a class="code" href="class_low_first_bit_writer.html#8554aa2126e1236fbcf8956ef98664bc">LowFirstBitWriter::PutBits</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> value, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)<a name="l00036"></a>00036 {<a name="l00037"></a>00037         <span class="keywordflow">if</span> (<a class="code" href="class_low_first_bit_writer.html#58294b1ee6610ff1ac6ead1beb31bace">m_counting</a>)<a name="l00038"></a>00038                 <a class="code" href="class_low_first_bit_writer.html#98734af15461d4d8783b822efb1af291">m_bitCount</a> += length;<a name="l00039"></a>00039         <span class="keywordflow">else</span><a name="l00040"></a>00040         {<a name="l00041"></a>00041                 <a class="code" href="class_low_first_bit_writer.html#0df2a5478042587afd61c8f2c0c04b59">m_buffer</a> |= value &lt;&lt; <a class="code" href="class_low_first_bit_writer.html#20da2a4de9640ac6f3b785a7fff56c60">m_bitsBuffered</a>;<a name="l00042"></a>00042                 m_bitsBuffered += length;<a name="l00043"></a>00043                 assert(m_bitsBuffered &lt;= <span class="keyword">sizeof</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)*8);<a name="l00044"></a>00044                 <span class="keywordflow">while</span> (m_bitsBuffered &gt;= 8)<a name="l00045"></a>00045                 {<a name="l00046"></a>00046                         <a class="code" href="class_low_first_bit_writer.html#ff9c2060798e6c750768b3112721b522">m_outputBuffer</a>[<a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a>++] = (byte)<a class="code" href="class_low_first_bit_writer.html#0df2a5478042587afd61c8f2c0c04b59">m_buffer</a>;<a name="l00047"></a>00047                         <span class="keywordflow">if</span> (<a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a> == <a class="code" href="class_low_first_bit_writer.html#ff9c2060798e6c750768b3112721b522">m_outputBuffer</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>())<a name="l00048"></a>00048                         {<a name="l00049"></a>00049                                 <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#e15df84a7b67c25dfe2ce0ef5a74123c" title="input multiple bytes that may be modified by callee">PutModifiable</a>(<a class="code" href="class_low_first_bit_writer.html#ff9c2060798e6c750768b3112721b522">m_outputBuffer</a>, <a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a>);<a name="l00050"></a>00050                                 <a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a> = 0;<a name="l00051"></a>00051                         }<a name="l00052"></a>00052                         <a class="code" href="class_low_first_bit_writer.html#0df2a5478042587afd61c8f2c0c04b59">m_buffer</a> &gt;&gt;= 8;<a name="l00053"></a>00053                         m_bitsBuffered -= 8;<a name="l00054"></a>00054                 }<a name="l00055"></a>00055         }<a name="l00056"></a>00056 }<a name="l00057"></a>00057 <a name="l00058"></a><a class="code" href="class_low_first_bit_writer.html#e1754cdbee6731279670409c65db0770">00058</a> <span class="keywordtype">void</span> <a class="code" href="class_low_first_bit_writer.html#e1754cdbee6731279670409c65db0770">LowFirstBitWriter::FlushBitBuffer</a>()<a name="l00059"></a>00059 {<a name="l00060"></a>00060         <span class="keywordflow">if</span> (<a class="code" href="class_low_first_bit_writer.html#58294b1ee6610ff1ac6ead1beb31bace">m_counting</a>)<a name="l00061"></a>00061                 <a class="code" href="class_low_first_bit_writer.html#98734af15461d4d8783b822efb1af291">m_bitCount</a> += 8*(<a class="code" href="class_low_first_bit_writer.html#20da2a4de9640ac6f3b785a7fff56c60">m_bitsBuffered</a> &gt; 0);<a name="l00062"></a>00062         <span class="keywordflow">else</span><a name="l00063"></a>00063         {<a name="l00064"></a>00064                 <span class="keywordflow">if</span> (<a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a> &gt; 0)<a name="l00065"></a>00065                 {<a name="l00066"></a>00066                         <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#e15df84a7b67c25dfe2ce0ef5a74123c" title="input multiple bytes that may be modified by callee">PutModifiable</a>(<a class="code" href="class_low_first_bit_writer.html#ff9c2060798e6c750768b3112721b522">m_outputBuffer</a>, <a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a>);<a name="l00067"></a>00067                         <a class="code" href="class_low_first_bit_writer.html#75a39e9548b284609320ab615289040d">m_bytesBuffered</a> = 0;<a name="l00068"></a>00068                 }<a name="l00069"></a>00069                 <span class="keywordflow">if</span> (<a class="code" href="class_low_first_bit_writer.html#20da2a4de9640ac6f3b785a7fff56c60">m_bitsBuffered</a> &gt; 0)<a name="l00070"></a>00070                 {<a name="l00071"></a>00071                         <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>((byte)<a class="code" href="class_low_first_bit_writer.html#0df2a5478042587afd61c8f2c0c04b59">m_buffer</a>);<a name="l00072"></a>00072                         m_buffer = 0;<a name="l00073"></a>00073                         <a class="code" href="class_low_first_bit_writer.html#20da2a4de9640ac6f3b785a7fff56c60">m_bitsBuffered</a> = 0;<a name="l00074"></a>00074                 }

⌨️ 快捷键说明

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