00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _SEQUENCE_ID_H_
00018 #define _SEQUENCE_ID_H_
00019
00020 #include <oasys/debug/Formatter.h>
00021 #include "../naming/EndpointID.h"
00022
00023 namespace dtn {
00024
00029 class SequenceID : public oasys::Formatter {
00030 public:
00031 SequenceID();
00032
00037 typedef enum {
00038 EMPTY = 0,
00039 COUNTER = 1,
00040 IDENTIFIER = 2
00041 } type_t;
00042
00046 typedef enum {
00047 LT = -1,
00048 EQ = 0,
00049 GT = 1,
00050 NEQ = 2,
00051 ILL = 999
00052 } comp_t;
00053
00055 static const char* comp2str(comp_t eq);
00056
00058 void add(const EndpointID& eid, u_int64_t counter);
00059
00061 void add(const EndpointID& eid, const std::string& identifier);
00062
00067 u_int64_t get_counter(const EndpointID& eid) const;
00068
00073 std::string get_identifier(const EndpointID& eid) const;
00074
00076 int format(char* buf, size_t sz) const;
00077
00079 std::string to_str() const;
00080
00084 bool parse(const std::string& str);
00085
00087 comp_t compare(const SequenceID& v) const;
00088
00090 bool operator<(const SequenceID& v) const { return compare(v) == LT; }
00091 bool operator>(const SequenceID& v) const { return compare(v) == GT; }
00092 bool operator==(const SequenceID& v) const { return compare(v) == EQ; }
00093
00095 bool operator!=(const SequenceID& v) const { return compare(v) == NEQ; }
00096
00097 bool operator<=(const SequenceID& v) const
00098 {
00099 int cmp = compare(v);
00100 return cmp == LT || cmp == EQ;
00101 }
00102
00103 bool operator>=(const SequenceID& v) const
00104 {
00105 int cmp = compare(v);
00106 return cmp == GT || cmp == EQ;
00107 }
00109
00111 void assign(const SequenceID& other);
00112
00115 void update(const SequenceID& other);
00116
00118 struct Entry {
00119 Entry()
00120 : eid_(), type_(EMPTY), counter_(0), identifier_("") {}
00121
00122 Entry(const EndpointID& eid, u_int64_t counter)
00123 : eid_(eid), type_(COUNTER), counter_(counter), identifier_("") {}
00124
00125 Entry(const EndpointID& eid, const std::string& id)
00126 : eid_(eid), type_(IDENTIFIER), counter_(0), identifier_(id) {}
00127
00128 Entry(const Entry& other)
00129 : eid_(other.eid_), type_(other.type_),
00130 counter_(other.counter_), identifier_(other.identifier_) {}
00131
00132 EndpointID eid_;
00133 type_t type_;
00134 u_int64_t counter_;
00135 std::string identifier_;
00136 };
00137
00141 const Entry& get_entry(const EndpointID& eid) const;
00142
00144 typedef std::vector<Entry> EntryVec;
00145 typedef EntryVec::iterator iterator;
00146 typedef EntryVec::const_iterator const_iterator;
00147
00148 bool empty() const { return vector_.empty(); }
00149 EntryVec::iterator begin() { return vector_.begin(); }
00150 EntryVec::iterator end() { return vector_.end(); }
00151 EntryVec::const_iterator begin() const { return vector_.begin(); }
00152 EntryVec::const_iterator end() const { return vector_.end(); }
00154
00155 private:
00157 EntryVec vector_;
00158
00160 static comp_t compare_entries(const Entry& left, const Entry& right);
00161
00163 static comp_t compare_one_way(const SequenceID& lv,
00164 const SequenceID& rv,
00165 comp_t cur_state);
00166 };
00167
00168 }
00169
00170 #endif