00001
00002
00003
00004
00005
00006
00007
00008 #include "ibrdtn/data/EID.h"
00009
00010 namespace dtn
00011 {
00012 namespace data
00013 {
00014 EID::EID()
00015 : _scheme("dtn"), _ssp("none")
00016 {
00017 }
00018
00019 EID::EID(const EID &other)
00020 : _scheme(other._scheme), _ssp(other._ssp)
00021 {
00022 }
00023
00024 EID::EID(std::string scheme, std::string ssp)
00025 : _scheme(scheme), _ssp(ssp)
00026 {
00027
00028 }
00029
00030 EID::EID(std::string value)
00031 {
00032 try {
00033
00034 size_t delimiter = value.find_first_of(":");
00035
00036
00037 if (delimiter == std::string::npos)
00038 throw ibrcommon::Exception("wrong eid format");
00039
00040
00041 _scheme = value.substr(0, delimiter);
00042
00043
00044 size_t startofssp = delimiter + 1;
00045 _ssp = value.substr(startofssp, value.length() - startofssp);
00046
00047
00048 } catch (...) {
00049 _scheme = "dtn";
00050 _ssp = "none";
00051 }
00052 }
00053
00054 EID::~EID()
00055 {
00056 }
00057
00058 EID& EID::operator=(const EID &other)
00059 {
00060 _ssp = other._ssp;
00061 _scheme = other._scheme;
00062 return *this;
00063 }
00064
00065 bool EID::operator==(EID const& other) const
00066 {
00067 return (_ssp == other._ssp) && (_scheme == other._scheme);
00068 }
00069
00070 bool EID::operator==(string const& other) const
00071 {
00072 return ((*this) == EID(other));
00073 }
00074
00075 bool EID::operator!=(EID const& other) const
00076 {
00077 return !((*this) == other);
00078 }
00079
00080 EID EID::operator+(string suffix)
00081 {
00082 return EID(getString() + suffix);
00083 }
00084
00085 bool EID::sameHost(string const& other) const
00086 {
00087 return ( other == getNodeEID() );
00088 }
00089
00090 bool EID::sameHost(EID const& other) const
00091 {
00092 return ( other.getNodeEID() == getNodeEID() );
00093 }
00094
00095 bool EID::operator<(EID const& other) const
00096 {
00097 return getString() < other.getString();
00098 }
00099
00100 bool EID::operator>(EID const& other) const
00101 {
00102 return other < (*this);
00103 }
00104
00105 std::string EID::getString() const
00106 {
00107 return _scheme + ":" + _ssp;
00108 }
00109
00110 std::string EID::getApplication() const throw (ibrcommon::Exception)
00111 {
00112
00113 size_t first_char = _ssp.find_first_not_of("/");
00114
00115
00116 if (first_char == std::string::npos)
00117 throw ibrcommon::Exception("wrong eid format");
00118
00119
00120 size_t application_start = _ssp.find_first_of("/", first_char);
00121
00122
00123 if (application_start == std::string::npos)
00124 return "";
00125
00126
00127 return _ssp.substr(application_start, _ssp.length() - application_start);
00128 }
00129
00130 std::string EID::getNode() const throw (ibrcommon::Exception)
00131 {
00132
00133 size_t first_char = _ssp.find_first_not_of("/");
00134
00135
00136 if (first_char == std::string::npos)
00137 throw ibrcommon::Exception("wrong eid format");
00138
00139
00140 size_t application_start = _ssp.find_first_of("/", first_char);
00141
00142
00143 if (application_start == std::string::npos)
00144 return _ssp;
00145
00146
00147 return _ssp.substr(0, application_start);
00148 }
00149
00150 std::string EID::getScheme() const
00151 {
00152 return _scheme;
00153 }
00154
00155 std::string EID::getNodeEID() const
00156 {
00157 return _scheme + ":" + getNode();
00158 }
00159
00160 bool EID::hasApplication() const
00161 {
00162
00163 size_t first_char = _ssp.find_first_not_of("/");
00164
00165
00166 if (first_char == std::string::npos)
00167 throw ibrcommon::Exception("wrong eid format");
00168
00169
00170 size_t application_start = _ssp.find_first_of("/", first_char);
00171
00172
00173 if (application_start == std::string::npos)
00174 return false;
00175
00176
00177 return true;
00178 }
00179 }
00180 }