|
IBR-DTNSuite 0.6
|
00001 /* 00002 * BundleID.cpp 00003 * 00004 * Created on: 01.09.2009 00005 * Author: morgenro 00006 */ 00007 00008 #include "ibrdtn/config.h" 00009 #include "ibrdtn/data/BundleID.h" 00010 #include "ibrdtn/data/SDNV.h" 00011 #include "ibrdtn/data/BundleString.h" 00012 00013 namespace dtn 00014 { 00015 namespace data 00016 { 00017 BundleID::BundleID(const dtn::data::EID s, const size_t t, const size_t sq, const bool f, const size_t o) 00018 : source(s), timestamp(t), sequencenumber(sq), fragment(f), offset(o) 00019 { 00020 } 00021 00022 BundleID::BundleID(const dtn::data::Bundle &b) 00023 : source(b._source), timestamp(b._timestamp), sequencenumber(b._sequencenumber), 00024 fragment(b.get(dtn::data::Bundle::FRAGMENT)), offset(b._fragmentoffset) 00025 { 00026 } 00027 00028 BundleID::~BundleID() 00029 { 00030 } 00031 00032 bool BundleID::operator<(const BundleID& other) const 00033 { 00034 if (source < other.source) return true; 00035 if (source != other.source) return false; 00036 00037 if (timestamp < other.timestamp) return true; 00038 if (timestamp != other.timestamp) return false; 00039 00040 if (sequencenumber < other.sequencenumber) return true; 00041 if (sequencenumber != other.sequencenumber) return false; 00042 00043 if (fragment && (offset < other.offset)) return true; 00044 00045 return false; 00046 } 00047 00048 bool BundleID::operator>(const BundleID& other) const 00049 { 00050 return !(((*this) < other) || ((*this) == other)); 00051 } 00052 00053 bool BundleID::operator!=(const BundleID& other) const 00054 { 00055 return !((*this) == other); 00056 } 00057 00058 bool BundleID::operator==(const BundleID& other) const 00059 { 00060 if (other.timestamp != timestamp) return false; 00061 if (other.sequencenumber != sequencenumber) return false; 00062 if (other.source != source) return false; 00063 00064 if (fragment) 00065 { 00066 if (other.offset != offset) return false; 00067 } 00068 00069 return true; 00070 } 00071 00072 size_t BundleID::getTimestamp() const 00073 { 00074 return timestamp; 00075 } 00076 00077 string BundleID::toString() const 00078 { 00079 stringstream ss; 00080 ss << "[" << timestamp << "." << sequencenumber; 00081 00082 if (fragment) 00083 { 00084 ss << "." << offset; 00085 } 00086 00087 ss << "] " << source.getString(); 00088 00089 return ss.str(); 00090 } 00091 00092 std::ostream &operator<<(std::ostream &stream, const BundleID &obj) 00093 { 00094 dtn::data::SDNV timestamp(obj.timestamp); 00095 dtn::data::SDNV sequencenumber(obj.sequencenumber); 00096 dtn::data::SDNV offset(obj.offset); 00097 dtn::data::BundleString source(obj.source.getString()); 00098 00099 stream << timestamp << sequencenumber << offset << source; 00100 00101 return stream; 00102 } 00103 00104 std::istream &operator>>(std::istream &stream, BundleID &obj) 00105 { 00106 dtn::data::SDNV timestamp; 00107 dtn::data::SDNV sequencenumber; 00108 dtn::data::SDNV offset; 00109 dtn::data::BundleString source; 00110 00111 stream >> timestamp >> sequencenumber >> offset >> source; 00112 00113 obj.timestamp = timestamp.getValue(); 00114 obj.sequencenumber = sequencenumber.getValue(); 00115 obj.offset = offset.getValue(); 00116 obj.source = dtn::data::EID(source); 00117 00118 return stream; 00119 } 00120 } 00121 }