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