📄 channels_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: channels.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>channels.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// channels.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 00005 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span>00006 <span class="preprocessor"></span>00007 <span class="preprocessor">#include "channels.h"</span>00008 00009 NAMESPACE_BEGIN(CryptoPP)00010 USING_NAMESPACE(std)00011 00012 #<span class="keywordflow">if</span> 000013 <span class="keywordtype">void</span> MessageSwitch::AddDefaultRoute(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> &destination, <span class="keyword">const</span> std::string &channel)00014 {00015 m_defaultRoutes.push_back(Route(&destination, channel));00016 }00017 00018 <span class="keywordtype">void</span> MessageSwitch::AddRoute(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> begin, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> end, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> &destination, <span class="keyword">const</span> std::string &channel)00019 {00020 RangeRoute route(begin, end, Route(&destination, channel));00021 RouteList::iterator it = upper_bound(m_routes.begin(), m_routes.end(), route);00022 m_routes.insert(it, route);00023 }00024 00025 <span class="comment">/*</span>00026 <span class="comment">class MessageRouteIterator</span>00027 <span class="comment">{</span>00028 <span class="comment">public:</span>00029 <span class="comment"> typedef MessageSwitch::RouteList::const_iterator RouteIterator;</span>00030 <span class="comment"> typedef MessageSwitch::DefaultRouteList::const_iterator DefaultIterator;</span>00031 <span class="comment"></span>00032 <span class="comment"> bool m_useDefault;</span>00033 <span class="comment"> RouteIterator m_itRouteCurrent, m_itRouteEnd;</span>00034 <span class="comment"> DefaultIterator m_itDefaultCurrent, m_itDefaultEnd;</span>00035 <span class="comment"></span>00036 <span class="comment"> MessageRouteIterator(MessageSwitch &ms, const std::string &channel)</span>00037 <span class="comment"> : m_channel(channel)</span>00038 <span class="comment"> {</span>00039 <span class="comment"> pair<MapIterator, MapIterator> range = cs.m_routeMap.equal_range(channel);</span>00040 <span class="comment"> if (range.first == range.second)</span>00041 <span class="comment"> {</span>00042 <span class="comment"> m_useDefault = true;</span>00043 <span class="comment"> m_itListCurrent = cs.m_defaultRoutes.begin();</span>00044 <span class="comment"> m_itListEnd = cs.m_defaultRoutes.end();</span>00045 <span class="comment"> }</span>00046 <span class="comment"> else</span>00047 <span class="comment"> {</span>00048 <span class="comment"> m_useDefault = false;</span>00049 <span class="comment"> m_itMapCurrent = range.first;</span>00050 <span class="comment"> m_itMapEnd = range.second;</span>00051 <span class="comment"> }</span>00052 <span class="comment"> }</span>00053 <span class="comment"></span>00054 <span class="comment"> bool End() const</span>00055 <span class="comment"> {</span>00056 <span class="comment"> return m_useDefault ? m_itListCurrent == m_itListEnd : m_itMapCurrent == m_itMapEnd;</span>00057 <span class="comment"> }</span>00058 <span class="comment"></span>00059 <span class="comment"> void Next()</span>00060 <span class="comment"> {</span>00061 <span class="comment"> if (m_useDefault)</span>00062 <span class="comment"> ++m_itListCurrent;</span>00063 <span class="comment"> else</span>00064 <span class="comment"> ++m_itMapCurrent;</span>00065 <span class="comment"> }</span>00066 <span class="comment"></span>00067 <span class="comment"> BufferedTransformation & Destination()</span>00068 <span class="comment"> {</span>00069 <span class="comment"> return m_useDefault ? *m_itListCurrent->first : *m_itMapCurrent->second.first;</span>00070 <span class="comment"> }</span>00071 <span class="comment"></span>00072 <span class="comment"> const std::string & Message()</span>00073 <span class="comment"> {</span>00074 <span class="comment"> if (m_useDefault)</span>00075 <span class="comment"> return m_itListCurrent->second.get() ? *m_itListCurrent->second.get() : m_channel;</span>00076 <span class="comment"> else</span>00077 <span class="comment"> return m_itMapCurrent->second.second;</span>00078 <span class="comment"> }</span>00079 <span class="comment">};</span>00080 <span class="comment"></span>00081 <span class="comment">void MessageSwitch::Put(byte inByte);</span>00082 <span class="comment">void MessageSwitch::Put(const byte *inString, unsigned int length);</span>00083 <span class="comment"></span>00084 <span class="comment">void MessageSwitch::Flush(bool completeFlush, int propagation=-1);</span>00085 <span class="comment">void MessageSwitch::MessageEnd(int propagation=-1);</span>00086 <span class="comment">void MessageSwitch::PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);</span>00087 <span class="comment">void MessageSwitch::MessageSeriesEnd(int propagation=-1);</span>00088 <span class="comment">*/</span>00089 <span class="preprocessor">#endif</span>00090 <span class="preprocessor"></span>00091 <span class="keyword">class </span>ChannelRouteIterator00092 {00093 <span class="keyword">public</span>:00094 <span class="keyword">typedef</span> ChannelSwitch::RouteMap::const_iterator MapIterator;00095 <span class="keyword">typedef</span> ChannelSwitch::DefaultRouteList::const_iterator ListIterator;00096 00097 <span class="keyword">const</span> std::string m_channel;00098 <span class="keywordtype">bool</span> m_useDefault;00099 MapIterator m_itMapCurrent, m_itMapEnd;00100 ListIterator m_itListCurrent, m_itListEnd;00101 00102 ChannelRouteIterator(<a class="code" href="class_channel_switch.html">ChannelSwitch</a> &cs, <span class="keyword">const</span> std::string &channel)00103 : m_channel(channel)00104 {00105 pair<MapIterator, MapIterator> range = cs.<a class="code" href="class_channel_switch.html#_channel_switchr0">m_routeMap</a>.equal_range(channel);00106 <span class="keywordflow">if</span> (range.first == range.second)00107 {00108 m_useDefault = <span class="keyword">true</span>;00109 m_itListCurrent = cs.<a class="code" href="class_channel_switch.html#_channel_switchr1">m_defaultRoutes</a>.begin();00110 m_itListEnd = cs.<a class="code" href="class_channel_switch.html#_channel_switchr1">m_defaultRoutes</a>.end();00111 }00112 <span class="keywordflow">else</span>00113 {00114 m_useDefault = <span class="keyword">false</span>;00115 m_itMapCurrent = range.first;00116 m_itMapEnd = range.second;00117 }00118 }00119 00120 <span class="keywordtype">bool</span> End()<span class="keyword"> const</span>00121 <span class="keyword"> </span>{00122 <span class="keywordflow">return</span> m_useDefault ? m_itListCurrent == m_itListEnd : m_itMapCurrent == m_itMapEnd;00123 }00124 00125 <span class="keywordtype">void</span> Next()00126 {00127 <span class="keywordflow">if</span> (m_useDefault)00128 ++m_itListCurrent;00129 <span class="keywordflow">else</span>00130 ++m_itMapCurrent;00131 }00132 00133 <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> & Destination()00134 {00135 <span class="keywordflow">return</span> m_useDefault ? *m_itListCurrent->first : *m_itMapCurrent->second.first;00136 }00137 00138 <span class="keyword">const</span> std::string & Channel()00139 {00140 <span class="keywordflow">if</span> (m_useDefault)00141 <span class="keywordflow">return</span> m_itListCurrent->second.get() ? *m_itListCurrent->second.get() : m_channel;00142 <span class="keywordflow">else</span>00143 <span class="keywordflow">return</span> m_itMapCurrent->second.second;00144 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -