📄 files_8cpp-source.html
字号:
<!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++: files.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 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 List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul></div><h1>files.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// files.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 "files.h"</span><a name="l00008"></a>00008 <a name="l00009"></a>00009 <span class="preprocessor">#include <limits></span><a name="l00010"></a>00010 <a name="l00011"></a>00011 NAMESPACE_BEGIN(CryptoPP)<a name="l00012"></a>00012 <a name="l00013"></a>00013 using namespace std;<a name="l00014"></a>00014 <a name="l00015"></a>00015 <span class="keywordtype">void</span> Files_TestInstantiations()<a name="l00016"></a>00016 {<a name="l00017"></a>00017 <a class="code" href="class_file_store.html" title="file-based implementation of Store interface">FileStore</a> f0;<a name="l00018"></a>00018 <a class="code" href="class_file_source.html" title="file-based implementation of Source interface">FileSource</a> f1;<a name="l00019"></a>00019 <a class="code" href="class_file_sink.html" title="file-based implementation of Sink interface">FileSink</a> f2;<a name="l00020"></a>00020 }<a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="keywordtype">void</span> FileStore::StoreInitialize(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &parameters)<a name="l00023"></a>00023 {<a name="l00024"></a>00024 m_file.<a class="code" href="classmember__ptr.html#0191c833924d93e9093b07bab31010fe">reset</a>(<span class="keyword">new</span> std::ifstream);<a name="l00025"></a>00025 <span class="keyword">const</span> <span class="keywordtype">char</span> *fileName;<a name="l00026"></a>00026 <span class="keywordflow">if</span> (parameters.<a class="code" href="class_name_value_pairs.html#96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(<a class="code" href="namespace_name.html#d66764c80784dda0472b4862eed4cf94" title="const char *">Name::InputFileName</a>(), fileName))<a name="l00027"></a>00027 {<a name="l00028"></a>00028 ios::openmode binary = parameters.<a class="code" href="class_name_value_pairs.html#943b2009297783f1c35bae46efc3b5f7" title="get a named value, returns the default if the name doesn't exist">GetValueWithDefault</a>(<a class="code" href="namespace_name.html#3fa390ba37a12cbc0475ecb3a3482fa7" title="bool">Name::InputBinaryMode</a>(), <span class="keyword">true</span>) ? ios::binary : ios::openmode(0);<a name="l00029"></a>00029 m_file->open(fileName, ios::in | binary);<a name="l00030"></a>00030 <span class="keywordflow">if</span> (!*m_file)<a name="l00031"></a>00031 <span class="keywordflow">throw</span> OpenErr(fileName);<a name="l00032"></a>00032 m_stream = m_file.<a class="code" href="classmember__ptr.html#2d10dec2a51691b589d56b71ec78e59a">get</a>();<a name="l00033"></a>00033 }<a name="l00034"></a>00034 <span class="keywordflow">else</span><a name="l00035"></a>00035 {<a name="l00036"></a>00036 m_stream = NULL;<a name="l00037"></a>00037 parameters.<a class="code" href="class_name_value_pairs.html#96686e9f8d6ce3ab870e516fb72b608e" title="get a named value, returns true if the name exists">GetValue</a>(<a class="code" href="namespace_name.html#86928da4acaa3a6bfe38b16bfda4bc68" title="std::istream *">Name::InputStreamPointer</a>(), m_stream);<a name="l00038"></a>00038 }<a name="l00039"></a>00039 m_waiting = <span class="keyword">false</span>;<a name="l00040"></a>00040 }<a name="l00041"></a>00041 <a name="l00042"></a><a class="code" href="class_file_store.html#27e29d3d04ddf2888d968327b26d9c88">00042</a> lword <a class="code" href="class_file_store.html#27e29d3d04ddf2888d968327b26d9c88" title="returns number of bytes that is currently ready for retrieval">FileStore::MaxRetrievable</a>()<span class="keyword"> const</span><a name="l00043"></a>00043 <span class="keyword"></span>{<a name="l00044"></a>00044 <span class="keywordflow">if</span> (!m_stream)<a name="l00045"></a>00045 <span class="keywordflow">return</span> 0;<a name="l00046"></a>00046 <a name="l00047"></a>00047 streampos current = m_stream->tellg();<a name="l00048"></a>00048 streampos end = m_stream->seekg(0, ios::end).tellg();<a name="l00049"></a>00049 m_stream->seekg(current);<a name="l00050"></a>00050 <span class="keywordflow">return</span> end-current;<a name="l00051"></a>00051 }<a name="l00052"></a>00052 <a name="l00053"></a><a class="code" href="class_file_store.html#792ca84496eb6fc13fb9f5d14244a42c">00053</a> <span class="keywordtype">size_t</span> <a class="code" href="class_file_store.html#792ca84496eb6fc13fb9f5d14244a42c" title="upon return, byteCount contains number of bytes that have finished being transfered...">FileStore::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="l00054"></a>00054 {<a name="l00055"></a>00055 <span class="keywordflow">if</span> (!m_stream)<a name="l00056"></a>00056 {<a name="l00057"></a>00057 transferBytes = 0;<a name="l00058"></a>00058 <span class="keywordflow">return</span> 0;<a name="l00059"></a>00059 }<a name="l00060"></a>00060 <a name="l00061"></a>00061 lword size=transferBytes;<a name="l00062"></a>00062 transferBytes = 0;<a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="keywordflow">if</span> (m_waiting)<a name="l00065"></a>00065 <span class="keywordflow">goto</span> output;<a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keywordflow">while</span> (size && m_stream->good())<a name="l00068"></a>00068 {<a name="l00069"></a>00069 {<a name="l00070"></a>00070 <span class="keywordtype">size_t</span> spaceSize = 1024;<a name="l00071"></a>00071 m_space = <a class="code" href="struct_filter_put_space_helper.html#85fea9f0455741e4b340a3e035df9a39">HelpCreatePutSpace</a>(target, channel, 1, UnsignedMin(<span class="keywordtype">size_t</span>(0)-1, size), spaceSize);<a name="l00072"></a>00072 <a name="l00073"></a>00073 m_stream->read((<span class="keywordtype">char</span> *)m_space, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)STDMIN(size, (lword)spaceSize));<a name="l00074"></a>00074 }<a name="l00075"></a>00075 m_len = m_stream->gcount();<a name="l00076"></a>00076 <span class="keywordtype">size_t</span> blockedBytes;<a name="l00077"></a>00077 output:<a name="l00078"></a>00078 blockedBytes = target.<a class="code" href="class_buffered_transformation.html#eab62459524d9c93531ec365ba930be3">ChannelPutModifiable2</a>(channel, m_space, m_len, 0, blocking);<a name="l00079"></a>00079 m_waiting = blockedBytes > 0;<a name="l00080"></a>00080 <span class="keywordflow">if</span> (m_waiting)<a name="l00081"></a>00081 <span class="keywordflow">return</span> blockedBytes;<a name="l00082"></a>00082 size -= m_len;<a name="l00083"></a>00083 transferBytes += m_len;<a name="l00084"></a>00084 }<a name="l00085"></a>00085 <a name="l00086"></a>00086 <span class="keywordflow">if</span> (!m_stream->good() && !m_stream->eof())<a name="l00087"></a>00087 <span class="keywordflow">throw</span> <a class="code" href="class_file_store_1_1_read_err.html">ReadErr</a>();<a name="l00088"></a>00088 <a name="l00089"></a>00089 <span class="keywordflow">return</span> 0;<a name="l00090"></a>00090 }<a name="l00091"></a>00091 <a name="l00092"></a><a class="code" href="class_file_store.html#62603d2f8ffa342e9be7b7a2ee5dfaf4">00092</a> <span class="keywordtype">size_t</span> <a class="code" href="class_file_store.html#62603d2f8ffa342e9be7b7a2ee5dfaf4" title="upon return, begin contains the start position of data yet to be finished copying...">FileStore::CopyRangeTo2</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &target, lword &begin, lword end, <span class="keyword">const</span> std::string &channel, <span class="keywordtype">bool</span> blocking)<span class="keyword"> const</span><a name="l00093"></a>00093 <span class="keyword"></span>{<a name="l00094"></a>00094 <span class="keywordflow">if</span> (!m_stream)<a name="l00095"></a>00095 <span class="keywordflow">return</span> 0;<a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keywordflow">if</span> (begin == 0 && end == 1)<a name="l00098"></a>00098 {<a name="l00099"></a>00099 <span class="keywordtype">int</span> result = m_stream->peek();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -