00001 /* 00002 * Copyright 2007 Baylor University 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _PROPHET_DICTIONARY_H_ 00018 #define _PROPHET_DICTIONARY_H_ 00019 00020 #include <string> 00021 #include <map> 00022 #include "Util.h" 00023 #include "Bundle.h" 00024 #include "BundleCore.h" 00025 00026 namespace prophet 00027 { 00028 00033 class Dictionary 00034 { 00035 public: 00036 typedef std::map<u_int16_t,std::string> rribd; 00037 typedef std::map<u_int16_t,std::string>::const_iterator 00038 const_iterator; 00039 00043 static const u_int16_t INVALID_SID; 00044 00048 static const std::string NULL_STR; 00049 00053 Dictionary(const std::string& sender = "", 00054 const std::string& receiver = ""); 00055 00059 Dictionary(const Dictionary& d); 00060 00064 ~Dictionary() {} 00065 00069 u_int16_t find(const std::string& dest_id) const; 00070 00074 const std::string& find(u_int16_t sid) const; 00075 00079 const std::string& sender() const { return sender_; } 00080 00084 const std::string& receiver() const { return receiver_; } 00085 00090 u_int16_t insert(const std::string& dest_id); 00091 00096 u_int16_t insert(const Bundle* b); 00097 00102 bool assign(const std::string& dest_id, u_int16_t sid); 00103 00105 const_iterator begin() const { return rribd_.begin(); } 00106 const_iterator end() const { return rribd_.end(); } 00108 00112 size_t size() const { return ribd_.size(); } 00113 00118 size_t guess_ribd_size(size_t RASsz) const; 00119 00123 void clear(); 00124 00128 Dictionary& operator= (const Dictionary& d) 00129 { 00130 sender_.assign(d.sender_); 00131 receiver_.assign(d.receiver_); 00132 ribd_ = d.ribd_; 00133 rribd_ = d.rribd_; 00134 return *this; 00135 } 00136 00140 void dump(BundleCore* core,const char* file,u_int line) const; 00141 00142 protected: 00143 typedef std::map<std::string,u_int16_t,less_string> ribd; 00144 00145 std::string sender_; 00146 std::string receiver_; 00147 ribd ribd_; 00148 rribd rribd_; 00149 00150 }; // Dictionary 00151 00152 }; // namespace prophet 00153 #endif // _PROPHET_DICTIONARY_H_