<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>DTN Reference Implementation: Dictionary.h 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.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>Dictionary.h</h1><a href="prophet_2Dictionary_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright 2007 Baylor University</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span> <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span> <a name="l00007"></a>00007 <span class="comment"> *</span> <a name="l00008"></a>00008 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span> <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span> <a name="l00015"></a>00015 <span class="comment"> */</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#ifndef _PROPHET_DICTIONARY_H_</span> <a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define _PROPHET_DICTIONARY_H_</span> <a name="l00019"></a>00019 <span class="preprocessor"></span> <a name="l00020"></a>00020 <span class="preprocessor">#include <string></span> <a name="l00021"></a>00021 <span class="preprocessor">#include <map></span> <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="Util_8h.html">Util.h</a>"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="prophet_2Bundle_8h.html">Bundle.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="BundleCore_8h.html">BundleCore.h</a>"</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="keyword">namespace </span>prophet <a name="l00027"></a>00027 { <a name="l00028"></a>00028 <a name="l00033"></a><a class="code" href="classprophet_1_1Dictionary.html">00033</a> <span class="keyword">class </span><a class="code" href="classprophet_1_1Dictionary.html" title="Utility class to facilitate converting to and from routing string (endpoint ID) and...">Dictionary</a> <a name="l00034"></a>00034 { <a name="l00035"></a>00035 <span class="keyword">public</span>: <a name="l00036"></a><a class="code" href="classprophet_1_1Dictionary.html#be1155d68506d10798902b7304b60e5e">00036</a> <span class="keyword">typedef</span> std::map<u_int16_t,std::string> <a class="code" href="classprophet_1_1Dictionary.html#be1155d68506d10798902b7304b60e5e">rribd</a>; <a name="l00037"></a>00037 <span class="keyword">typedef</span> std::map<u_int16_t,std::string>::const_iterator <a name="l00038"></a><a class="code" href="classprophet_1_1Dictionary.html#80622a2076a9267f6131aadb9f865e05">00038</a> <a class="code" href="classprophet_1_1Dictionary.html#80622a2076a9267f6131aadb9f865e05">const_iterator</a>; <a name="l00039"></a>00039 <a name="l00043"></a><a class="code" href="classprophet_1_1Dictionary.html#bb335d818c777bf393a25cbbd0661679">00043</a> <span class="keyword">static</span> <span class="keyword">const</span> u_int16_t <a class="code" href="classprophet_1_1Dictionary.html#bb335d818c777bf393a25cbbd0661679" title="Reserve 0xffff for in-band error signal.">INVALID_SID</a>; <a name="l00044"></a>00044 <a name="l00048"></a><a class="code" href="classprophet_1_1Dictionary.html#7dcf0db4f9d83184525aaff84671bac1">00048</a> <span class="keyword">static</span> <span class="keyword">const</span> std::string <a class="code" href="classprophet_1_1Dictionary.html#7dcf0db4f9d83184525aaff84671bac1" title="Used for in-band error signal.">NULL_STR</a>; <a name="l00049"></a>00049 <a name="l00053"></a>00053 <a class="code" href="classprophet_1_1Dictionary.html#ad351c7c24507678ccbe774d1cad7c63" title="Default constructor.">Dictionary</a>(<span class="keyword">const</span> std::string& <a class="code" href="classprophet_1_1Dictionary.html#2610c511879ff8ddee2646f726aa2738" title="Convenience function; sender is defined as sid == 0.">sender</a> = <span class="stringliteral">""</span>, <a name="l00054"></a>00054 <span class="keyword">const</span> std::string& <a class="code" href="classprophet_1_1Dictionary.html#cac233cc73ca84854caf6653f99c85e0" title="Convenience function; receiver is defined as sid == 1.">receiver</a> = <span class="stringliteral">""</span>); <a name="l00055"></a>00055 <a name="l00059"></a>00059 <a class="code" href="classprophet_1_1Dictionary.html#ad351c7c24507678ccbe774d1cad7c63" title="Default constructor.">Dictionary</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Dictionary.html" title="Utility class to facilitate converting to and from routing string (endpoint ID) and...">Dictionary</a>& d); <a name="l00060"></a>00060 <a name="l00064"></a><a class="code" href="classprophet_1_1Dictionary.html#78f6bf3f0f9543c2007efcba4b17944a">00064</a> <a class="code" href="classprophet_1_1Dictionary.html#78f6bf3f0f9543c2007efcba4b17944a" title="Destructor.">~Dictionary</a>() {} <a name="l00065"></a>00065 <a name="l00069"></a>00069 u_int16_t <a class="code" href="classprophet_1_1Dictionary.html#b1cfc06ddc3d8128bbd7d6948a349ae9" title="If dest_id is valid, returns sid; else returns INVALID_SID.">find</a>(<span class="keyword">const</span> std::string& dest_id) <span class="keyword">const</span>; <a name="l00070"></a>00070 <a name="l00074"></a>00074 <span class="keyword">const</span> std::string& <a class="code" href="classprophet_1_1Dictionary.html#b1cfc06ddc3d8128bbd7d6948a349ae9" title="If dest_id is valid, returns sid; else returns INVALID_SID.">find</a>(u_int16_t sid) <span class="keyword">const</span>; <a name="l00075"></a>00075 <a name="l00079"></a><a class="code" href="classprophet_1_1Dictionary.html#2610c511879ff8ddee2646f726aa2738">00079</a> <span class="keyword">const</span> std::string& <a class="code" href="classprophet_1_1Dictionary.html#2610c511879ff8ddee2646f726aa2738" title="Convenience function; sender is defined as sid == 0.">sender</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1Dictionary.html#f66f3690f00af8809669a61225558de0" title="destination id of peering initiator">sender_</a>; } <a name="l00080"></a>00080 <a name="l00084"></a><a class="code" href="classprophet_1_1Dictionary.html#cac233cc73ca84854caf6653f99c85e0">00084</a> <span class="keyword">const</span> std::string& <a class="code" href="classprophet_1_1Dictionary.html#cac233cc73ca84854caf6653f99c85e0" title="Convenience function; receiver is defined as sid == 1.">receiver</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1Dictionary.html#bd4eaa070f4bc1b28b36f03bc9c19118" title="destination id of passive peer">receiver_</a>; } <a name="l00085"></a>00085 <a name="l00090"></a>00090 u_int16_t <a class="code" href="classprophet_1_1Dictionary.html#ac74ea4f1d334b765c7b641a18a213d4" title="Insert dest_id and return valid id upon success; else returns INVALID_SID.">insert</a>(<span class="keyword">const</span> std::string& dest_id); <a name="l00091"></a>00091 <a name="l00096"></a>00096 u_int16_t <a class="code" href="classprophet_1_1Dictionary.html#ac74ea4f1d334b765c7b641a18a213d4" title="Insert dest_id and return valid id upon success; else returns INVALID_SID.">insert</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b); <a name="l00097"></a>00097 <a name="l00102"></a>00102 <span class="keywordtype">bool</span> <a class="code" href="classprophet_1_1Dictionary.html#4f785ed38d15266fd52f82bfe2a3259a" title="Assign dest_id to arbitrary id (used by TLV deserialization); return true upon success...">assign</a>(<span class="keyword">const</span> std::string& dest_id, u_int16_t sid); <a name="l00103"></a>00103 <a name="l00105"></a><a class="code" href="classprophet_1_1Dictionary.html#01530ae50e9191b36cc2b56593725584">00105</a> <a class="code" href="classprophet_1_1Dictionary.html#80622a2076a9267f6131aadb9f865e05">const_iterator</a> <a class="code" href="classprophet_1_1Dictionary.html#01530ae50e9191b36cc2b56593725584" title="Iterators.">begin</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1Dictionary.html#b1ece3b8df19f96b6f374c69a14c5740" title="reverse lookup from string id to dest_id">rribd_</a>.begin(); } <a name="l00106"></a><a class="code" href="classprophet_1_1Dictionary.html#de4bd30ae5e6a17e1acb4c1730432d62">00106</a> <a class="code" href="classprophet_1_1Dictionary.html#80622a2076a9267f6131aadb9f865e05">const_iterator</a> <a class="code" href="classprophet_1_1Dictionary.html#de4bd30ae5e6a17e1acb4c1730432d62" title="Iterators.">end</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1Dictionary.html#b1ece3b8df19f96b6f374c69a14c5740" title="reverse lookup from string id to dest_id">rribd_</a>.end(); } <a name="l00108"></a>00108 <a name="l00112"></a><a class="code" href="classprophet_1_1Dictionary.html#c421fcb8a03a9f986e3413ae9e0d8505">00112</a> <span class="keywordtype">size_t</span> <a class="code" href="classprophet_1_1Dictionary.html#c421fcb8a03a9f986e3413ae9e0d8505" title="Return the number of elements in the dictionary.">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1Dictionary.html#76e8b257f6673199d0e6cbf15e697ef3" title="forward lookup, dest_id to string id">ribd_</a>.size(); } <a name="l00113"></a>00113 <a name="l00118"></a>00118 <span class="keywordtype">size_t</span> <a class="code" href="classprophet_1_1Dictionary.html#250334386542b62223dc658ecceacf66" title="Helper function for serializing, where RASsz is the sizeof(RoutingAddressString)...">guess_ribd_size</a>(<span class="keywordtype">size_t</span> RASsz) <span class="keyword">const</span>; <a name="l00119"></a>00119 <a name="l00123"></a>00123 <span class="keywordtype">void</span> <a class="code" href="classprophet_1_1Dictionary.html#dc4702ba4c07259ab17cedaa48786723" title="Wipe out dictionary and prepare to deserialize new one.">clear</a>(); <a name="l00124"></a>00124 <a name="l00128"></a><a class="code" href="classprophet_1_1Dictionary.html#584614db05873a821bfeb172bb0b76e0">00128</a> <a class="code" href="classprophet_1_1Dictionary.html" title="Utility class to facilitate converting to and from routing string (endpoint ID) and...">Dictionary</a>& <a class="code" href="classprophet_1_1Dictionary.html#584614db05873a821bfeb172bb0b76e0" title="Assignment operator.">operator= </a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Dictionary.html" title="Utility class to facilitate converting to and from routing string (endpoint ID) and...">Dictionary</a>& d) <a name="l00129"></a>00129 { <a name="l00130"></a>00130 <a class="code" href="classprophet_1_1Dictionary.html#f66f3690f00af8809669a61225558de0" title="destination id of peering initiator">sender_</a>.assign(d.<a class="code" href="classprophet_1_1Dictionary.html#f66f3690f00af8809669a61225558de0" title="destination id of peering initiator">sender_</a>); <a name="l00131"></a>00131 <a class="code" href="classprophet_1_1Dictionary.html#bd4eaa070f4bc1b28b36f03bc9c19118" title="destination id of passive peer">receiver_</a>.assign(d.<a class="code" href="classprophet_1_1Dictionary.html#bd4eaa070f4bc1b28b36f03bc9c19118" title="destination id of passive peer">receiver_</a>); <a name="l00132"></a>00132 <a class="code" href="classprophet_1_1Dictionary.html#76e8b257f6673199d0e6cbf15e697ef3" title="forward lookup, dest_id to string id">ribd_</a> = d.<a class="code" href="classprophet_1_1Dictionary.html#76e8b257f6673199d0e6cbf15e697ef3" title="forward lookup, dest_id to string id">ribd_</a>; <a name="l00133"></a>00133 <a class="code" href="classprophet_1_1Dictionary.html#b1ece3b8df19f96b6f374c69a14c5740" title="reverse lookup from string id to dest_id">rribd_</a> = d.<a class="code" href="classprophet_1_1Dictionary.html#b1ece3b8df19f96b6f374c69a14c5740" title="reverse lookup from string id to dest_id">rribd_</a>; <a name="l00134"></a>00134 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00140"></a>00140 <span class="keywordtype">void</span> <a class="code" href="classprophet_1_1Dictionary.html#e67044b9cd2dbb9de172fc3cf3d6c088" title="Debug method for printing out internal state to log.">dump</a>(<a class="code" href="classprophet_1_1BundleCore.html" title="Prophet facade&#39;s abstract interface into DTN host&#39;s bundle core.">BundleCore</a>* core,<span class="keyword">const</span> <span class="keywordtype">char</span>* file,u_int line) <span class="keyword">const</span>; <a name="l00141"></a>00141 <a name="l00142"></a>00142 <span class="keyword">protected</span>: <a name="l00143"></a><a class="code" href="classprophet_1_1Dictionary.html#fff33bd8c9aff922cdd5dd1fb87d4a7f">00143</a> <span class="keyword">typedef</span> std::map<std::string,u_int16_t,less_string> <a class="code" href="classprophet_1_1Dictionary.html#fff33bd8c9aff922cdd5dd1fb87d4a7f">ribd</a>; <a name="l00144"></a>00144 <a name="l00145"></a><a class="code" href="classprophet_1_1Dictionary.html#f66f3690f00af8809669a61225558de0">00145</a> std::string <a class="code" href="classprophet_1_1Dictionary.html#f66f3690f00af8809669a61225558de0" title="destination id of peering initiator">sender_</a>; <a name="l00146"></a><a class="code" href="classprophet_1_1Dictionary.html#bd4eaa070f4bc1b28b36f03bc9c19118">00146</a> std::string <a class="code" href="classprophet_1_1Dictionary.html#bd4eaa070f4bc1b28b36f03bc9c19118" title="destination id of passive peer">receiver_</a>; <a name="l00147"></a><a class="code" href="classprophet_1_1Dictionary.html#76e8b257f6673199d0e6cbf15e697ef3">00147</a> <a class="code" href="classprophet_1_1Dictionary.html#fff33bd8c9aff922cdd5dd1fb87d4a7f">ribd</a> <a class="code" href="classprophet_1_1Dictionary.html#76e8b257f6673199d0e6cbf15e697ef3" title="forward lookup, dest_id to string id">ribd_</a>; <a name="l00148"></a><a class="code" href="classprophet_1_1Dictionary.html#b1ece3b8df19f96b6f374c69a14c5740">00148</a> <a class="code" href="classprophet_1_1Dictionary.html#be1155d68506d10798902b7304b60e5e">rribd</a> <a class="code" href="classprophet_1_1Dictionary.html#b1ece3b8df19f96b6f374c69a14c5740" title="reverse lookup from string id to dest_id">rribd_</a>; <a name="l00149"></a>00149 <a name="l00150"></a>00150 }; <span class="comment">// Dictionary</span> <a name="l00151"></a>00151 <a name="l00152"></a>00152 }; <span class="comment">// namespace prophet</span> <a name="l00153"></a>00153 <span class="preprocessor">#endif // _PROPHET_DICTIONARY_H_</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:39 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>