00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _ENDPOINT_ID_H_
00018 #define _ENDPOINT_ID_H_
00019
00020 #include <string>
00021 #include <oasys/serialize/Serialize.h>
00022 #include <oasys/serialize/SerializableVector.h>
00023
00024 struct dtn_endpoint_id_t;
00025
00026 namespace dtn {
00027
00028 class EndpointID;
00029 class EndpointIDPattern;
00030 class Scheme;
00031
00032 class EndpointID : public oasys::SerializableObject {
00033 public:
00037 EndpointID() : scheme_(NULL), valid_(false), is_pattern_(false) {}
00038
00042 EndpointID(const oasys::Builder&)
00043 : scheme_(NULL), valid_(false), is_pattern_(false) {}
00044
00048 EndpointID(const std::string& str)
00049 : str_(str), scheme_(NULL), valid_(false), is_pattern_(false)
00050 {
00051 parse();
00052 }
00053
00057 EndpointID(const EndpointID& other)
00058 : SerializableObject(other)
00059 {
00060 if (&other != this)
00061 assign(other);
00062 }
00063
00067 virtual ~EndpointID() {}
00068
00072 bool assign(const EndpointID& other)
00073 {
00074 str_ = other.str_;
00075 scheme_str_ = other.scheme_str_;
00076 ssp_ = other.ssp_;
00077 scheme_ = other.scheme_;
00078 valid_ = other.valid_;
00079 is_pattern_ = other.is_pattern_;
00080 return true;
00081 }
00082
00087 bool assign(const std::string& str)
00088 {
00089 str_.assign(str);
00090 return parse();
00091 }
00092
00097 bool assign(const char* str, size_t len)
00098 {
00099 str_.assign(str, len);
00100 return parse();
00101 }
00102
00107 bool assign(const std::string& scheme, const std::string& ssp)
00108 {
00109 str_ = scheme + ":" + ssp;
00110 return parse();
00111 }
00112
00116 bool equals(const EndpointID& other) const
00117 {
00118 return str_ == other.str_;
00119 }
00120
00124 bool operator==(const EndpointID& other) const
00125 {
00126 return str_ == other.str_;
00127 }
00128
00132 bool operator!=(const EndpointID& other) const
00133 {
00134 return str_ != other.str_;
00135 }
00136
00142 bool assign(const dtn_endpoint_id_t* eid);
00143
00151 bool append_service_tag(const char* tag);
00152
00157 void copyto(dtn_endpoint_id_t* eid) const;
00158
00162 bool known_scheme() const
00163 {
00164 return (scheme_ != NULL);
00165 }
00166
00171 static const EndpointID NULL_EID() { return EndpointID("dtn:none"); }
00172
00178 static const EndpointID WILDCARD_EID() { return EndpointID("*:*"); }
00179
00183 virtual void serialize(oasys::SerializeAction* a);
00184
00188 const std::string& str() const { return str_; }
00189 const std::string& scheme_str() const { return scheme_str_; }
00190 const std::string& ssp() const { return ssp_; }
00191 Scheme* scheme() const { return scheme_; }
00192 bool valid() const { return valid_; }
00193 bool is_pattern() const { return is_pattern_; }
00194 const char* c_str() const { return str_.c_str(); }
00195 const char* data() const { return str_.data(); }
00196 size_t length() const { return str_.length(); }
00198
00199 protected:
00205 bool parse();
00206
00207 std::string str_;
00208 std::string scheme_str_;
00209 std::string ssp_;
00210 Scheme* scheme_;
00211 bool valid_;
00212 bool is_pattern_;
00213 };
00214
00220 class EndpointIDPattern : public EndpointID {
00221 public:
00225 EndpointIDPattern() : EndpointID()
00226 {
00227 is_pattern_ = true;
00228 }
00229
00233 EndpointIDPattern(const std::string& str) : EndpointID()
00234 {
00235 is_pattern_ = true;
00236 assign(str);
00237 }
00238
00242 EndpointIDPattern(const EndpointIDPattern& other)
00243 : EndpointID(other)
00244 {
00245 is_pattern_ = true;
00246 assign(other);
00247 }
00248
00253 EndpointIDPattern(const EndpointID& other)
00254 {
00255 is_pattern_ = true;
00256 assign(other);
00257 }
00258
00263 bool match(const EndpointID& eid) const;
00264
00265 };
00266
00270 class EndpointIDVector : public oasys::SerializableVector<EndpointID> {};
00271
00272 }
00273
00274 #endif