00001 #ifndef DSR_PDB_PDB_INDEX_H 00002 #define DSR_PDB_PDB_INDEX_H 00003 #include <cassert> 00004 #include <ostream> 00005 namespace dsrpdb { 00006 00008 00011 template <class Type> 00012 class PDB_index { 00013 typedef PDB_index<Type> This; 00014 public: 00016 explicit PDB_index(unsigned int v): v_(v){} 00018 PDB_index():v_(-1){} 00020 operator unsigned int() const { 00021 assert(*this); 00022 return v_; 00023 } 00024 bool operator==(This o) const { 00025 if (!o || !*this) return false; 00026 return v_== o.v_; 00027 } 00028 bool operator!=(This o) const { 00029 if (!o || !*this) return false; 00030 return v_!= o.v_; 00031 } 00032 bool operator<(This o) const { 00033 if (!o || !*this) return false; 00034 return v_ < o.v_; 00035 } 00036 bool operator>(This o) const { 00037 if (!o || !*this) return false; 00038 return v_ > o.v_; 00039 } 00040 bool operator<=(This o) const { 00041 if (!o || !*this) return false; 00042 return v_ <= o.v_; 00043 } 00044 bool operator>=(This o) const { 00045 if (!o || !*this) return false; 00046 return v_ >= o.v_; 00047 } 00048 operator bool() const { 00049 return v_ != -1; 00050 } 00051 std::ostream &write(std::ostream &o) const { 00052 if (operator bool()) { 00053 o << "(" << v_ << ")"; 00054 } else { 00055 o << "(null)"; 00056 } 00057 return o; 00058 } 00059 protected: 00060 int v_; 00061 }; 00062 00063 template <class T> 00064 std::ostream &operator<<(std::ostream &o, PDB_index<T> i) { 00065 return i.write(o); 00066 } 00067 } 00068 #endif